UNPKG

shift-admin-ui-kit

Version:
23 lines (17 loc) 614 B
import { liveMessagingConfigured, liveMessage } from '../actions' import Pusher from 'pusher-js' export default function PusherMessaging(config, dispatch) { if (config && config.pusher && config.pusher.key) { const account_reference = config.account_reference const socket = new Pusher(config.pusher.key, { cluster: config.pusher.cluster, encrypted: true }) const channel = socket.subscribe(account_reference) function broadcastEvent(event, data) { dispatch(liveMessage(data)) } channel.bind_global(broadcastEvent) dispatch(liveMessagingConfigured()) } }