Class OverSIP::WebSocket::Connection
An OverSIP::WebSocket::Connection instance involves a WebSocket connection initiated by a client.
Class instance methods
http_reject(status_code=403, reason_phrase=nil, extra_headers=nil)
This method can only be used within the OverSIP::WebSocketEvents.on_connection callback. By invoking this method the WebSocket handshake is rejected.
Parameters
status_code- The HTTP status code (
Fixnum) to reply (by default403). reason_phrase- The HTTP reason phrase (
String) for the response (by default the standard reason phrase for the given status code). extra_headers- An optional
Arrayof custom HTTP headers (Strings) to be added to the response.
Examples
connection.http_reject 403, "Origin Not Allowed", [ "Date: #{Time.now}" ]
connection.http_reject 404
close(websocket_status_code=nil, websocket_reason=nil)
If the WebSocket connection is not yet established this method closes it (optional parameters are ignored).
Otherwise, if the WebSocket connection is already established, this method sends a WebSocket Close Frame to the peer and terminates the underlying connection.
Parameters
websocket_status_code- The WebSocket Close Frame status code (by default
nil). websocket_reason- The WebSocket Close Frame reason (by
nil).
Examples
connection.close
connection.close 3012, "server is reloading"
open?
Returns true if the connection is still open, false otherwise.
remote_ip_type
Gets the remote IP type (:ipv4 or :ipv6 Symbols) of the connection.
Example
connection.remote_ip_type
#=> :ipv4
remote_ip
Gets the remote IP (String) of the connection.
Example
connection.remote_ip
#=> "1.2.3.4"
remote_port
Gets the remote port (Fixnum) of the connection.
Example
connection.remote_port
#=> 25681
transport
Gets the SIP transport (:ws or :wss Symbols) of the connection.
Example
connection.transport
#=> :ws
cvars
Connection variables. A Hash for storing custom key / values associated to this connection that can be later retrieved from SIP requests arriving through this WebSocket connection via the cvars instance method of the OverSIP::SIP::Request class.
Example
connection.cvars[:user_id] = "alice"
connection.cvars
#=> {:user_id => "alice"}