|
1 | 1 | import { AutoenableMixinProvider } from '@scrypted/common/src/autoenable-mixin-provider';
|
2 | 2 | import { Deferred } from '@scrypted/common/src/deferred';
|
3 |
| -import { listenZeroSingleClient } from '@scrypted/common/src/listen-cluster'; |
4 | 3 | import { timeoutPromise } from '@scrypted/common/src/promise-utils';
|
5 |
| -import { createBrowserSignalingSession } from "@scrypted/common/src/rtc-connect"; |
6 | 4 | import { legacyGetSignalingSessionOptions } from '@scrypted/common/src/rtc-signaling';
|
7 | 5 | import { SettingsMixinDeviceBase, SettingsMixinDeviceOptions } from '@scrypted/common/src/settings-mixin';
|
8 | 6 | import { createZygote } from '@scrypted/common/src/zygote';
|
9 |
| -import sdk, { ConnectOptions, DeviceCreator, DeviceCreatorSettings, DeviceProvider, FFmpegInput, HttpRequest, Intercom, MediaConverter, MediaObject, MediaObjectOptions, MixinProvider, RTCSessionControl, RTCSignalingChannel, RTCSignalingClient, RTCSignalingOptions, RTCSignalingSession, RequestMediaStream, RequestMediaStreamOptions, ResponseMediaStreamOptions, ScryptedDeviceType, ScryptedInterface, ScryptedMimeTypes, ScryptedNativeId, Setting, SettingValue, Settings, VideoCamera, WritableDeviceState } from '@scrypted/sdk'; |
| 7 | +import sdk, { DeviceCreator, DeviceCreatorSettings, DeviceProvider, FFmpegInput, Intercom, MediaConverter, MediaObject, MediaObjectOptions, MixinProvider, RTCSessionControl, RTCSignalingChannel, RTCSignalingClient, RTCSignalingOptions, RTCSignalingSession, RequestMediaStream, RequestMediaStreamOptions, ResponseMediaStreamOptions, ScryptedDeviceType, ScryptedInterface, ScryptedMimeTypes, ScryptedNativeId, Setting, SettingValue, Settings, VideoCamera, WritableDeviceState } from '@scrypted/sdk'; |
10 | 8 | import { StorageSettings } from '@scrypted/sdk/storage-settings';
|
11 | 9 | import crypto from 'crypto';
|
12 | 10 | import ip from 'ip';
|
@@ -586,111 +584,6 @@ export class WebRTCPlugin extends AutoenableMixinProvider implements DeviceCreat
|
586 | 584 | ...ret,
|
587 | 585 | };
|
588 | 586 | }
|
589 |
| - |
590 |
| - async onConnection(request: HttpRequest, webSocketUrl: string) { |
591 |
| - const weriftConfiguration = await this.getWeriftConfiguration(); |
592 |
| - |
593 |
| - const cleanup = new Deferred<string>(); |
594 |
| - cleanup.promise.then(e => this.console.log('cleaning up rtc connection:', e)); |
595 |
| - |
596 |
| - try { |
597 |
| - const ws = new WebSocket(webSocketUrl); |
598 |
| - cleanup.promise.finally(() => ws.close()); |
599 |
| - |
600 |
| - if (request.isPublicEndpoint) { |
601 |
| - cleanup.resolve('public endpoint not supported'); |
602 |
| - return; |
603 |
| - } |
604 |
| - |
605 |
| - const client = await listenZeroSingleClient('127.0.0.1'); |
606 |
| - cleanup.promise.finally(() => { |
607 |
| - client.cancel(); |
608 |
| - client.clientPromise.then(cp => cp.destroy()).catch(() => { }); |
609 |
| - }); |
610 |
| - |
611 |
| - const message = await new Promise<{ |
612 |
| - connectionManagementId: string, |
613 |
| - updateSessionId: string, |
614 |
| - } & ConnectOptions>((resolve, reject) => { |
615 |
| - const close = () => { |
616 |
| - const str = 'Connection closed while waiting for message'; |
617 |
| - reject(new Error(str)); |
618 |
| - cleanup.resolve(str); |
619 |
| - }; |
620 |
| - ws.addEventListener('close', close); |
621 |
| - |
622 |
| - ws.onmessage = message => { |
623 |
| - ws.removeEventListener('close', close); |
624 |
| - resolve(JSON.parse(message.data)); |
625 |
| - } |
626 |
| - }); |
627 |
| - |
628 |
| - message.username = request.username; |
629 |
| - |
630 |
| - const { connectionManagementId, updateSessionId } = message; |
631 |
| - if (connectionManagementId) { |
632 |
| - cleanup.promise.finally(async () => { |
633 |
| - const plugins = await systemManager.getComponent('plugins'); |
634 |
| - plugins.setHostParam('@scrypted/webrtc', connectionManagementId); |
635 |
| - }); |
636 |
| - } |
637 |
| - if (updateSessionId) { |
638 |
| - cleanup.promise.finally(async () => { |
639 |
| - const plugins = await systemManager.getComponent('plugins'); |
640 |
| - plugins.setHostParam('@scrypted/webrtc', updateSessionId); |
641 |
| - }); |
642 |
| - } |
643 |
| - |
644 |
| - const session = await createBrowserSignalingSession(ws, '@scrypted/webrtc', 'remote'); |
645 |
| - const clientOptions = await legacyGetSignalingSessionOptions(session); |
646 |
| - |
647 |
| - const result = zygote(); |
648 |
| - this.activeConnections++; |
649 |
| - result.worker.on('exit', () => { |
650 |
| - this.activeConnections--; |
651 |
| - cleanup.resolve('worker exited (onConnection)'); |
652 |
| - }); |
653 |
| - |
654 |
| - let connection: WebRTCConnectionManagement; |
655 |
| - try { |
656 |
| - const { createConnection } = await result.result; |
657 |
| - connection = await createConnection(message, client.port, session, |
658 |
| - this.storageSettings.values.maximumCompatibilityMode, clientOptions, { |
659 |
| - configuration: this.getRTCConfiguration(), |
660 |
| - weriftConfiguration, |
661 |
| - ipv4Ban: this.storageSettings.values.ipv4Ban, |
662 |
| - }); |
663 |
| - } |
664 |
| - catch (e) { |
665 |
| - result.worker.terminate(); |
666 |
| - throw e; |
667 |
| - } |
668 |
| - handleCleanupConnection(cleanup, connection, result); |
669 |
| - |
670 |
| - timeoutPromise(60000, connection.waitConnected()) |
671 |
| - .catch(() => { |
672 |
| - cleanup.resolve('timeout'); |
673 |
| - }); |
674 |
| - |
675 |
| - await connection.negotiateRTCSignalingSession(); |
676 |
| - |
677 |
| - const cp = await client.clientPromise; |
678 |
| - cp.on('close', () => cleanup.resolve('socket client closed')); |
679 |
| - sdk.connect(cp, message); |
680 |
| - } |
681 |
| - catch (e) { |
682 |
| - console.error("error negotiating browser RTCC signaling", e); |
683 |
| - cleanup.resolve('error'); |
684 |
| - } |
685 |
| - } |
686 |
| -} |
687 |
| - |
688 |
| -function handleCleanupConnection(cleanup: Deferred<string>, connection: WebRTCConnectionManagement, result: ReturnType<typeof zygote>) { |
689 |
| - cleanup.promise.finally(() => { |
690 |
| - connection.close().catch(() => { }); |
691 |
| - setTimeout(() => result.worker.terminate(), 30000) |
692 |
| - }); |
693 |
| - connection.waitClosed().finally(() => cleanup.resolve('peer connection closed')); |
694 | 587 | }
|
695 | 588 |
|
696 | 589 | export async function fork() {
|
|
0 commit comments