Proper call requests for callee
This commit is contained in:
parent
e9957ac12f
commit
333dc17c0a
6 changed files with 54 additions and 93 deletions
|
@ -4,12 +4,16 @@ import {
|
|||
Call,
|
||||
CallEndedReason,
|
||||
CallId,
|
||||
CallingMessage,
|
||||
CallLogLevel,
|
||||
CallSettings,
|
||||
CallState,
|
||||
CanvasVideoRenderer,
|
||||
DeviceId,
|
||||
GumVideoCapturer,
|
||||
HangupMessage,
|
||||
HangupType,
|
||||
OfferType,
|
||||
RingRTC,
|
||||
UserId,
|
||||
} from 'ringrtc';
|
||||
|
@ -21,7 +25,7 @@ import {
|
|||
ActionsType as UxActionsType,
|
||||
CallDetailsType,
|
||||
} from '../state/ducks/calling';
|
||||
import { CallingMessageClass, EnvelopeClass } from '../textsecure.d';
|
||||
import { EnvelopeClass } from '../textsecure.d';
|
||||
import {
|
||||
AudioDevice,
|
||||
CallHistoryDetailsType,
|
||||
|
@ -398,7 +402,7 @@ export class CallingClass {
|
|||
|
||||
async handleCallingMessage(
|
||||
envelope: EnvelopeClass,
|
||||
callingMessage: CallingMessageClass
|
||||
callingMessage: CallingMessage
|
||||
): Promise<void> {
|
||||
window.log.info('CallingClass.handleCallingMessage()');
|
||||
|
||||
|
@ -439,6 +443,35 @@ export class CallingClass {
|
|||
}
|
||||
const receiverIdentityKey = receiverIdentityRecord.publicKey.slice(1); // Ignore the type header, it is not used.
|
||||
|
||||
const conversation = window.ConversationController.get(remoteUserId);
|
||||
if (!conversation) {
|
||||
window.log.error('Missing conversation; ignoring call message.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (callingMessage.offer && !conversation.getAccepted()) {
|
||||
window.log.info(
|
||||
'Conversation was not approved by user; rejecting call message.'
|
||||
);
|
||||
|
||||
const hangup = new HangupMessage();
|
||||
hangup.callId = callingMessage.offer.callId;
|
||||
hangup.deviceId = remoteDeviceId;
|
||||
hangup.type = HangupType.NeedPermission;
|
||||
|
||||
const message = new CallingMessage();
|
||||
message.legacyHangup = hangup;
|
||||
|
||||
await this.handleOutgoingSignaling(remoteUserId, message);
|
||||
|
||||
this.addCallHistoryForFailedIncomingCall(
|
||||
conversation,
|
||||
callingMessage.offer.type === OfferType.VideoCall
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const messageAgeSec = envelope.messageAgeSec ? envelope.messageAgeSec : 0;
|
||||
|
||||
window.log.info('CallingClass.handleCallingMessage(): Handling in RingRTC');
|
||||
|
@ -525,7 +558,7 @@ export class CallingClass {
|
|||
|
||||
private async handleOutgoingSignaling(
|
||||
remoteUserId: UserId,
|
||||
message: CallingMessageClass
|
||||
message: CallingMessage
|
||||
): Promise<boolean> {
|
||||
const conversation = window.ConversationController.get(remoteUserId);
|
||||
const sendOptions = conversation
|
||||
|
@ -585,17 +618,10 @@ export class CallingClass {
|
|||
window.log.info(
|
||||
`Peer is not trusted, ignoring incoming call for conversation: ${conversation.idForLogging()}`
|
||||
);
|
||||
this.addCallHistoryForFailedIncomingCall(conversation, call);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Simple Call Requests: Ensure that the conversation is accepted.
|
||||
// If not, do not allow the call.
|
||||
if (!conversation.getAccepted()) {
|
||||
window.log.info(
|
||||
`Messaging is not accepted, ignoring incoming call for conversation: ${conversation.idForLogging()}`
|
||||
this.addCallHistoryForFailedIncomingCall(
|
||||
conversation,
|
||||
call.isVideoCall
|
||||
);
|
||||
this.addCallHistoryForFailedIncomingCall(conversation, call);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -610,7 +636,7 @@ export class CallingClass {
|
|||
return await this.getCallSettings(conversation);
|
||||
} catch (err) {
|
||||
window.log.error(`Ignoring incoming call: ${err.stack}`);
|
||||
this.addCallHistoryForFailedIncomingCall(conversation, call);
|
||||
this.addCallHistoryForFailedIncomingCall(conversation, call.isVideoCall);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -774,11 +800,11 @@ export class CallingClass {
|
|||
|
||||
private addCallHistoryForFailedIncomingCall(
|
||||
conversation: ConversationModel,
|
||||
call: Call
|
||||
wasVideoCall: boolean
|
||||
) {
|
||||
const callHistoryDetails: CallHistoryDetailsType = {
|
||||
wasIncoming: true,
|
||||
wasVideoCall: call.isVideoCall,
|
||||
wasVideoCall,
|
||||
// Since the user didn't decline, make sure it shows up as a missed call instead
|
||||
wasDeclined: false,
|
||||
acceptedTime: undefined,
|
||||
|
|
64
ts/textsecure.d.ts
vendored
64
ts/textsecure.d.ts
vendored
|
@ -12,6 +12,7 @@ import { ByteBufferClass } from './window.d';
|
|||
import SendMessage, { SendOptionsType } from './textsecure/SendMessage';
|
||||
import { WebAPIType } from './textsecure/WebAPI';
|
||||
import utils from './textsecure/Helpers';
|
||||
import { CallingMessage as CallingMessageClass } from 'ringrtc';
|
||||
|
||||
type AttachmentType = any;
|
||||
|
||||
|
@ -1214,65 +1215,4 @@ export declare class WebSocketResponseMessageClass {
|
|||
body?: ProtoBinaryType;
|
||||
}
|
||||
|
||||
// Everything from here down to HangupType (everything related to calling)
|
||||
// must be kept in sync with RingRTC (ringrtc-node).
|
||||
// Whenever you change this, make sure you change RingRTC as well.
|
||||
|
||||
type ProtobufArrayBuffer = ArrayBuffer | { toArrayBuffer: () => ArrayBuffer };
|
||||
|
||||
export type DeviceId = number;
|
||||
|
||||
export type CallId = any;
|
||||
|
||||
export class CallingMessageClass {
|
||||
offer?: OfferMessageClass;
|
||||
answer?: AnswerMessageClass;
|
||||
iceCandidates?: Array<IceCandidateMessageClass>;
|
||||
legacyHangup?: HangupMessageClass;
|
||||
busy?: BusyMessageClass;
|
||||
hangup?: HangupMessageClass;
|
||||
supportsMultiRing?: boolean;
|
||||
destinationDeviceId?: DeviceId;
|
||||
}
|
||||
|
||||
export class OfferMessageClass {
|
||||
callId?: CallId;
|
||||
type?: OfferType;
|
||||
sdp?: string;
|
||||
}
|
||||
|
||||
export enum OfferType {
|
||||
AudioCall = 0,
|
||||
VideoCall = 1,
|
||||
}
|
||||
|
||||
export class AnswerMessageClass {
|
||||
callId?: CallId;
|
||||
sdp?: string;
|
||||
}
|
||||
|
||||
export class IceCandidateMessageClass {
|
||||
callId?: CallId;
|
||||
mid?: string;
|
||||
line?: number;
|
||||
opaque?: ProtobufArrayBuffer;
|
||||
sdp?: string;
|
||||
}
|
||||
|
||||
export class BusyMessageClass {
|
||||
callId?: CallId;
|
||||
}
|
||||
|
||||
export class HangupMessageClass {
|
||||
callId?: CallId;
|
||||
type?: HangupType;
|
||||
deviceId?: DeviceId;
|
||||
}
|
||||
|
||||
export enum HangupType {
|
||||
Normal = 0,
|
||||
Accepted = 1,
|
||||
Declined = 2,
|
||||
Busy = 3,
|
||||
NeedPermission = 4,
|
||||
}
|
||||
export { CallingMessageClass };
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { CallState } from 'ringrtc';
|
||||
|
||||
// Must be kept in sync with RingRTC.AudioDevice
|
||||
export interface AudioDevice {
|
||||
// Device name.
|
||||
|
@ -10,15 +12,6 @@ export interface AudioDevice {
|
|||
i18nKey?: string;
|
||||
}
|
||||
|
||||
// This must be kept in sync with RingRTC.CallState.
|
||||
export enum CallState {
|
||||
Prering = 'init',
|
||||
Ringing = 'ringing',
|
||||
Accepted = 'connected',
|
||||
Reconnecting = 'connecting',
|
||||
Ended = 'ended',
|
||||
}
|
||||
|
||||
export enum CallingDeviceType {
|
||||
CAMERA,
|
||||
MICROPHONE,
|
||||
|
@ -46,3 +39,5 @@ export type ChangeIODevicePayloadType =
|
|||
| { type: CallingDeviceType.CAMERA; selectedDevice: string }
|
||||
| { type: CallingDeviceType.MICROPHONE; selectedDevice: AudioDevice }
|
||||
| { type: CallingDeviceType.SPEAKER; selectedDevice: AudioDevice };
|
||||
|
||||
export { CallState };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue