Class: WAMP::Protocols::Version1

Inherits:
Object
  • Object
show all
Defined in:
lib/wamp/protocols/version_1.rb

Overview

Describes the WAMP protocol messages per www.wamp.ws/spec#call_message

Instance Method Summary collapse

Instance Method Details

#call(call_id, proc_uri, *args) ⇒ String

Builds the RPC CALL message (client to server) [ TYPE_ID_CALL , callID , procURI , … ]

Parameters:

  • call_id (String)

    This should be a randomly generated string to identify the RPC call, the call ID will be returned to the client in the

    RPC CALLRESULT or CALLERROR messages.
    
  • proc_uri (String)

    The procURI is a string that identifies the remote procedure to be called and MUST be a valid URI or CURIE.

  • *args (Array)

    Zero or more additional arguments to be sent with the CALL message.

Returns:

  • (String)

    The CALL message as a JSON string



40
41
42
# File 'lib/wamp/protocols/version_1.rb', line 40

def call(call_id, proc_uri, *args)
  [type[:CALL], call_id, proc_uri, *args].to_json
end

#call_error(call_id, error_uri, error_desc, error_details = nil) ⇒ String

Builds the RPC CALLERROR message (server to client) [ TYPE_ID_CALLERROR , callID , errorURI , errorDesc , errorDetails(Optional) ]

Parameters:

  • call_id (String)

    This should match the call ID given by the client by the client.

  • error_uri (String)

    A CURIE or URI identifying the error.

  • error_desc (String)

    A description of the error that occured.

  • error_details (String) (defaults to: nil)

    Optional. Used to communicate application error details, defined by the error_uri.

Returns:

  • (String)

    The ERRORRESULT message as a JSON string.



64
65
66
67
68
# File 'lib/wamp/protocols/version_1.rb', line 64

def call_error(call_id, error_uri, error_desc, error_details = nil)
  msg = [type[:CALLERROR], call_id, error_uri, error_desc, error_details]
  msg.delete_if { |x| x.nil? }
  msg.to_json
end

#call_result(call_id, result = nil) ⇒ String

Builds the RPC CALLRESULT message (server to client) [ TYPE_ID_CALLRESULT , callID , result ]

Parameters:

  • call_id (String)

    This should match the call ID given by the client by the client.

  • result (String, Integer, Hash, Array) (defaults to: nil)

    The results of the RPC procedure initiated by the CALL. Defaults to nil of non is given.

Returns:

  • (String)

    The CALLRESULT message as a JSON string.



51
52
53
# File 'lib/wamp/protocols/version_1.rb', line 51

def call_result(call_id, result = nil)
  [type[:CALLRESULT], call_id, result].to_json
end

#event(topic_uri, event) ⇒ String

Builds the PubSub EVENT message (server to client)

[ TYPE_ID_EVENT , topicURI , event ]

Parameters:

  • topic_uri (String)

    The topic URI or CURIE to publish the event to.

  • event (String, Array, Hash)

    The payload to be delivered to the clients

Returns:

  • (String)

    The EVENT message as a JSON string.



114
115
116
# File 'lib/wamp/protocols/version_1.rb', line 114

def event(topic_uri, event)
  [type[:EVENT], topic_uri, event].to_json
end

#prefix(prefix, uri) ⇒ String

Builds the PREFIX message (client to server) [ TYPE_ID_PREFIX , prefix , URI ]

Parameters:

  • prefix (String)

    The shortened CURIE prefix to be registered.

  • uri (String)

    The full URI to register the prefix to.

Returns:

  • (String)

    The PREFIX message as a JSON string.



26
27
28
# File 'lib/wamp/protocols/version_1.rb', line 26

def prefix(prefix, uri)
  [type[:PREFIX], prefix, uri].to_json
end

#publish(topic_uri, event, exclude = nil, elgible = nil) ⇒ String

Builds the PubSub PUBLISH message (client to server) [ TYPE_ID_PUBLISH , topicURI , event ] [ TYPE_ID_PUBLISH , topicURI , event , excludeMe ] [ TYPE_ID_PUBLISH , topicURI , event , exclude , eligible ]

Parameters:

  • topic_uri (String)

    The topic URI or CURIE to publish the event to.

  • payload (String, Array, Hash)

    The payload to be delivered to the server.

  • exclude (true, false, Array<String>) (defaults to: nil)

    Optional. Determines which clients to exclude from the delivery of the event from the server, you can give true or false will exclude/include the sending client, or give an Array of client ID’s to exclude.

  • elgible (Array<String>) (defaults to: nil)

    Optional. An array lf client ID’s elgible to receive the published message.

Returns:

  • (String)

    The PUBLISH message as a JSON string.



101
102
103
104
105
106
107
# File 'lib/wamp/protocols/version_1.rb', line 101

def publish(topic_uri, event, exclude = nil, elgible = nil)
  msg = [type[:PUBLISH], topic_uri, event]
  msg[3] = exclude unless exclude.nil?
  msg[4] = elgible unless elgible.nil?

  msg.to_json
end

#subscribe(topic_uri) ⇒ String

Builds the PubSub SUBSCRIBE message (client to server) [ TYPE_ID_SUBSCRIBE , topicURI ]

Parameters:

  • topic_uri (String)

    The topic URI or CURIE (from PREFIX) to receive published events to the given topic.

Returns:

  • (String)

    The SUBSCRIBE message as a JSON string.



75
76
77
# File 'lib/wamp/protocols/version_1.rb', line 75

def subscribe(topic_uri)
  [type[:SUBSCRIBE], topic_uri].to_json
end

#unsubscribe(topic_uri) ⇒ String

Builds the PubSub UNSUBSCRIBE message (client to server) [ TYPE_ID_UNSUBSCRIBE , topicURI ]

Parameters:

  • topic_uri (String)

    The topic URI or CURIE to unsubscribe from.

Returns:

  • (String)

    The UNSUBSCRIBE message as a JSON string.



83
84
85
# File 'lib/wamp/protocols/version_1.rb', line 83

def unsubscribe(topic_uri)
  [type[:UNSUBSCRIBE], topic_uri].to_json
end

#versionInteger

Returns The version of the WAMP protocol defined in this class.

Returns:

  • (Integer)

    The version of the WAMP protocol defined in this class.



8
9
10
# File 'lib/wamp/protocols/version_1.rb', line 8

def version
  1
end

#welcome(id) ⇒ String

Builds the WELCOME message (server to client) [ TYPE_ID_WELCOME , sessionId , protocolVersion, serverIdent ]

Parameters:

  • client_id (String)

    The server generated ID that the WELCOME message is to be sent to.

Returns:

  • (String)

    The WELCOME message as a JSON string.



17
18
19
# File 'lib/wamp/protocols/version_1.rb', line 17

def welcome(id)
  [type[:WELCOME], id, version, server_ident].to_json
end