Skip to content

Commit

Permalink
[MM-45894] Calls: support for signaling media tracks using data chann…
Browse files Browse the repository at this point in the history
…els (#8246)

* Replace pako with fflate

* Allow signaling through data channel

* Update calls-common
  • Loading branch information
streamer45 authored Oct 9, 2024
1 parent 603ea79 commit e693431
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 27 deletions.
29 changes: 13 additions & 16 deletions app/products/calls/connection/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// See LICENSE.txt for license information.

import {RTCMonitor, RTCPeer, parseRTCStats} from '@mattermost/calls/lib';
import {deflate} from 'pako';
import {zlibSync, strToU8} from 'fflate';
import {DeviceEventEmitter, type EmitterSubscription, NativeEventEmitter, NativeModules, Platform} from 'react-native';
import InCallManager from 'react-native-incall-manager';
import {mediaDevices, MediaStream, MediaStreamTrack, registerGlobals} from 'react-native-webrtc';
import {mediaDevices, MediaStream, MediaStreamTrack, registerGlobals, RTCSessionDescription} from 'react-native-webrtc';

import {setPreferredAudioRoute, setSpeakerphoneOn} from '@calls/actions/calls';
import {
Expand Down Expand Up @@ -311,6 +311,7 @@ export async function newConnection(
title,
threadID: rootId,
av1Support,
dcSignaling: config.EnableDCSignaling,
});
}
});
Expand Down Expand Up @@ -385,6 +386,7 @@ export async function newConnection(
peer = new RTCPeer({
iceServers: iceConfigs || [],
logger,
dcSignaling: config.EnableDCSignaling,
});

collectICEStats();
Expand All @@ -396,22 +398,20 @@ export async function newConnection(
});
rtcMonitor.on('mos', processMeanOpinionScore);

peer.on('offer', (sdp) => {
logDebug(`calls: local offer, sending: ${JSON.stringify(sdp)}`);
ws.send('sdp', {
data: deflate(JSON.stringify(sdp)),
}, true);
});
const sdpHandler = (sdp: RTCSessionDescription) => {
const payload = JSON.stringify(sdp);

peer.on('answer', (sdp) => {
logDebug(`calls: local answer, sending: ${JSON.stringify(sdp)}`);
// SDP data is compressed using zlib since it's text based
// and can grow substantially, potentially hitting the maximum
// message size (8KB).
ws.send('sdp', {
data: deflate(JSON.stringify(sdp)),
data: zlibSync(strToU8(payload)),
}, true);
});
};
peer.on('offer', sdpHandler);
peer.on('answer', sdpHandler);

peer.on('candidate', (candidate) => {
logDebug(`calls: local candidate: ${JSON.stringify(candidate)}`);
ws.send('ice', {
data: JSON.stringify(candidate),
});
Expand Down Expand Up @@ -449,9 +449,6 @@ export async function newConnection(
if (!msg) {
return;
}
if (msg.type !== 'ping') {
logDebug('calls: remote signal', data);
}
if (msg.type === 'answer' || msg.type === 'candidate' || msg.type === 'offer') {
peer?.signal(data);
}
Expand Down
1 change: 1 addition & 0 deletions app/products/calls/types/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export const DefaultCallsConfig: CallsConfigState = {
EnableAV1: false,
TranscribeAPI: TranscribeAPI.WhisperCPP,
GroupCallsAllowed: true, // Set to true to keep backward compatibility with older servers.
EnableDCSignaling: false,
};

export type ApiResp = {
Expand Down
30 changes: 21 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@formatjs/intl-numberformat": "8.10.3",
"@formatjs/intl-pluralrules": "5.2.14",
"@gorhom/bottom-sheet": "4.6.4",
"@mattermost/calls": "github:mattermost/calls-common#1ce6defb1ee0c1e0f106ddff8f46c37d10d60b76",
"@mattermost/calls": "github:mattermost/calls-common#8d2b13bd2f10847a4be461dd4225fef2ade06ab9",
"@mattermost/compass-icons": "0.1.45",
"@mattermost/hardware-keyboard": "file:./libraries/@mattermost/hardware-keyboard",
"@mattermost/keyboard-tracker": "file:./libraries/@mattermost/keyboard-tracker",
Expand Down Expand Up @@ -57,12 +57,12 @@
"expo-store-review": "7.0.2",
"expo-video-thumbnails": "8.0.0",
"expo-web-browser": "13.0.3",
"fflate": "0.8.2",
"fuse.js": "7.0.0",
"html-entities": "2.5.2",
"mime-db": "1.53.0",
"moment-timezone": "0.5.45",
"node-html-parser": "6.1.13",
"pako": "2.1.0",
"path-to-regexp": "8.1.0",
"react": "18.2.0",
"react-freeze": "1.0.4",
Expand Down

0 comments on commit e693431

Please sign in to comment.