Signals
Signals are small messages, with a payload of up to 64 bytes. Like messages, signals are replicated to all global data centers but its pricing is far lower, making signals ideal for high-volume streams of data.
Maximum size of signal payload
By default, signals are limited to a message payload size of 64
bytes. This limit applies only to the payload, and not to the URI or headers. If you require a larger payload size, please contact support.
Don't JSON serialize
You shouldn't JSON serialize when sending signals/messages via PubNub. The serialization is done for you automatically. If you are sending JSON, just pass the full object as the message payload. PubNub takes care of everything for you.
State Shape
The data about an individual signal is stored as a slice in a normalized pool of Signals. The following example shows the shape of a list of Signals in the store:
{
"byId": {
"introductions": [
{
"channel": "introductions",
"subscription": {},
"timetoken": "15724660884258083",
"publisher": "pn-f3164dfb-dbde-4c6a-8d7e-e939a2c4dadb",
"message": {
"type": "signal_type"
}
}
]
}
}
Reducers
The PubNub Redux framework provides reducers your app can implement that respond to various actions that update the store. To track the state of a set of objects in the store, combine the reducers you want into the rootReducer for your app.
createSignalReducer
createSignalReducer
instantiates a reducer in the store that responds to actions dispatched to update the state of signals in the store.
createSignalReducer();
Listeners
The PubNub Redux framework includes listeners that monitor PubNub events from the server and dispatch corresponding actions. All listeners are automatically invoked if your app registers the combined PubNub listener. You can register only specific listeners, or implement your own combine listeners function.
createSignalListener
createSignalListener
registers a listener in the store that monitors when signals are received from the server, and dispatches corresponding actions to update the store.
A sample implementation of a signal listener:
pubnub.addListener(createSignalListener(store.dispatch));
Commands
The PubNub Redux framework provides commands that your app can dispatch to the store to be managed by the Thunk middleware. Commands interact with the PubNub API and dispatch basic actions which are then processed by reducers to update the state in the store.
sendSignal
Send a signal packaged in a request object.
sendSignal( request, [meta] );
sendSignal Arguments
Parameter | Type | Required | Description |
---|---|---|---|
request | MessageContentType | Yes | Message content request parameter object. |
[meta] | object | Optional | Standard meta options object. |
MessageContentType Properties
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
message | object | Yes | n/a | The message may be any valid JSON type, including objects, arrays, strings, and numbers. |
channel | string | Yes | n/a | The channel name to publish messages to. |
sendSignal Sample Usage
dispatch(sendSignal({
message: {
type: 'signal_type'
}
channel: 'space_ac4e67b98b34b44c4a39466e93e',
}
}));