You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.1 KiB
TypeScript
75 lines
2.1 KiB
TypeScript
import _ from 'lodash';
|
|
import { SignalService } from '../protobuf';
|
|
import { TTL_DEFAULT } from '../session/constants';
|
|
import { SNodeAPI } from '../session/snode_api';
|
|
import { CallManager, UserUtils } from '../session/utils';
|
|
import { removeFromCache } from './cache';
|
|
import { EnvelopePlus } from './types';
|
|
|
|
export async function handleCallMessage(
|
|
envelope: EnvelopePlus,
|
|
callMessage: SignalService.CallMessage
|
|
) {
|
|
const sender = envelope.senderIdentity || envelope.source;
|
|
|
|
const currentOffset = SNodeAPI.getLatestTimestampOffset();
|
|
const sentTimestamp = _.toNumber(envelope.timestamp);
|
|
|
|
const { type } = callMessage;
|
|
|
|
if (type === SignalService.CallMessage.Type.PROVISIONAL_ANSWER) {
|
|
await removeFromCache(envelope);
|
|
|
|
window.log.info('Skipping callMessage PROVISIONAL_ANSWER');
|
|
return;
|
|
}
|
|
|
|
if (type === SignalService.CallMessage.Type.PRE_OFFER) {
|
|
await removeFromCache(envelope);
|
|
|
|
window.log.info('Skipping callMessage PRE_OFFER');
|
|
return;
|
|
}
|
|
|
|
if (type === SignalService.CallMessage.Type.OFFER) {
|
|
if (Math.max(sentTimestamp - (Date.now() - currentOffset)) > TTL_DEFAULT.CALL_MESSAGE) {
|
|
window?.log?.info('Dropping incoming OFFER callMessage sent a while ago: ', sentTimestamp);
|
|
await removeFromCache(envelope);
|
|
|
|
return;
|
|
}
|
|
await removeFromCache(envelope);
|
|
|
|
await CallManager.handleCallTypeOffer(sender, callMessage, sentTimestamp);
|
|
|
|
return;
|
|
}
|
|
|
|
if (type === SignalService.CallMessage.Type.END_CALL) {
|
|
await removeFromCache(envelope);
|
|
|
|
CallManager.handleCallTypeEndCall(sender, callMessage.uuid);
|
|
|
|
return;
|
|
}
|
|
|
|
if (type === SignalService.CallMessage.Type.ANSWER) {
|
|
await removeFromCache(envelope);
|
|
|
|
await CallManager.handleCallTypeAnswer(sender, callMessage);
|
|
|
|
return;
|
|
}
|
|
if (type === SignalService.CallMessage.Type.ICE_CANDIDATES) {
|
|
await removeFromCache(envelope);
|
|
|
|
await CallManager.handleCallTypeIceCandidates(sender, callMessage);
|
|
|
|
return;
|
|
}
|
|
await removeFromCache(envelope);
|
|
|
|
// if this another type of call message, just add it to the manager
|
|
await CallManager.handleOtherCallTypes(sender, callMessage);
|
|
}
|