mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
Buffer toDevice messages
This commit is contained in:
parent
50f46a21bd
commit
503b149e55
@ -44,6 +44,12 @@ export type Options = Omit<GroupCallOptions, "emitUpdate" | "createTimeout" | "t
|
|||||||
clock: Clock
|
clock: Clock
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type BufferedMessage = {
|
||||||
|
message: SignallingMessage<MGroupCallBase>;
|
||||||
|
userId: string;
|
||||||
|
deviceId: string;
|
||||||
|
}
|
||||||
|
|
||||||
function getRoomMemberKey(roomId: string, userId: string): string {
|
function getRoomMemberKey(roomId: string, userId: string): string {
|
||||||
return JSON.stringify(roomId)+`,`+JSON.stringify(userId);
|
return JSON.stringify(roomId)+`,`+JSON.stringify(userId);
|
||||||
}
|
}
|
||||||
@ -51,6 +57,7 @@ function getRoomMemberKey(roomId: string, userId: string): string {
|
|||||||
export class CallHandler implements RoomStateHandler {
|
export class CallHandler implements RoomStateHandler {
|
||||||
// group calls by call id
|
// group calls by call id
|
||||||
private readonly _calls: ObservableMap<string, GroupCall> = new ObservableMap<string, GroupCall>();
|
private readonly _calls: ObservableMap<string, GroupCall> = new ObservableMap<string, GroupCall>();
|
||||||
|
private _bufferedDeviceMessages = new Map<string, Set<BufferedMessage>>();
|
||||||
// map of `"roomId","userId"` to set of conf_id's they are in
|
// map of `"roomId","userId"` to set of conf_id's they are in
|
||||||
private roomMemberToCallIds: Map<string, Set<string>> = new Map();
|
private roomMemberToCallIds: Map<string, Set<string>> = new Map();
|
||||||
private groupCallOptions: GroupCallOptions;
|
private groupCallOptions: GroupCallOptions;
|
||||||
@ -190,6 +197,17 @@ export class CallHandler implements RoomStateHandler {
|
|||||||
handleDeviceMessage(message: SignallingMessage<MGroupCallBase>, userId: string, deviceId: string, log: ILogItem) {
|
handleDeviceMessage(message: SignallingMessage<MGroupCallBase>, userId: string, deviceId: string, log: ILogItem) {
|
||||||
// TODO: buffer messages for calls we haven't received the state event for yet?
|
// TODO: buffer messages for calls we haven't received the state event for yet?
|
||||||
const call = this._calls.get(message.content.conf_id);
|
const call = this._calls.get(message.content.conf_id);
|
||||||
|
if (!call) {
|
||||||
|
const id = message.content.conf_id;
|
||||||
|
const set = this._bufferedDeviceMessages.get(id);
|
||||||
|
const buffer = { message, userId, deviceId };
|
||||||
|
if (set) {
|
||||||
|
set.add(buffer);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this._bufferedDeviceMessages.set(id, new Set([buffer]));
|
||||||
|
}
|
||||||
|
}
|
||||||
call?.handleDeviceMessage(message, userId, deviceId, log);
|
call?.handleDeviceMessage(message, userId, deviceId, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +231,18 @@ export class CallHandler implements RoomStateHandler {
|
|||||||
roomId: roomId
|
roomId: roomId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.applyBufferedMessagesToCall(call, log);
|
||||||
|
}
|
||||||
|
|
||||||
|
private applyBufferedMessagesToCall(call: GroupCall, log: ILogItem) {
|
||||||
|
const id = call.id;
|
||||||
|
const buffers = this._bufferedDeviceMessages.get(id);
|
||||||
|
if (buffers) {
|
||||||
|
for (const buffer of buffers) {
|
||||||
|
const { message, userId, deviceId } = buffer;
|
||||||
|
call.handleDeviceMessage(message, userId, deviceId, log);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCallMemberEvent(event: StateEvent, member: RoomMember, roomId: string, log: ILogItem) {
|
private handleCallMemberEvent(event: StateEvent, member: RoomMember, roomId: string, log: ILogItem) {
|
||||||
|
Loading…
Reference in New Issue
Block a user