impl session id so EC does not ignore our messages

This commit is contained in:
Bruno Windels 2022-04-07 16:53:37 +02:00
parent fe6e7b09b5
commit 6472800387
4 changed files with 20 additions and 0 deletions

View File

@ -50,11 +50,13 @@ export class CallHandler {
// map of userId to set of conf_id's they are in // map of userId to set of conf_id's they are in
private memberToCallIds: Map<string, Set<string>> = new Map(); private memberToCallIds: Map<string, Set<string>> = new Map();
private groupCallOptions: GroupCallOptions; private groupCallOptions: GroupCallOptions;
private sessionId = makeId("s");
constructor(private readonly options: Options) { constructor(private readonly options: Options) {
this.groupCallOptions = Object.assign({}, this.options, { this.groupCallOptions = Object.assign({}, this.options, {
emitUpdate: (groupCall, params) => this._calls.update(groupCall.id, params), emitUpdate: (groupCall, params) => this._calls.update(groupCall.id, params),
createTimeout: this.options.clock.createTimeout, createTimeout: this.options.clock.createTimeout,
sessionId: this.sessionId
}); });
} }

View File

@ -61,6 +61,7 @@ export class PeerCall implements IDisposable {
private _state = CallState.Fledgling; private _state = CallState.Fledgling;
private direction: CallDirection; private direction: CallDirection;
private localMedia?: LocalMedia; private localMedia?: LocalMedia;
private seq: number = 0;
// A queue for candidates waiting to go out. // A queue for candidates waiting to go out.
// We try to amalgamate candidates into a single candidate message where // We try to amalgamate candidates into a single candidate message where
// possible // possible
@ -258,6 +259,7 @@ export class PeerCall implements IDisposable {
const content = { const content = {
call_id: callId, call_id: callId,
version: 1, version: 1,
seq: this.seq++,
}; };
// TODO: Don't send UserHangup reason to older clients // TODO: Don't send UserHangup reason to older clients
if (reason) { if (reason) {
@ -304,6 +306,7 @@ export class PeerCall implements IDisposable {
offer, offer,
[SDPStreamMetadataKey]: this.localMedia!.getSDPMetadata(), [SDPStreamMetadataKey]: this.localMedia!.getSDPMetadata(),
version: 1, version: 1,
seq: this.seq++,
lifetime: CALL_TIMEOUT_MS lifetime: CALL_TIMEOUT_MS
}; };
if (this._state === CallState.CreateOffer) { if (this._state === CallState.CreateOffer) {
@ -578,6 +581,7 @@ export class PeerCall implements IDisposable {
const answerContent: MCallAnswer<MCallBase> = { const answerContent: MCallAnswer<MCallBase> = {
call_id: this.callId, call_id: this.callId,
version: 1, version: 1,
seq: this.seq++,
answer: { answer: {
sdp: localDescription.sdp, sdp: localDescription.sdp,
type: localDescription.type, type: localDescription.type,
@ -648,6 +652,7 @@ export class PeerCall implements IDisposable {
content: { content: {
call_id: this.callId, call_id: this.callId,
version: 1, version: 1,
seq: this.seq++,
candidates candidates
}, },
}, log); }, log);

View File

@ -69,10 +69,15 @@ export interface CallReplacesTarget {
export type MCallBase = { export type MCallBase = {
call_id: string; call_id: string;
version: string | number; version: string | number;
seq: number;
} }
export type MGroupCallBase = MCallBase & { export type MGroupCallBase = MCallBase & {
conf_id: string; conf_id: string;
device_id: string;
sender_session_id: string;
dest_session_id: string;
party_id: string; // Should not need this?
} }
export type MCallAnswer<Base extends MCallBase> = Base & { export type MCallAnswer<Base extends MCallBase> = Base & {

View File

@ -33,6 +33,7 @@ export type Options = Omit<PeerCallOptions, "emitUpdate" | "sendSignallingMessag
confId: string, confId: string,
ownUserId: string, ownUserId: string,
ownDeviceId: string, ownDeviceId: string,
sessionId: string,
hsApi: HomeServerApi, hsApi: HomeServerApi,
encryptDeviceMessage: (userId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage>, encryptDeviceMessage: (userId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage>,
emitUpdate: (participant: Member, params?: any) => void, emitUpdate: (participant: Member, params?: any) => void,
@ -41,6 +42,7 @@ export type Options = Omit<PeerCallOptions, "emitUpdate" | "sendSignallingMessag
export class Member { export class Member {
private peerCall?: PeerCall; private peerCall?: PeerCall;
private localMedia?: LocalMedia; private localMedia?: LocalMedia;
private destSessionId?: string;
constructor( constructor(
public readonly member: RoomMember, public readonly member: RoomMember,
@ -140,7 +142,13 @@ export class Member {
this.peerCall = this._createPeerCall(message.content.call_id); this.peerCall = this._createPeerCall(message.content.call_id);
} }
if (this.peerCall) { if (this.peerCall) {
const prevState = this.peerCall.state;
this.peerCall.handleIncomingSignallingMessage(message, deviceId); this.peerCall.handleIncomingSignallingMessage(message, deviceId);
//if (prevState !== this.peerCall.state) {
if (!this.destSessionId) {
this.destSessionId = message.content.sender_session_id;
}
//}
} else { } else {
// TODO: need to buffer events until invite comes? // TODO: need to buffer events until invite comes?
} }