Class: FrCable::HttpHandler
- Inherits:
-
Object
- Object
- FrCable::HttpHandler
- Defined in:
- lib/fr_cable/http_handler.rb
Instance Method Summary collapse
- #channel_class(room) ⇒ Object
- #connect(connection_uuid) ⇒ Object
- #connection_class ⇒ Object
- #disconnect(connection_uuid) ⇒ Object
- #message(payload) ⇒ Object
- #subscribe(payload) ⇒ Object
- #unsubscribe(payload) ⇒ Object
Instance Method Details
#channel_class(room) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/fr_cable/http_handler.rb', line 4 def channel_class(room) @channel_class ||= {} @channel_class[room] ||= begin splited_room_name = room.split(":") splited_room_name[0].constantize.new({room: splited_room_name[1]}) end @channel_class[room] end |
#connect(connection_uuid) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/fr_cable/http_handler.rb', line 47 def connect connection_uuid result = connection_class.connected(connection_uuid) if result ::FrCable::HTTPClient.post(::FrCable::Rack.config[:socket_server_url], body: {type: 'accept_connection', payload: connection_uuid}.to_json) else ::FrCable::HTTPClient.post(::FrCable::Rack.config[:socket_server_url], body: {type: 'deny_connection', payload: connection_uuid}.to_json) end end |
#connection_class ⇒ Object
13 14 15 |
# File 'lib/fr_cable/http_handler.rb', line 13 def connection_class @connection_class ||= ::ApplicationCable::Connection.new end |
#disconnect(connection_uuid) ⇒ Object
56 57 58 |
# File 'lib/fr_cable/http_handler.rb', line 56 def disconnect connection_uuid connection_class.disconnected(connection_uuid) end |
#message(payload) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/fr_cable/http_handler.rb', line 17 def payload connection_uuid = payload["connection_uuid"] room = payload["room"] = payload["message"] channel_class(room).receive() end |
#subscribe(payload) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fr_cable/http_handler.rb', line 25 def subscribe payload connection_uuid = payload["connection"] room = payload["room"] uuid = payload["subscription"] result = channel_class(room).subscribed(connection_uuid) if result ::FrCable::HTTPClient.post(::FrCable::Rack.config[:socket_server_url], body: {type: 'accept_subscription', payload: uuid}.to_json) else ::FrCable::HTTPClient.post(::FrCable::Rack.config[:socket_server_url], body: {type: 'deny_subscription', payload: uuid}.to_json) end end |
#unsubscribe(payload) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/fr_cable/http_handler.rb', line 38 def unsubscribe payload connection_uuid = payload[:connection_uuid] room = payload[:room] uuid = payload[:uuid] channel_class(room).unsubscribed(connection_uuid) end |