Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add 'stop', 'start' events in space stream #1027

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/restapi/src/lib/pushstream/DataModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ export class DataModifier {
return ProposedEventNames.JoinSpace;
case 'remove':
return ProposedEventNames.SpaceRemove;
case 'start':
return ProposedEventNames.StartSpace;
case 'stop':
return ProposedEventNames.StopSpace;
default:
throw new Error(`Unknown current event name: ${currentEventName}`);
}
Expand Down Expand Up @@ -431,6 +435,10 @@ export class DataModifier {
return this.mapToJoinSpaceEvent(data, includeRaw);
case 'leaveSpace':
return this.mapToLeaveSpaceEvent(data, includeRaw);
case 'start':
return this.mapToStartSpaceEvent(data, includeRaw);
case 'stop':
return this.mapToStopSpaceEvent(data, includeRaw);
default:
// If the eventType is unknown, check for known messageCategories
switch (data.messageCategory) {
Expand Down Expand Up @@ -702,4 +710,60 @@ export class DataModifier {
}
return eventData;
}

private static mapToStartSpaceEvent(data: any, includeRaw: boolean): any {
type BaseEventData = {
event: string;
origin: string;
timestamp: string;
spaceId: string;
from: string;
to: null;
raw?: {
verificationProof: string;
};
};

const eventData: BaseEventData = {
origin: data.messageOrigin,
timestamp: data.timestamp,
spaceId: data.spaceId,
from: data.from,
to: null,
event: data.eventType,
};

if (includeRaw) {
eventData.raw = { verificationProof: data.verificationProof };
}
return eventData;
}

private static mapToStopSpaceEvent(data: any, includeRaw: boolean): any {
type BaseEventData = {
event: string;
origin: string;
timestamp: string;
spaceId: string;
from: string;
to: null;
raw?: {
verificationProof: string;
};
};

const eventData: BaseEventData = {
origin: data.messageOrigin,
timestamp: data.timestamp,
spaceId: data.spaceId,
from: data.from,
to: null,
event: data.eventType,
};

if (includeRaw) {
eventData.raw = { verificationProof: data.verificationProof };
}
return eventData;
}
}
8 changes: 5 additions & 3 deletions packages/restapi/src/lib/pushstream/PushStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,12 @@ export class PushStream extends EventEmitter {

if (this.shouldEmitSpace(data.spaceId)) {
if (
data.eventType === SpaceEventType.JoinSpace ||
data.eventType === SpaceEventType.LeaveSpace ||
data.eventType === SpaceEventType.Join ||
data.eventType === SpaceEventType.Leave ||
data.eventType === MessageEventType.Request ||
data.eventType === SpaceEventType.Remove
data.eventType === SpaceEventType.Remove ||
data.eventType === SpaceEventType.Start ||
data.eventType === SpaceEventType.Stop
) {
if (shouldEmit(STREAM.SPACE)) {
this.emit(STREAM.SPACE, modifiedData);
Expand Down
8 changes: 6 additions & 2 deletions packages/restapi/src/lib/pushstream/pushStreamTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export enum GroupEventType {
export enum SpaceEventType {
CreateSpace = 'createSpace',
UpdateSpace = 'updateSpace',
JoinSpace = 'joinSpace',
LeaveSpace = 'leaveSpace',
Join = 'joinSpace',
Leave = 'leaveSpace',
Remove = 'remove',
Stop = 'stop',
Start = 'start'
}

export enum ProposedEventNames {
Expand All @@ -81,6 +83,8 @@ export enum ProposedEventNames {
LeaveSpace = 'space.participant.leave',
JoinSpace = 'space.participant.join',
SpaceRemove = 'space.participant.remove',
StartSpace = 'space.start',
StopSpace = 'space.stop'
}

export interface Profile {
Expand Down