Class: Mooncell::Protocol::WebSocket Private

Inherits:
Object
  • Object
show all
Includes:
Mooncell::Protocol
Defined in:
lib/mooncell/protocol/websocket.rb,
lib/mooncell/protocol/websocket/server.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

WebSocket Protocol

Since:

  • 0.1.0

Defined Under Namespace

Classes: Server

Constant Summary collapse

BAD_RESPONSE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

[
  400,
  {},
  []
].freeze

Instance Method Summary collapse

Methods included from Mooncell::Protocol

get, included

Constructor Details

#initialize(app) ⇒ WebSocket

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create protocol instance

TODO: Generalize protocol behaviors

Since:

  • 0.1.0



27
28
29
# File 'lib/mooncell/protocol/websocket.rb', line 27

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Implement Rack interface

Parameters:

  • env (Hash)

    the rack environment

Since:

  • 0.1.0



45
46
47
48
49
# File 'lib/mooncell/protocol/websocket.rb', line 45

def call(env)
  return BAD_RESPONSE unless Faye::WebSocket.websocket?(env)

  WebSocket::Server.new(app, env).rack_response
end

#optionsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return options

Returns:

  • (Hash)

    the server options

Since:

  • 0.1.0



57
58
59
60
61
# File 'lib/mooncell/protocol/websocket.rb', line 57

def options
  {
    Port: app.configuration.port
  }
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Start Server

Since:

  • 0.1.0



35
36
37
# File 'lib/mooncell/protocol/websocket.rb', line 35

def start
  Rack::Handler.default.run(self, options)
end