Skip to content

Instantly share code, notes, and snippets.

@kruyvanna
Last active December 20, 2015 05:18
Show Gist options
  • Save kruyvanna/6076754 to your computer and use it in GitHub Desktop.
Save kruyvanna/6076754 to your computer and use it in GitHub Desktop.
window.App.webSocketServer = {};
var PORT = 3001;
var socketServer = new monaca.WebSocketServer(PORT);
socketServer.onClientConnected = function(client){
App.trigger('client:connected', client);
};
socketServer.onClientDisconnected = function(client){
App.trigger('client:disconnected', client);
};
socketServer.onerror = function(error){
echo(error);
};
App.webSocketServer.start = function(){
socketServer.start(
function(response){
App.trigger('websocket_server:started', response);
},
echo
);
}
App.webSocketServer.getClients = function(success, failure){
socketServer.getClients(
success,
failure
);
}
App.webSocketServer.sendMessageToClients = function(message){
socketServer.sendToAllClients(
message,
echo,
echo
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment