Class: Landline::Handlers::WebSockServer

Inherits:
Probe
  • Object
show all
Defined in:
lib/landline/extensions/websocket.rb

Overview

Web socket server handler

Instance Attribute Summary

Attributes inherited from Probe

#properties

Attributes inherited from Node

#remap, #root

Instance Method Summary collapse

Methods inherited from Node

#go, #reject

Constructor Details

#initialize(path, parent:, **params, &callback) ⇒ WebSockServer

Returns a new instance of WebSockServer.

Parameters:

  • path (Object)
  • parent (Landline::Node)
  • params (Hash)

    options hash

  • callback (#call)

    callback to process request within

Options Hash (**params):

  • :version (Integer)

    protocol version

  • :protocols (Array<String>)

    array of supported sub-protocols

  • :secure (Boolean)

    true if the server will use wss:// protocol



247
248
249
250
251
252
253
254
255
# File 'lib/landline/extensions/websocket.rb', line 247

def initialize(path, parent:, **params, &callback)
  nodeparams = params.dup
  nodeparams.delete(:version)
  nodeparams.delete(:protocols)
  nodeparams.delete(:secure)
  super(path, parent: parent, **nodeparams)
  @callback = callback
  @params = params
end

Instance Method Details

#process(request) ⇒ Object

Method callback on successful request navigation Creates a websocket from a given request

Parameters:



260
261
262
263
264
265
266
267
268
# File 'lib/landline/extensions/websocket.rb', line 260

def process(request)
  @callback.call(
    Landline::WebSocket::WSockWrapper.handshake(
      request,
      **@params
    )
  )
  ""
end