Commit 79f0ebc1 authored by Ujvari Gergely's avatar Ujvari Gergely

Throw out sockjswrapper.coffee

parent af478dbd
......@@ -9,9 +9,11 @@ get_quote = (annotation) ->
quote
class Displayer
this.$inject = ['$scope','$element','$timeout','streamfilter']
path: window.location.protocol + '//' + window.location.hostname + ':' +
window.location.port + '/__streamer__'
idTable : {}
this.$inject = ['$scope','$element','$timeout','streamfilter']
constructor: ($scope, $element, $timeout, streamfilter) ->
$scope.annotation = {}
$scope.annotations = [$scope.annotation]
......@@ -37,14 +39,25 @@ class Displayer
to_change.replies = replies
to_change.reply_count = reply_count
$scope.open = =>
$scope.sock = new SockJSWrapper $scope, $scope.filter
, null
, $scope.manage_new_data
,=>
$scope.sock = new SockJS @path
$scope.sock.onopen = =>
$scope.sock.send JSON.stringify $scope.filter
$scope.sock.onclose = =>
$timeout $scope.open, 5000
$scope.sock.onmessage = (msg) =>
console.log 'Got something'
console.log msg
data = msg.data[0]
action = msg.data[1]
unless data instanceof Array then data = [data]
$scope.$apply =>
$scope.manage_new_data data, action
$scope.manage_new_data = (data, action) =>
#sort annotations by creation date
data.sort (a, b) ->
......
class window.SockJSWrapper
transports: ['xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']
path: window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/__streamer__'
constructor: ($scope, filter, fn_open, fn_message, fn_close) ->
@sock = new SockJS(@path, @transports)
@sock.onopen = =>
@sock.send JSON.stringify filter
if fn_open? then fn_open()
@sock.onclose = fn_close
@sock.onmessage = (msg) =>
console.log 'Got something'
console.log msg
data = msg.data[0]
action = msg.data[1]
unless data instanceof Array then data = [data]
if fn_message?
$scope.$apply =>
fn_message data, action
close: ->
@sock.close()
......@@ -23,6 +23,8 @@ syntaxHighlight = (json) ->
)
class Streamer
path: window.location.protocol + '//' + window.location.hostname + ':' +
window.location.port + '/__streamer__'
strategies: ['include_any', 'include_all', 'exclude_any', 'exclude_all']
past_modes: ['none','hits','time']
......@@ -109,13 +111,25 @@ class Streamer
$scope.open()
$scope.open = =>
$scope.sock = new SockJSWrapper $scope, $scope.filter
, =>
$scope.sock = new SockJS @path
$scope.sock.onopen = =>
$scope.sock.send JSON.stringify $scope.filter
$scope.streaming = true
, $scope.manage_new_data
,=>
$scope.sock.onclose = =>
$scope.streaming = false
$scope.sock.onmessage = (msg) =>
console.log 'Got something'
console.log msg
data = msg.data[0]
action = msg.data[1]
unless data instanceof Array then data = [data]
$scope.$apply =>
$scope.manage_new_data data, action
$scope.manage_new_data = (data, action) =>
for annotation in data
annotation.action = action
......
......@@ -9,6 +9,8 @@ get_quote = (annotation) ->
quote
class UserStream
path: window.location.protocol + '//' + window.location.hostname + ':' +
window.location.port + '/__streamer__'
this.$inject = ['$scope','$timeout','streamfilter']
constructor: ($scope, $timeout, streamfilter) ->
......@@ -29,12 +31,24 @@ class UserStream
$scope.annotations.splice 0,0,annotation
$scope.open = =>
$scope.sock = new SockJSWrapper $scope, $scope.filter
, null
, $scope.manage_new_data
,=>
$scope.sock = new SockJS(@path)
$scope.sock.onopen = =>
$scope.sock.send JSON.stringify $scope.filter
$scope.sock.onclose = =>
$timeout $scope.open, 5000
$scope.sock.onmessage = (msg) =>
console.log 'Got something'
console.log msg
data = msg.data[0]
action = msg.data[1]
unless data instanceof Array then data = [data]
$scope.$apply =>
$scope.manage_new_data data, action
$scope.open()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment