Class: Startback::Websocket::Hub::App

Inherits:
App
  • Object
show all
Defined in:
lib/startback/websocket/hub/app.rb

Overview

The Hub is a very opinionated websocket protocol based on room and subscriptions, allowing users to subscribe to rooms etc etc… # TODO

Direct Known Subclasses

Room

Constant Summary

Constants inherited from App

App::JS_CLIENT

Instance Method Summary collapse

Methods inherited from App

#broadcast, #call, #on_close, #on_error, #on_open

Constructor Details

#initialize(context, rooms, handler) ⇒ App

Returns a new instance of App.



11
12
13
14
15
# File 'lib/startback/websocket/hub/app.rb', line 11

def initialize(context, rooms, handler)
  super(context)
  @handler = handler
  @rooms = rooms
end

Instance Method Details

#on_message(event, ws, env) ⇒ Object



21
22
23
# File 'lib/startback/websocket/hub/app.rb', line 21

def on_message(event, ws, env)
  @handler.call(Message.new(event.data, ws), ws, env)
end

#room(name) ⇒ Object



17
18
19
# File 'lib/startback/websocket/hub/app.rb', line 17

def room(name)
  @rooms[name]
end