mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Remove redis channel
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
_ = require 'underscore'
|
||||
redis = require 'redis'
|
||||
guid = require 'guid'
|
||||
|
||||
module.exports =
|
||||
class RedisChannel
|
||||
_.extend @prototype, require('event-emitter')
|
||||
|
||||
constructor: (@name) ->
|
||||
@clientId = guid.create().toString()
|
||||
|
||||
@subscribeClient = redis.createClient()
|
||||
@sendClient = redis.createClient()
|
||||
@subscribeClient.on 'error', (error) -> console.error("Error on subscribe client", error)
|
||||
@sendClient.on 'error', (error) -> console.error("Error on send client", error)
|
||||
|
||||
@subscribeClient.subscribe @name, =>
|
||||
console.log "subscribed to channel", @name
|
||||
@send 'channel:participant-joined', @clientId
|
||||
@trigger 'channel:opened'
|
||||
|
||||
@subscribeClient.on 'message', (channelName, message) =>
|
||||
return unless channelName is @name
|
||||
[senderId, eventName, args...] = JSON.parse(message)
|
||||
unless senderId is @clientId
|
||||
console.log "message on channel", eventName, args...
|
||||
@trigger(eventName, args...)
|
||||
|
||||
send: (eventName, args...) ->
|
||||
message = JSON.stringify([@clientId, eventName, args...])
|
||||
@sendClient.publish(@name, message)
|
||||
Reference in New Issue
Block a user