Adapter: stompws

AeroGear.Notifier.adapters. stompws

new stompws(clientName, settings) → {Object}

Status: Deprecated
The stomp adapter uses an underlying stomp.js implementation for messaging.
Parameters:
Name Type Argument Default Description
clientName String the name used to reference this particular notifier client
settings Object <optional>
{} the settings to be passed to the adapter
Properties
Name Type Argument Default Description
autoConnect Boolean <optional>
false Automatically connect the client to the connectURL on creation IF LOGIN IS NOT NEEDED. This option is ignored and a connection is automatically established if channels are provided as the connection is necessary prior to channel subscription
connectURL String <optional>
"" defines the URL for connecting to the messaging service
onConnect Function <optional>
callback to be executed when a connection is established if autoConnect === true
onConnectError Function <optional>
callback to be executed when connecting to a service is unsuccessful if autoConnect === true
channels Array <optional>
[] a set of channel objects to which this client can subscribe. Each object should have a String address as well as a callback to be executed when a message is received on that channel.
Deprecated:
  • since 2.1.0 and will be removed in a future release.
    Source:
    Returns:
    The created notifier client
    Type
    Object
    Example
        // Create an empty Notifier
        var notifier = AeroGear.Notifier();
    
        // Create a channel object and the channel callback function
        var channelObject = {
            address: "org.aerogear.messaging.global",
            callback: channelCallback
        };
    
        function channelCallback( message ) {
            console.log( message );
        }
    
        // Add a stompws client with all the settings that will autoConnect to the server and subscribe to a channel
        notifier.add({
            name: "client1",
            type: "stompws"
            settings: {
                autoConnect: true,
                connectURL: "ws://localhost:61614/stomp",
                onConnect: function() {
                    console.log( "connected" );
                },
                onConnectError: function() {
                    console.log( "connection error" );
                },
                channels: [ channelObject ]
            }
        });

    Methods

    connect(options)

    Connect the client to the messaging service
    Parameters:
    Name Type Argument Default Description
    options Object <optional>
    {} Options to pass to the connect method
    Properties
    Name Type Argument Default Description
    login String <optional>
    login name used to connect to the server
    password String <optional>
    password used to connect to the server
    protocol String | Array <optional>
    "v11.stomp" STOMP protocol to use. Can either be a string with a single protocol or an array of protocol strings
    url String <optional>
    The URL for the messaging service. This url will override and reset any connectURL specified when the client was created.
    onConnect Function <optional>
    callback to be executed when a connection is established
    onConnectError Function <optional>
    callback to be executed when connecting to a service is unsuccessful
    host String <optional>
    name of a virtual host on the stomp server that the client wishes to connect to
    Source:
    Example
        // Create an empty Notifier
        var notifier = AeroGear.Notifier();
    
        // Create a channel object and the channel callback function
        var channelObject = {
            address: "org.aerogear.messaging.global",
            callback: channelCallback
        };
    
        function channelCallback( message ) {
            console.log( message );
        }
    
        // Add stompws clients
        notifier.add({
            name: "client1",
            type: "stompws"
            settings: {
                connectURL: "ws://localhost:61614/stomp",
                onConnect: function() {
                    console.log( "connected" );
                },
                onConnectError: function() {
                    console.log( "connection error" );
                },
                channels: [ channelObject ]
            }
        },
        {
            name: "client2",
            type: "stompws"
            settings: {
                connectURL: "ws://localhost:61614/stomp1",
                onConnect: function() {
                    console.log( "connected" );
                },
                onConnectError: function() {
                    console.log( "connection error" );
                }
            }
        });
    
        // Connect to the Server with login/password
        notifier.clients.client1.connect({
            login: "guest",
            password: "guest"
            onConnect: function() {
                console.log( "connected" );
            },
            onConnectError: function( event ) {
                console.log( "connection error", event );
            }
        });
    
        // Connect to an unsecured Server
        notifier.clients.client2.connect({
            onConnect: function() {
                console.log( "connected" );
            },
            onConnectError: function( event ) {
                console.log( "connection error", event );
            }
        });

    debug(onData)

    Set the client's debug property. Used to see the data being sent and received.
    Parameters:
    Name Type Argument Description
    onData Function <optional>
    callback to be executed when data is sent and received
    Source:
    Example
        // Log data being sent and received
        notifier.clients.client2.debug(
            function(data) {
                console.log( data );
            }
        );

    disconnect(onDisconnect)

    Disconnect the client from the messaging service
    Parameters:
    Name Type Argument Description
    onDisconnect Function <optional>
    callback to be executed when a connection is terminated
    Source:
    Example
        // Disconnect from the messaging service and pass a function to be called after disconnecting
        notifier.clients.client2.disconnect(
            function() {
                console.log( "connected" );
            }
        );

    send(channel, message)

    Send a message to a particular channel
    Parameters:
    Name Type Argument Default Description
    channel String the channel to which to send the message
    message String | Object <optional>
    "" the message object to send
    Source:
    Example
        // Send an empty message to a channel
        notifier.clients.client2.send( "jms.topic.chat" );
    
        // Send a "Hello" message to a channel
        notifier.clients.client2.send( "jms.topic.chat", "Hello" );
    
        // Send a "Hello" message as an object,  requires headers( can just be an empty object )
        notifier.clients.client2.send( "jms.topic.chat", { "headers": {}, "body": "Hello" } );
    
        // Send a "Hello" message as an object,  with non empty headers
        notifier.clients.client2.send( "jms.topic.chat", { "headers": { priority: 9 }, "body": "Hello" } );

    subscribe(channels, reset)

    Subscribe this client to a new channel
    Parameters:
    Name Type Argument Description
    channels Object | Array a channel object or array of channel objects to which this client can subscribe. Each object should have a String address as well as a callback to be executed when a message is received on that channel.
    reset Boolean <optional>
    if true, remove all channels from the set and replace with the supplied channel(s)
    Source:
    Example
        // Subscribe to a channel
        notifier.clients.client2.subscribe({
            address: "channelAddress",
            callback: function(){ ... }
        });
    
        // Subscribe to multiple channels
        notifier.clients.client2.subscribe([
            {
                address: "channelAddress1",
                callback: function(){ ... }
            },
            {
                address: "channelAddress2",
                callback: function(){ ... }
            },
        ]);
    
        // Subscribe to a channel, but first unsubscribe from all currently subscribed channels by adding the reset parameter
        notifier.clients.client2.subscribe({
            address: "channelAddress3",
            callback: function(){ ... }
        }, true );

    unsubscribe(channels)

    Unsubscribe this client from a channel
    Parameters:
    Name Type Description
    channels Object | Array a channel object or a set of channel objects to which this client nolonger wishes to subscribe
    Source:
    Example
        // Unsubscribe from a channel
        notifier.clients.client2.unsubscribe({
            address: "channelAddress",
            callback: function(){ ... }
        });
    
        // Unsubscribe from multiple channels
        notifier.clients.client2.unsubscribe([
            {
                address: "channelAddress1",
                callback: function(){ ... }
            },
            {
                address: "channelAddress2",
                callback: function(){ ... }
            },
        ]);