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
|
- Source:
Returns:
The created notifier client
- Type
- Object
Methods
-
connect(options)
-
Connect the client to the messaging service
Parameters:
Name Type Argument Description optionsObject <optional>
Options to pass to the connect method Properties
Name Type Argument Description urlString <optional>
The URL for the messaging service. This url will override and reset any connectURL specified when the client was created. protocols_whitelistArray <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']" onConnectFunction <optional>
callback to be executed when a connection is established and hello message has been acknowledged onConnectErrorFunction <optional>
callback to be executed when connecting to a service is unsuccessful onCloseFunction <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 onDisconnectFunction <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 channelsObject | 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. resetBoolean <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 channelsObject | 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 );