Skip to content

Commit

Permalink
Isolate the syncedStreamEvents (#252)
Browse files Browse the repository at this point in the history
I am investigating reusing this class in the sync agent, this makes it a
little easier
  • Loading branch information
texuf authored Jun 24, 2024
1 parent 981b651 commit 508c019
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions packages/sdk/src/streamEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export type StreamEncryptionEvents = {
userDeviceKeyMessage: (streamId: string, userId: string, userDevice: UserDevice) => void
}

export type SyncedStreamEvents = {
streamSyncStateChange: (newState: SyncState) => void
streamRemovedFromSync: (streamId: string) => void
streamSyncActive: (active: boolean) => void
}

/// Stream state events, emitted after initialization
export type StreamStateEvents = {
clientInitStatusUpdated: (status: ClientInitStatus) => void
Expand All @@ -51,8 +57,6 @@ export type StreamStateEvents = {
streamUserLeft: (streamId: string, userId: string) => void
streamMembershipUpdated: (streamId: string, userId: string) => void
streamPendingMembershipUpdated: (streamId: string, userId: string) => void
streamSyncActive: (active: boolean) => void
streamSyncStateChange: (newState: SyncState) => void
userJoinedStream: (streamId: string) => void
userInvitedToStream: (streamId: string) => void
userLeftStream: (streamId: string) => void
Expand Down Expand Up @@ -87,7 +91,6 @@ export type StreamStateEvents = {
streamEnsAddressUpdated: (streamId: string, userId: string) => void
streamNftUpdated: (streamId: string, userId: string) => void
streamChannelPropertiesUpdated: (streamId: string) => void
streamRemovedFromSync: (streamId: string) => void
}

export type StreamEvents = StreamEncryptionEvents & StreamStateEvents
export type StreamEvents = StreamEncryptionEvents & StreamStateEvents & SyncedStreamEvents
6 changes: 3 additions & 3 deletions packages/sdk/src/syncedStreams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Err, SyncCookie, SyncOp, SyncStreamsResponse } from '@river-build/proto
import { DLogger, dlog, dlogError, shortenHexString } from '@river-build/dlog'
import { StreamRpcClient, errorContains } from './makeStreamRpcClient'
import { unpackStream, unpackStreamAndCookie } from './sign'
import { StreamStateEvents } from './streamEvents'
import { SyncedStreamEvents } from './streamEvents'
import { SyncedStream } from './syncedStream'
import TypedEmitter from 'typed-emitter'
import { isDefined } from './check'
Expand Down Expand Up @@ -74,7 +74,7 @@ export class SyncedStreams {
private readonly logSync: DLogger
private readonly logError: DLogger
// clientEmitter is used to proxy the events from the streams to the client
private readonly clientEmitter: TypedEmitter<StreamStateEvents>
private readonly clientEmitter: TypedEmitter<SyncedStreamEvents>

// Starting the client creates the syncLoop
// While a syncLoop exists, the client tried to keep the syncLoop connected, and if it reconnects, it
Expand Down Expand Up @@ -112,7 +112,7 @@ export class SyncedStreams {
constructor(
userId: string,
rpcClient: StreamRpcClient,
clientEmitter: TypedEmitter<StreamStateEvents>,
clientEmitter: TypedEmitter<SyncedStreamEvents>,
) {
this.userId = userId
this.rpcClient = rpcClient
Expand Down

0 comments on commit 508c019

Please sign in to comment.