diff --git a/ts/session/constants.ts b/ts/session/constants.ts index 0ed905b8f..b5ef23e87 100644 --- a/ts/session/constants.ts +++ b/ts/session/constants.ts @@ -14,6 +14,7 @@ export const DURATION = { export const TTL_DEFAULT = { TYPING_MESSAGE: 20 * DURATION.SECONDS, + CALL_MESSAGE: 5 * 60 * DURATION.SECONDS, TTL_MAX: 14 * DURATION.DAYS, }; diff --git a/ts/session/messages/outgoing/controlMessage/CallMessage.ts b/ts/session/messages/outgoing/controlMessage/CallMessage.ts new file mode 100644 index 000000000..59e3a5b79 --- /dev/null +++ b/ts/session/messages/outgoing/controlMessage/CallMessage.ts @@ -0,0 +1,50 @@ +import { SignalService } from '../../../../protobuf'; +import { MessageParams } from '../Message'; +import { ContentMessage } from '..'; +import { signalservice } from '../../../../protobuf/compiled'; +import { TTL_DEFAULT } from '../../../constants'; +interface CallMessageMessageParams extends MessageParams { + type: SignalService.CallMessage.Type; + sdpMLineIndexes: Array; + sdpMids: Array; + sdps: Array; + referencedAttachmentTimestamp: number; +} + +export class CallMessageMessage extends ContentMessage { + public readonly type: signalservice.CallMessage.Type; + public readonly sdpMLineIndexes: Array; + public readonly sdpMids: Array; + public readonly sdps: Array; + + constructor(params: CallMessageMessageParams) { + super({ timestamp: params.timestamp, identifier: params.identifier }); + this.type = params.type; + this.sdpMLineIndexes = params.sdpMLineIndexes; + this.sdpMids = params.sdpMids; + this.sdps = params.sdps; + // this does not make any sense + if (this.type !== signalservice.CallMessage.Type.END_CALL && this.sdps.length === 0) { + throw new Error('sdps must be set unless this is a END_CALL type message'); + } + } + + public contentProto(): SignalService.Content { + return new SignalService.Content({ + callMessage: this.dataCallProto(), + }); + } + + public ttl() { + return TTL_DEFAULT.CALL_MESSAGE; + } + + private dataCallProto(): SignalService.CallMessage { + return new SignalService.CallMessage({ + type: this.type, + sdpMLineIndexes: this.sdpMLineIndexes, + sdpMids: this.sdpMids, + sdps: this.sdps, + }); + } +}