Skip to content

Commit

Permalink
[base] Upgrade bifur client
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent cc8b82c commit d6d91c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/@sanity/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"homepage": "https://www.sanity.io/",
"dependencies": {
"@sanity/bifur-client": "^0.0.5",
"@sanity/bifur-client": "^0.0.7",
"@sanity/client": "1.150.7",
"@sanity/color": "^1.0.0",
"@sanity/components": "1.150.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import {map, mergeMapTo, share, switchMapTo, tap, switchMap} from 'rxjs/operators'
import {EMPTY, fromEvent, merge, Observable, defer} from 'rxjs'
import {Observable, EMPTY} from 'rxjs'
import {map, share} from 'rxjs/operators'
import {BifurClient} from '@sanity/bifur-client'
import {PresenceLocation} from '../types'
import {Transport, TransportEvent, TransportMessage} from './transport'

Expand Down Expand Up @@ -58,23 +58,27 @@ const handleIncomingMessage = (event: IncomingBifurEvent<Location[]>): Transport
throw new Error(`Got unknown presence event: ${JSON.stringify(event)}`)
}

export const createBifurTransport = (bifur, sessionId: string): Transport => {
export const createBifurTransport = (bifur: BifurClient, sessionId: string): Transport => {
const incomingEvents$: Observable<TransportEvent> = bifur
.request('presence')
.request<IncomingBifurEvent<Location[]>>('presence')
.pipe(map(handleIncomingMessage))

const dispatchMessage = (message: TransportMessage) => {
const dispatchMessage = (message: TransportMessage): Observable<undefined> => {
if (message.type === 'rollCall') {
return bifur.request('presence_rollcall', {session: sessionId})
}

if (message.type === 'state') {
return bifur.request('presence_announce', {
data: {locations: message.locations, sessionId}
})
}

if (message.type === 'disconnect') {
return bifur.request('presence_disconnect', {session: sessionId})
}

return EMPTY
}

return [incomingEvents$.pipe(share()), dispatchMessage]
Expand Down

0 comments on commit d6d91c8

Please sign in to comment.