Skip to content

Commit

Permalink
#add socket broadcast helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstyles committed Mar 29, 2016
1 parent cf3bd41 commit 0566f22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<button class="js-ack">Send <span class="small">(with acknowledgement)</span></button>
<button class="js-chatBtn">Chat</button>
<div class="connections"><span class="js-connect">1</span></div>
<script src="https://cdn.socket.io/socket.io-1.3.7.js"></script>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script>
var socket = io()

Expand Down
13 changes: 11 additions & 2 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = class Socket {
let packet = {
event: event,
data: data,
socket: this,
socket: this,
acknowledge: cb
}

Expand Down Expand Up @@ -79,12 +79,21 @@ module.exports = class Socket {
/**
* Helper through to the socket
* @param event <String>
* @param data <?>
* @param packet <?>
*/
emit( event, packet ) {
this.socket.emit( event, packet )
}

/**
* Helper through to broadcasting
* @param event <String>
* @param packet <?>
*/
broadcast( event, packet ) {
this.socket.broadcast.emit( event, packet )
}

/**
* Disconnect helper
*/
Expand Down

0 comments on commit 0566f22

Please sign in to comment.