Improve stream broadcast

pull/725/head
Rodrigo Nascimento 10 years ago
parent 405c2b84c2
commit c750384e2c
  1. 26
      server/stream/streamBroadcast.coffee

@ -18,11 +18,11 @@
connections[record.extraInformation.port].disconnect()
delete connections[record.extraInformation.port]
broadcast = (streamName, eventName, args, userId) ->
broadcast = (streamName, args, userId) ->
for port, connection of connections
if connection.status().connected is true
console.log 'broadcast to', port, streamName, eventName, args
connection.call 'stream', streamName, eventName, args
console.log 'broadcast to', port, streamName, args
connection.call 'stream', streamName, args
Meteor.methods
@ -36,16 +36,20 @@
for streamName, stream of streams
do (streamName, stream) ->
emitters[streamName] = stream.emit
stream.emit = (eventName, args...) ->
broadcast streamName, eventName, args
emitters[streamName].apply {}, arguments
emitters[streamName] = stream.emitToSubscriptions
stream.emitToSubscriptions = (args, subscriptionId, userId) ->
if subscriptionId isnt 'broadcasted'
broadcast streamName, args
emitters[streamName] args, subscriptionId, userId
Meteor.methods
stream: (streamName, eventName, args) ->
console.log 'method stream', streamName, eventName, args
args.unshift eventName
emitters[streamName]?.apply {}, args
stream: (streamName, args) ->
console.log 'method stream', streamName, args
if not emitters[streamName]?
console.log "Stream for broadcast with name #{streamName} does not exists".red
else
emitters[streamName].call null, args, 'broadcasted'
Meteor.startup ->

Loading…
Cancel
Save