mirror of
https://github.com/koush/scrypted.git
synced 2026-05-31 00:30:30 +01:00
webrtc: fix unhandled rejection
This commit is contained in:
@@ -9,7 +9,7 @@ import sdk, { FFmpegInput, Intercom, MediaObject, MediaStreamUrl, ResponseMediaS
|
||||
import { logConnectionState, waitClosed, waitConnected, waitIceConnected } from "./peerconnection-util";
|
||||
import { startRtpForwarderProcess } from "./rtp-forwarders";
|
||||
import { getFFmpegRtpAudioOutputArguments, requiredAudioCodecs, requiredVideoCodec } from "./webrtc-required-codecs";
|
||||
import { createRawResponse, getWeriftIceServers, isPeerConnectionAlive } from "./werift-util";
|
||||
import { createRawResponse, getWeriftIceServers, isPeerConnectionAlive, logIsLocalIceTransport } from "./werift-util";
|
||||
import { H264Repacketizer } from "../../homekit/src/types/camera/h264-packetizer";
|
||||
|
||||
const { mediaManager } = sdk;
|
||||
@@ -20,6 +20,14 @@ export interface RTCPeerConnectionPipe {
|
||||
pcClose: Promise<unknown>;
|
||||
}
|
||||
|
||||
function ignoreDeferred(...d: Deferred<any>[]) {
|
||||
d.forEach(d => d.promise.catch(() => { }));
|
||||
}
|
||||
|
||||
function ignorePromise(...p: Promise<any>[]) {
|
||||
p.forEach(p => p.catch(() => { }));
|
||||
}
|
||||
|
||||
export async function createRTCPeerConnectionSource(options: {
|
||||
console: Console,
|
||||
mediaStreamOptions: ResponseMediaStreamOptions,
|
||||
@@ -35,13 +43,14 @@ export async function createRTCPeerConnectionSource(options: {
|
||||
const sessionControl = new Deferred<RTCSessionControl>();
|
||||
const peerConnection = new Deferred<RTCPeerConnection>();
|
||||
const intercom = new Deferred<Intercom>();
|
||||
ignoreDeferred(sessionControl, intercom);
|
||||
|
||||
const cleanup = () => {
|
||||
console.log('webrtc/rtsp cleaning up');
|
||||
clientPromise.then(client => client.destroy());
|
||||
sessionControl.promise.then(sc => sc.endSession());
|
||||
peerConnection.promise.then(pc => pc.close());
|
||||
intercom.promise.then(intercom => intercom.stopIntercom());
|
||||
clientPromise.then(client => client.destroy()).catch(() => {});
|
||||
sessionControl.promise.then(sc => sc.endSession()).catch(() => {});
|
||||
peerConnection.promise.then(pc => pc.close()).catch(() => {});
|
||||
ignorePromise(intercom.promise.then(intercom => intercom.stopIntercom()));
|
||||
};
|
||||
|
||||
clientPromise.then(socket => socket.on('close', cleanup));
|
||||
@@ -69,6 +78,18 @@ export async function createRTCPeerConnectionSource(options: {
|
||||
|
||||
logConnectionState(console, ret);
|
||||
peerConnection.resolve(ret);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
if (ret.remoteIsBundled)
|
||||
await waitConnected(ret);
|
||||
else
|
||||
await waitIceConnected(ret);
|
||||
logIsLocalIceTransport(console, ret);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
let audioTrack: string;
|
||||
@@ -82,12 +103,6 @@ export async function createRTCPeerConnectionSource(options: {
|
||||
let gotVideo = false;
|
||||
|
||||
const pc = await peerConnection.promise;
|
||||
pc.iceConnectionStateChange.subscribe(() => {
|
||||
console.log('iceConnectionState', pc.iceConnectionState);
|
||||
});
|
||||
pc.connectionStateChange.subscribe(() => {
|
||||
console.log('connectionState', pc.connectionState);
|
||||
});
|
||||
|
||||
const setupAudioTranscevier = (transciever: RTCRtpTransceiver) => {
|
||||
audioTransceiver = transciever;
|
||||
|
||||
Reference in New Issue
Block a user