Adapter: SimplePush

AeroGear.Notifier.adapters. SimplePush

new SimplePush(clientName, settings) → {Object}

Status: Experimental
This adapter allows communication with the AeroGear implementation of the SimplePush server protocol. Most of this functionality will be hidden behind the SimplePush client polyfill but is accessible if necessary.
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
connectURL String <optional>
"" defines the URL for connecting to the messaging service
useNative Boolean <optional>
false Create a WebSocket connection to the Mozilla SimplePush server instead of a SockJS connection to a custom server
Source:
Returns:
The created notifier client
Type
Object

Methods

connect(options)

Connect the client to the messaging service
Parameters:
Name Type Argument Description
options Object <optional>
Options to pass to the connect method
Properties
Name Type Argument Description
url String <optional>
The URL for the messaging service. This url will override and reset any connectURL specified when the client was created.
protocols_whitelist Array <optional>
A list protocols that may be used by SockJS. By default all available protocols will be used, which is equivalent to supplying: "['websocket', 'xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']"
onConnect Function <optional>
callback to be executed when a connection is established and hello message has been acknowledged
onConnectError Function <optional>
callback to be executed when connecting to a service is unsuccessful
onClose Function <optional>
callback to be executed when a connection to the server is closed
Source:
Example
    var SPNotifier = AeroGear.Notifier({
        name: "sp",
        type: "SimplePush",
        settings: {
            connectURL: "http://localhost:7777/simplepush"
        }
    }).clients.sp;

    // Use all defaults
    SPNotifier.connect();

    // Custom options
    SPNotifier.connect({
        simplePushServerURL: "http://some.other.domain",
        onConnect: spConnect,
        onClose: spClose
    });

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
    var SPNotifier = AeroGear.Notifier({
        name: "sp",
        type: "SimplePush",
        settings: {
            connectURL: "http://localhost:7777/simplepush"
        }
    }).clients.sp;

    // Default
    SPNotifier.disconnect();

    // Pass disconnect callback
    SPNotifier.disconnect(function() {
        console.log("Disconnected");
    });

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. At a minimum, each channel should contain a requestObject which will eventually contain the subscription success callback. Reused channels may also contain channelID and other metadata.
reset Boolean <optional>
if true, remove all channels from the set and replace with the supplied channel(s)
Source:
Example
    var SPNotifier = AeroGear.Notifier({
        name: "sp",
        type: "SimplePush",
        settings: {
            connectURL: "http://localhost:7777/simplepush"
        }
    }).clients.sp;

    SPNotifier.subscribe({
        requestObject: {},
        callback: function( message ) {
            console.log("Notification Received");
        }
    });

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
    var SPNotifier = AeroGear.Notifier({
        name: "sp",
        type: "SimplePush",
        settings: {
            connectURL: "http://localhost:7777/simplepush"
        }
    }).clients.sp;

    SPNotifier.unsubscribe( channelObject );