Last active
August 29, 2015 14:22
-
-
Save LukasGasior1/5ce253c2b5883c4e3f5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.service('commandService', function($http) { | |
return { | |
createGame: function(success, error) { | |
$http.post('/game') | |
.success(success) | |
.error(error); | |
}, | |
startGame: function(gameId, playersCount, error) { | |
$http.post('/game/' + gameId + '/start?playersCount=' + playersCount) | |
.error(error); | |
}, | |
roll: function(gameId, player, error) { | |
$http.post('/game/' + gameId + '/roll/' + player) | |
.error(error); | |
} | |
}; | |
}); | |
module.service('eventService', function($rootScope) { | |
var ws = null; | |
return { | |
connect: function(gameId) { | |
ws = new WebSocket('ws://' + window.location.hostname + ':' + window.location.port + '/' + gameId + '/events'); | |
ws.onmessage = function(event) { | |
var message = JSON.parse(event.data); | |
$rootScope.$broadcast('events.' + message.eventType, message.data); | |
}; | |
}, | |
disconnect: function() { | |
if (ws != null) { | |
ws.close(); | |
} | |
} | |
}; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment