subscribe()

subscribe(topicURI, onEvent[, advancedOptions])

Subscribes for topicURI events.

Input Parameters:

  • topicURI. Required. A string that identifies the topic. Must meet a WAMP Spec URI requirements.

  • onEvent. Published event callback. Will be called on receiving published event with one hash-table parameter with following attributes:

    • argsList: array payload (maybe omitted)

    • argsDict: object payload (maybe omitted)

    • details: some publication options object.

  • advancedOptions. Optional parameters hash table. Must include any or all of the options:

    • match: string matching policy ("prefix"|"wildcard")

Returns promise:

  • Resolved with one hash-table parameter with following attributes:

    • topic

    • requestId

    • subscriptionId

    • subscriptionKey

  • Rejected with one of the Errors instances

await ws.subscribe('chat.message.received', function (eventData) { console.log('Received new chat message!', eventData); });

try {
    let res = await ws.subscribe('some.another.topic',
        function (eventData) { console.log('Received topic event', eventData); }
    );
    console.log('Successfully subscribed to topic: ' + res.topic);

} catch (e) {
    console.log('Subscription error:' + e.error);
}

Last updated