Skip to content

Commit

Permalink
added socketserver service
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Spratley committed Dec 1, 2014
1 parent 365ca4f commit 5de9bd3
Show file tree
Hide file tree
Showing 4 changed files with 362 additions and 321 deletions.
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<script src="scripts/services/cmssessionservice.js"></script>
<script src="scripts/services/cmsnotify.js"></script>
<script src="scripts/filters/gravatar.js"></script>
<script src="scripts/services/cmssocketservice.js"></script>
<!-- endbuild -->
</body>
</html>
38 changes: 38 additions & 0 deletions app/scripts/services/cmssocketservice.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

###*
# @ngdoc service
# @name angularCmsApp.cmsSocketService
# @description
# # cmsSocketService
# Service in the angularCmsApp.
###
angular.module('angularCmsApp').service 'cmsSocketService', ->
# AngularJS will instantiate a singleton by calling "new" on this function
WebSocketClient = (options) ->
_ws = undefined
_ws = new WebSocket(options.endpoint, options.protocol)
_ws.onmessage = (e) ->
console.log e.data

_ws.onerror = (e) ->
console.log e

_ws.onclose = (e) ->
console.log e

_ws.onopen = (e) ->
_ws.send "update"
return
instance: _ws
close: ->
_ws.close()

send: (obj) ->
try
_ws.send obj
catch err
throw err
return

return WebSocketClient
Loading

0 comments on commit 5de9bd3

Please sign in to comment.