Module: Plezi::Base::Bridge

Extended by:
Bridge
Included in:
Bridge
Defined in:
lib/plezi/controller/bridge.rb

Overview

This module bridges between the Plezi Controller and the Iodine::Connection .

Constant Summary collapse

CONTROLLER_NAME =
"plezi.controller".to_sym
CLIENT_NAME =

don’t rename without updating Controller

"@_pl__client".to_sym

Instance Method Summary collapse

Instance Method Details

#controller(client) ⇒ Object

returns a client’s controller



8
9
10
# File 'lib/plezi/controller/bridge.rb', line 8

def controller client
  client.env[CONTROLLER_NAME]
end

#on_close(client) ⇒ Object

called when the client is closed (no longer available)



32
33
34
# File 'lib/plezi/controller/bridge.rb', line 32

def on_close client
   controller(client).on_close
end

#on_drained(client) ⇒ Object

called when all the previous calls to ‘client.write` have completed (the local buffer was drained and is now empty)



37
38
39
# File 'lib/plezi/controller/bridge.rb', line 37

def on_drained client
   controller(client).on_drained
end

#on_message(client, data) ⇒ Object

called when data is available



23
24
25
# File 'lib/plezi/controller/bridge.rb', line 23

def on_message client, data
   controller(client).on_message(data)
end

#on_open(client) ⇒ Object

called when the callback object is linked with a new client



13
14
15
16
17
18
19
20
21
# File 'lib/plezi/controller/bridge.rb', line 13

def on_open client
  c = controller(client)
  c.instance_variable_set(CLIENT_NAME, client)
  if client.protocol == :sse
    c.on_sse
  else
    c.on_open
  end
end

#on_shutdown(client) ⇒ Object

called when the server is shutting down, before closing the client (it’s still possible to send messages to the client)



28
29
30
# File 'lib/plezi/controller/bridge.rb', line 28

def on_shutdown client
   controller(client).on_shutdown
end