Skip to content

Commit

Permalink
Add authorization subscription to presence store
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbonial committed Sep 20, 2024
1 parent 4a43ff2 commit b0dc1a0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ type RollCallEvent = {
session: string
}

type IncomingBifurEvent<T> = RollCallEvent | BifurStateMessage | BifurDisconnectMessage
type ExpireEvent = {
type: 'expires'
event: 'expires'
at: string
}

type IncomingBifurEvent<T> =
| RollCallEvent
| BifurStateMessage
| BifurDisconnectMessage
| ExpireEvent

const handleIncomingMessage = (event: IncomingBifurEvent<Location[]>): TransportEvent => {
// console.log('ws incoming event', event)
Expand Down Expand Up @@ -57,14 +67,13 @@ const handleIncomingMessage = (event: IncomingBifurEvent<Location[]>): Transport
}
}

// if (event.type === 'subscription') {
// return {
// type: 'subscription',
// userId: event.i,
// sessionId: event.m.session,
// timestamp: new Date().toISOString(),
// }
// }
if (event.event === 'expires') {
return {
type: 'authorizationExpire',
expiresAt: event.at,
timestamp: new Date().toISOString(),
}
}

throw new Error(`Got unknown presence event: ${JSON.stringify(event)}`)
}
Expand All @@ -78,12 +87,13 @@ export const createBifurTransport = (bifur: BifurClient, sessionId: string): Tra
.listen<IncomingBifurEvent<Location[]>>('authorization')
.pipe(map(handleIncomingMessage))

const testIncomingAuthorizationEvents$: Observable<TransportEvent> = bifur
.listen<IncomingBifurEvent<Location[]>>('authorization')
.subscribe((event) => {
// eslint-disable-next-line no-console
console.log('[++++++]Authorization event', event)
})
// const testIncomingAuthorizationEvents$: Observable<TransportEvent> = bifur
// .listen<IncomingBifurEvent<Location[]>>('authorization')
// .pipe(map(handleIncomingMessage))
// .subscribe((event) => {
// // eslint-disable-next-line no-console
// console.log('[++++++]Authorization event', event)
// })

const dispatchMessage = (message: TransportMessage): Observable<undefined> => {
if (message.type === 'rollCall') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,21 @@ export interface RollCallEvent extends RollCallMessage {
userId: string
}

export type TransportMessage = DisconnectMessage | StateMessage | RollCallMessage
export type TransportEvent = StateEvent | RollCallEvent | DisconnectEvent
export interface AuthorizationExpireMessage {
type: 'authorizationExpire'
}

export interface AuthorizationExpireEvent extends AuthorizationExpireMessage {
expiresAt: string
timestamp: string
}

export type TransportMessage =
| DisconnectMessage
| StateMessage
| RollCallMessage
| AuthorizationExpireMessage
export type TransportEvent = StateEvent | RollCallEvent | DisconnectEvent | AuthorizationExpireEvent

// This is the interface a transport must implement
export type Transport = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export function __tmp_wrap_presenceStore(context: {
SESSION_ID,
)

authorizationEvents$.subscribe((event) => {
// console.log('[++++++]Authorization event', event)
})

const currentLocation$ = new BehaviorSubject<PresenceLocation[]>([])
const locationChange$ = currentLocation$.pipe(distinctUntilChanged())

Expand Down

0 comments on commit b0dc1a0

Please sign in to comment.