Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,23 @@ To fire an event to the WebSocket server you can call:
app.BrainSocket.message('some.event',[some:data]);
```

Typically you would fire these messages after user interactions take place in your app.
**Note:** Firing an event before a connection to the websockets server will cause an error. As such, if you want to fire an event as soon as possible after pageload you should use the "onopen" event handler as shown below.


```javascript
app.BrainSocket.onopen(function()
{
// this executes as soon as the connection is established.
app.BrainSocket.message('newClient.event',
{
'message':'register',
'user_id':fake_user_id
}
);
});
```

Typically though, you would fire these messages after user interactions take place in your app.

Here's an example with jquery:

Expand Down
2 changes: 1 addition & 1 deletion example/js/brain-socket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions lib/BrainSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ function BrainSocket(WebSocketConnection,BrainSocketPubSub){

this.connection.BrainSocket = this;

this.onopen = function(fn){
WebSocketConnection.onopen = fn;
};

this.connection.digestMessage = function(data){
try{
var object = JSON.parse(data);
Expand Down
2 changes: 1 addition & 1 deletion lib/brain-socket.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.