options()

options([opts])

.options() method can be called in two forms:

  • without parameters, it will return current options

  • with one parameter as hash-table it will set new options and return Wampy instance back

Options attributes description:

  • debug. Default value: false. Enable debug logging.

  • logger. Default value: null. User-provided logging function. If debug=true and no logger specified, console.log will be used.

  • autoReconnect. Default value: true. Enable auto reconnecting. In case of connection failure, Wampy will try to reconnect to WAMP server, and if you were subscribed to any topics, or had registered some procedures, Wampy will resubscribe to that topics and reregister procedures.

  • reconnectInterval. Default value: 2000 (ms). Reconnection Interval in ms.

  • maxRetries. Default value: 25. Max reconnection attempts. After reaching this value .disconnect() will be called. Set to 0 to disable limit.

  • realm. Default value: null. WAMP Realm to join on server. See WAMP spec for additional info.

  • helloCustomDetails. Default value: null. Custom attributes to send to router on hello.

  • uriValidation. Default value: strict. Can be changed to loose for less strict URI validation.

  • authid. Default value: null. Authentication (user) id to use in challenge.

  • authmethods. Default value: []. Array of strings of supported authentication methods.

  • authextra. Default value: {}. Additional authentication options for Cryptosign-based authentication. See Cryptosign-based Authentication section and WAMP Spec CS for more info.

  • authPlugins. Default value: {}. Authentication helpers for processing different authmethods flows. It's a hash-map, where key is an authentication method and value is a function, that takes the necessary user secrets/keys and returns a function which accepts authmethod and challenge info and returns signed challenge answer. You can provide your own sign functions or use existing helpers. Functions may be asynchronous.

const wampyCra = require('wampy-cra');
const wampyCryptosign = require('wampy-cryptosign');

wampy.options({
    authPlugins: {
        // No need to process challenge data in ticket flow, as it is empty
        ticket: (function(userPassword) { return function() { return userPassword; }})(),
        wampcra: wampyCra.sign(secret),
        cryptosign: wampyCryptosign.sign(privateKey)
    },
    authMode: 'auto'
});
  • authMode. Default value: manual. Possible values: manual|auto. Mode of authorization flow. If it is set to manual - you also need to provide onChallenge callback, which will process authorization challenge. Or you can set it to auto and provide authPlugins (described above). In this case the necessary authorization flow will be chosen automatically. This allows to support few authorization methods simultaneously.

  • onChallenge. Default value: null. Callback function. It is fired when wamp server requests authentication during session establishment. This function receives two arguments: auth method and challenge details. Function should return computed signature, based on challenge details. See Challenge Response Authentication section, WAMP Spec CRA, Cryptosign-based Authentication section and WAMP Spec CS for more info. This function receives welcome details as an argument.

  • onClose. Default value: null. Callback function. Fired on closing connection to wamp server.

  • onError. Default value: null. Callback function. Fired on error in websocket communication.

  • onReconnect. Default value: null. Callback function. Fired every time on reconnection attempt.

  • onReconnectSuccess. Default value: null. Callback function. Fired every time when reconnection succeeded. This function receives welcome details as an argument.

  • ws. Default value: null. User provided WebSocket class. Useful in node environment.

  • additionalHeaders. Default value: null. User provided additional HTTP headers (for use in Node.js environment)

  • wsRequestOptions. Default value: null. User provided WS Client Config Options (for use in Node.js environment). See docs for WebSocketClient, tls.connect options.

  • serializer. Default value: JsonSerializer. User provided serializer class. Useful if you plan to use other encoders instead of default json.

  • payloadSerializers. Default value: { json: jsonSerializer }. User provided hashmap of serializer instances for using in Payload Passthru Mode. Allows to specify a few serializers and use them on per message/call basis.

wampy.options();

wampy.options({
    reconnectInterval: 1000,
    maxRetries: 999,
    onClose: function () { console.log('See you next time!'); },
    onError: function () { console.log('Breakdown happened'); },
    onReconnect: function () { console.log('Reconnecting...'); },
    onReconnectSuccess: function (welcomeDetails) { console.log('Reconnection succeeded. Details:', welcomeDetails); }
});

Last updated