Class: Citrus::Common::Remote::Frontend::ChannelRemote
- Inherits:
-
Object
- Object
- Citrus::Common::Remote::Frontend::ChannelRemote
- Defined in:
- lib/citrus/common/remote/frontend/channel_remote.rb
Overview
ChannelRemote
Instance Method Summary collapse
-
#broadcast(route, msg, args, &block) ⇒ Object
Broadcast to all the clients connected with current frontend server.
-
#initialize(app) ⇒ ChannelRemote
constructor
Create a new remote channel service.
-
#pushMessage(route, msg, uids, args, &block) ⇒ Object
Push message to client by uids.
Constructor Details
#initialize(app) ⇒ ChannelRemote
Create a new remote channel service
25 26 27 |
# File 'lib/citrus/common/remote/frontend/channel_remote.rb', line 25 def initialize app @app = app end |
Instance Method Details
#broadcast(route, msg, args, &block) ⇒ Object
Broadcast to all the clients connected with current frontend server
65 66 67 68 |
# File 'lib/citrus/common/remote/frontend/channel_remote.rb', line 65 def broadcast route, msg, args, &block connector = @app.components['connector'] connector.send nil, route, msg, nil, args, &block end |
#pushMessage(route, msg, uids, args, &block) ⇒ Object
Push message to client by uids
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/citrus/common/remote/frontend/channel_remote.rb', line 35 def pushMessage route, msg, uids, args, &block if msg.empty? block_given? and yield Exception.new 'can not send empty message' return end connector = @app.components['connector'] session_service = @app.session_service sids = []; fails = [] uids.each { |uid| sessions = session_service.get_by_uid uid if sessions sessions.each { |session| sids << session.id } else fails << uid end } connector.send(nil, route, msg, sids, args) { |err| block_given? and yield err, fails } end |