Add candidates negotiation

This commit is contained in:
Tiago Jacobs
2022-03-29 14:57:03 -03:00
parent 184fb8a190
commit 7036a276ed
12 changed files with 130 additions and 8 deletions

View File

@@ -0,0 +1,34 @@
import { addScreenShareRemoteIceCandidate as nativeAddScreenShareRemoteIceCandidate } from '../native-components/BBBN_ScreenShareService';
import nativeEmitter from '../native-messaging/emitter';
// Reference to the resolver of last call
let resolve = (value: unknown) => {
console.log(
`default resolve function called, this should never happen: ${value}`
);
};
// Resolve promise when SDP offer is available
nativeEmitter.addListener('onAddScreenShareRemoteIceCandidateCompleted', () => {
resolve(undefined);
});
// Entry point of this method
function addScreenShareRemoteIceCandidate(remoteCandidateJson: string) {
return new Promise((res, rej) => {
// store the resolver for later call (when event is received)
resolve = res;
try {
console.log(
`>nativeAddScreenShareRemoteIceCandidate ${remoteCandidateJson}`
);
// call native swift method that triggers the broadcast popup
nativeAddScreenShareRemoteIceCandidate(remoteCandidateJson);
} catch (e) {
rej(`Call to nativeAddScreenShareRemoteIceCandidate failed`);
}
});
}
export default addScreenShareRemoteIceCandidate;

View File

@@ -13,3 +13,7 @@ export function createScreenShareOffer() {
export function setScreenShareRemoteSDP(remoteSDP: string) {
ScreenShareService.setScreenShareRemoteSDP(remoteSDP);
}
export function addScreenShareRemoteIceCandidate(remoteCandidateJson: string) {
ScreenShareService.addScreenShareRemoteIceCandidate(remoteCandidateJson);
}

View File

@@ -3,6 +3,7 @@ import type { WebView, WebViewMessageEvent } from 'react-native-webview';
import initializeScreenShare from '../methods/initializeScreenShare';
import createScreenShareOffer from '../methods/createScreenShareOffer';
import setScreenShareRemoteSDP from '../methods/setScreenShareRemoteSDP';
import addScreenShareRemoteIceCandidate from '../methods/addScreenShareRemoteIceCandidate';
function observePromiseResult(
webViewRef: MutableRefObject<WebView>,
@@ -47,6 +48,11 @@ export function handleWebviewMessage(
case 'setRemoteDescription':
promise = setScreenShareRemoteSDP(data?.arguments[0].sdp);
break;
case 'addRemoteIceCandidate':
promise = addScreenShareRemoteIceCandidate(
JSON.stringify(data?.arguments[0])
);
break;
default:
throw `Unknown method ${data?.method}`;
}