First up get your hub events as a observable. I adapted this code to work against ASP.NET Core SignalR.
Then create a epic to start the hub (I am using typescript), dispatch that action somewhere on startup.
const startNotificationHubEpic: Epic<RootAction, RootAction, RootState, Services> = (action$, store, { notificationHub }) => {
return action$.pipe(
filter(isActionOf(startNotificationHub.request)),
switchMap(action =>
from(notificationHub.start()).pipe(
map(() => startNotificationHub.success()),
catchError(err => of(startNotificationHub.failure(err)))
)));
}
Finally use the startNotificationHub.success action to start listening to rsjx streams of events on the hub for every event you are interested in.
const listenForMessageEpic: Epic<RootAction, RootAction, RootState, Services> = (action$, store, { notificationHub }) => {
return action$.pipe(
filter(isActionOf(startNotificationHub.success)),
switchMap(act =>
notificationHub.on("Message", (messag: string) => ({message})).pipe(
map(notif => onMessage(notif))
)));
}
The onMessage action in turn can be consumed by another epic or used in a reducer to pass the notification data through to a component.