Calls: Only send relay ICE candidates if p2p is disabled (#3564)
This commit is contained in:
parent
42fe08cb6e
commit
afd894a3a5
@ -140,7 +140,7 @@ export function buildPhoneCall(call: GramJs.TypePhoneCall): ApiPhoneCall {
|
|||||||
gAOrB: Array.from(gAOrB),
|
gAOrB: Array.from(gAOrB),
|
||||||
keyFingerprint: keyFingerprint.toString(),
|
keyFingerprint: keyFingerprint.toString(),
|
||||||
startDate,
|
startDate,
|
||||||
p2pAllowed,
|
isP2pAllowed: Boolean(p2pAllowed),
|
||||||
connections: connections.map(buildApiCallConnection).filter(Boolean) as ApiPhoneCallConnection[],
|
connections: connections.map(buildApiCallConnection).filter(Boolean) as ApiPhoneCallConnection[],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ export interface ApiPhoneCall {
|
|||||||
adminId?: string;
|
adminId?: string;
|
||||||
participantId?: string;
|
participantId?: string;
|
||||||
isVideo?: boolean;
|
isVideo?: boolean;
|
||||||
|
isP2pAllowed?: boolean;
|
||||||
date?: number;
|
date?: number;
|
||||||
startDate?: number;
|
startDate?: number;
|
||||||
receiveDate?: number;
|
receiveDate?: number;
|
||||||
|
|||||||
@ -169,7 +169,12 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
|||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
void joinPhoneCall(
|
void joinPhoneCall(
|
||||||
connections, actions.sendSignalingData, isOutgoing, Boolean(call?.isVideo), actions.apiUpdate,
|
connections,
|
||||||
|
actions.sendSignalingData,
|
||||||
|
isOutgoing,
|
||||||
|
Boolean(call?.isVideo),
|
||||||
|
Boolean(call.isP2pAllowed),
|
||||||
|
actions.apiUpdate,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import type { MediaContent, MediaStateMessage, P2pMessage } from './p2pMessage';
|
|||||||
import {
|
import {
|
||||||
fromTelegramSource,
|
fromTelegramSource,
|
||||||
IS_ECHO_CANCELLATION_SUPPORTED,
|
IS_ECHO_CANCELLATION_SUPPORTED,
|
||||||
IS_NOISE_SUPPRESSION_SUPPORTED,
|
IS_NOISE_SUPPRESSION_SUPPORTED, isRelayAddress,
|
||||||
p2pPayloadTypeToConference,
|
p2pPayloadTypeToConference, removeRelatedAddress,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import buildSdp, { Conference } from './buildSdp';
|
import buildSdp, { Conference } from './buildSdp';
|
||||||
import { getUserStreams, StreamType } from './secretsauce';
|
import { getUserStreams, StreamType } from './secretsauce';
|
||||||
@ -174,6 +174,7 @@ export async function joinPhoneCall(
|
|||||||
emitSignalingData: (data: P2pMessage) => void,
|
emitSignalingData: (data: P2pMessage) => void,
|
||||||
isOutgoing: boolean,
|
isOutgoing: boolean,
|
||||||
shouldStartVideo: boolean,
|
shouldStartVideo: boolean,
|
||||||
|
isP2p: boolean,
|
||||||
onUpdate: (...args: any[]) => void,
|
onUpdate: (...args: any[]) => void,
|
||||||
) {
|
) {
|
||||||
const conn = new RTCPeerConnection({
|
const conn = new RTCPeerConnection({
|
||||||
@ -200,10 +201,17 @@ export async function joinPhoneCall(
|
|||||||
conn.onicecandidate = (e) => {
|
conn.onicecandidate = (e) => {
|
||||||
if (!e.candidate) return;
|
if (!e.candidate) return;
|
||||||
|
|
||||||
|
const { candidate } = e.candidate;
|
||||||
|
if(!isP2p && !isRelayAddress(candidate)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidateWithoutRelatedAddress = !isP2p ? removeRelatedAddress(candidate) : candidate;
|
||||||
|
|
||||||
emitSignalingData({
|
emitSignalingData({
|
||||||
'@type': 'Candidates',
|
'@type': 'Candidates',
|
||||||
candidates: [{
|
candidates: [{
|
||||||
sdpString: e.candidate.candidate,
|
sdpString: candidateWithoutRelatedAddress,
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -39,6 +39,27 @@ export function p2pPayloadTypeToConference(p: P2PPayloadType): PayloadType {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isRelayAddress(candidate: string) {
|
||||||
|
const parts = candidate.split(' ');
|
||||||
|
return parts.some((part) => part === 'relay');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeRelatedAddress(candidate: string) {
|
||||||
|
const parts = candidate.split(' ');
|
||||||
|
|
||||||
|
const raddrIndex = parts.indexOf('raddr');
|
||||||
|
if (raddrIndex !== -1) {
|
||||||
|
parts.splice(raddrIndex, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
const rportIndex = parts.indexOf('rport');
|
||||||
|
if (rportIndex !== -1) {
|
||||||
|
parts.splice(rportIndex, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parts.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
export const THRESHOLD = 0.1;
|
export const THRESHOLD = 0.1;
|
||||||
|
|
||||||
export const IS_SCREENSHARE_SUPPORTED = 'getDisplayMedia' in (navigator?.mediaDevices || {});
|
export const IS_SCREENSHARE_SUPPORTED = 'getDisplayMedia' in (navigator?.mediaDevices || {});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user