redux-saga-centrifuge
v1.0.1
Published
redux-saga-centrifuge encapsulates Centrifuge client initialization and broadcasts centrifuge channel events to redux-saga eventChannels
Downloads
3
Readme
redux-saga-centrifuge
Description
redux-saga-centrifuge
is a proxy between Centrifuge client and application middleware.
It encapsulates Centrifuge client initialization and broadcasts centrifuge channel events to redux-saga eventChannels
Installation
npm install @kismia/redux-saga-centrifuge
Usage
Initialize new Centrifuge client instance by calling initConnection method.
the first parameter is required, it should be a config object for Centrifuge client initialization.
Second parameter id optional, Map of centrifuge events handlers can be passed.
For more information about centrifuge client events read Client API
section on
centrifuge-js documentation
import { initConnection } from '@kismia/redux-saga-centrifuge';
export function* startCentrifuge() {
while (true) {
try {
yield take(setWebSocketConnection);
const { config } = yield call(getConfig);
yield call(
initConnection,
config,
new Map([['connect', () => put(handleCentrifugeConnection)]])
);
} catch (error) {
// handle error
}
}
}
For centrifuge event subscription call event channel creator from the package
import { eventChannels } from '@kismia/redux-saga-centrifuge/eventChannels';
export function* handleChatEvents() {
const { createChatEventChannel } = eventChannels;
const chatChannel = yield call(createChatEventChannel);
try {
while (true) {
const message = yield take(chatChannel);
...
}
} catch (error) {
// handle error
}
}
For creating new event channel creator you need just add a new channel name to config/centrifugeChannels.js
and indicate it as public, if needed.