mirror of
https://github.com/koush/scrypted.git
synced 2026-05-23 13:20:32 +01:00
webrtc: add connection timeout
This commit is contained in:
24
plugins/webrtc/package-lock.json
generated
24
plugins/webrtc/package-lock.json
generated
@@ -24,12 +24,11 @@
|
||||
"dependencies": {
|
||||
"@scrypted/sdk": "file:../sdk",
|
||||
"@scrypted/server": "file:../server",
|
||||
"http-auth-utils": "^3.0.2",
|
||||
"node-fetch-commonjs": "^3.1.1",
|
||||
"http-auth-utils": "^5.0.1",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.10.8",
|
||||
"@types/node": "^20.11.0",
|
||||
"ts-node": "^10.9.2"
|
||||
}
|
||||
},
|
||||
@@ -84,7 +83,7 @@
|
||||
},
|
||||
"../../sdk": {
|
||||
"name": "@scrypted/sdk",
|
||||
"version": "0.3.4",
|
||||
"version": "0.3.14",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/preset-typescript": "^7.18.6",
|
||||
@@ -143,9 +142,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/ip": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
|
||||
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
|
||||
"version": "1.1.9",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.9.tgz",
|
||||
"integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ=="
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -154,9 +153,8 @@
|
||||
"requires": {
|
||||
"@scrypted/sdk": "file:../sdk",
|
||||
"@scrypted/server": "file:../server",
|
||||
"@types/node": "^20.10.8",
|
||||
"http-auth-utils": "^3.0.2",
|
||||
"node-fetch-commonjs": "^3.1.1",
|
||||
"@types/node": "^20.11.0",
|
||||
"http-auth-utils": "^5.0.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
@@ -201,9 +199,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"ip": {
|
||||
"version": "1.1.5",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
|
||||
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
|
||||
"version": "1.1.9",
|
||||
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.9.tgz",
|
||||
"integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,24 +678,11 @@ class WebRTCBridge extends ScryptedDeviceBase implements BufferConverter {
|
||||
this.toMimeType = ScryptedMimeTypes.RTCConnectionManagement;
|
||||
}
|
||||
|
||||
async convert(data: any, fromMimeType: string, toMimeType: string, options?: MediaObjectOptions): Promise<any> {
|
||||
async convertInternal(result: ReturnType<typeof zygote>, cleanup: Deferred<string>, data: any, fromMimeType: string, toMimeType: string, options?: MediaObjectOptions): Promise<any> {
|
||||
const session = data as RTCSignalingSession;
|
||||
const maximumCompatibilityMode = !!this.plugin.storageSettings.values.maximumCompatibilityMode;
|
||||
const clientOptions = await legacyGetSignalingSessionOptions(session);
|
||||
|
||||
const result = zygote();
|
||||
|
||||
const cleanup = new Deferred<string>();
|
||||
|
||||
this.plugin.activeConnections++;
|
||||
result.worker.on('exit', () => {
|
||||
this.plugin.activeConnections--;
|
||||
cleanup.resolve('worker exited');
|
||||
});
|
||||
cleanup.promise.finally(() => {
|
||||
result.worker.terminate()
|
||||
});
|
||||
|
||||
const { createConnection } = await result.result;
|
||||
const connection = await createConnection({}, undefined, session,
|
||||
maximumCompatibilityMode,
|
||||
@@ -711,10 +698,29 @@ class WebRTCBridge extends ScryptedDeviceBase implements BufferConverter {
|
||||
await connection.negotiateRTCSignalingSession();
|
||||
await connection.waitConnected();
|
||||
|
||||
// await connection.negotiateRTCSignalingSession();
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
async convert(data: any, fromMimeType: string, toMimeType: string, options?: MediaObjectOptions): Promise<any> {
|
||||
const result = zygote();
|
||||
this.plugin.activeConnections++;
|
||||
const cleanup = new Deferred<string>();
|
||||
result.worker.on('exit', () => {
|
||||
this.plugin.activeConnections--;
|
||||
cleanup.resolve('worker exited');
|
||||
});
|
||||
cleanup.promise.finally(() => {
|
||||
result.worker.terminate()
|
||||
});
|
||||
|
||||
try {
|
||||
return await timeoutPromise(2 * 60 * 1000, this.convertInternal(result, cleanup, data, fromMimeType, toMimeType, options));
|
||||
}
|
||||
catch (e) {
|
||||
cleanup.resolve(e.toString());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default WebRTCPlugin;
|
||||
|
||||
@@ -55,9 +55,13 @@ export function waitIceConnected(pc: RTCPeerConnection) {
|
||||
}
|
||||
|
||||
export function waitClosed(pc: RTCPeerConnection) {
|
||||
return statePromise(pc.connectionStateChange, () => {
|
||||
return isPeerConnectionClosed(pc) || isPeerIceConnectionClosed(pc);
|
||||
})
|
||||
const connectPromise = statePromise(pc.connectionStateChange, () => {
|
||||
return isPeerConnectionClosed(pc);
|
||||
});
|
||||
const iceConnectPromise = statePromise(pc.iceConnectionStateChange, () => {
|
||||
return isPeerIceConnectionClosed(pc);
|
||||
});
|
||||
return Promise.any([connectPromise, iceConnectPromise]);
|
||||
}
|
||||
|
||||
export function logConnectionState(console: Console, pc: RTCPeerConnection) {
|
||||
|
||||
Reference in New Issue
Block a user