diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 1d2a66e00..2151017a8 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -28,6 +28,7 @@ import MatrixEvent from '../models/event'; import {EventType} from '../@types/event'; import { RoomMember } from '../models/room-member'; import { randomString } from '../randomstring'; +import { MCallReplacesEvent, MCallAnswer, MCallOfferNegotiate, CallCapabilities } from './callEventTypes'; // events: hangup, error(err), replaced(call), state(state, oldState) @@ -61,26 +62,6 @@ interface TurnServer { ttl?: number, } -interface CallCapabilities { - 'm.call.transferee': boolean, -} - -// allow camelcase as these are events type that go onto the wire -/* eslint-disable camelcase */ -interface MCallReplacesTarget { - id: string; - display_name: string, - avatar_url: string, -} - -interface MCallReplacesEvent { - replacement_id: string; - target_user: MCallReplacesTarget; - create_call: string; - target_room: string; -} -/* eslint-enable camelcase */ - export enum CallState { Fledgling = 'fledgling', InviteSent = 'invite_sent', @@ -810,7 +791,7 @@ export class MatrixCall extends EventEmitter { // required to still be sent for backwards compat type: this.peerConn.localDescription.type, }, - } as any; + } as MCallAnswer; if (this.client._supportsTransfer) { answerContent.capabilities = { @@ -1135,13 +1116,18 @@ export class MatrixCall extends EventEmitter { if (this.callHasEnded()) return; - const keyName = this.state === CallState.CreateOffer ? 'offer' : 'description'; const eventType = this.state === CallState.CreateOffer ? EventType.CallInvite : EventType.CallNegotiate; const content = { - [keyName]: this.peerConn.localDescription, lifetime: CALL_TIMEOUT_MS, - } as any; + } as MCallOfferNegotiate; + + // clunky because TypeScript can't folow the types through if we use an expression as the key + if (this.state === CallState.CreateOffer) { + content.offer = this.peerConn.localDescription; + } else { + content.description = this.peerConn.localDescription; + } if (this.client._supportsTransfer) { content.capabilities = { diff --git a/src/webrtc/callEventTypes.ts b/src/webrtc/callEventTypes.ts new file mode 100644 index 000000000..11d1cdd76 --- /dev/null +++ b/src/webrtc/callEventTypes.ts @@ -0,0 +1,37 @@ +// allow camelcase as these are events type that go onto the wire +/* eslint-disable camelcase */ + +interface CallOfferAnswer { + type: string; + sdp: string; +} + +export interface CallCapabilities { + 'm.call.transferee': boolean; +} + +export interface MCallAnswer { + answer: CallOfferAnswer; + capabilities: CallCapabilities; +} + +export interface MCallOfferNegotiate { + offer: CallOfferAnswer; + description: CallOfferAnswer; + lifetime: number; + capabilities: CallCapabilities; +} + +export interface MCallReplacesTarget { + id: string; + display_name: string; + avatar_url: string; +} + +export interface MCallReplacesEvent { + replacement_id: string; + target_user: MCallReplacesTarget; + create_call: string; + target_room: string; +} +/* eslint-enable camelcase */