sdk/ui: rtc signaling types

This commit is contained in:
Koushik Dutta
2022-01-24 19:51:27 -08:00
parent e098373d1c
commit a37ec60d60
4 changed files with 41 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import { ScryptedDevice, ScryptedMimeTypes, RTCAVMessage, MediaManager, VideoCamera, MediaStreamOptions, MediaObject } from '@scrypted/sdk/types';
import { ScryptedDevice, ScryptedMimeTypes, RTCAVMessage, MediaManager, VideoCamera, MediaStreamOptions, MediaObject, RTCAVSource } from '@scrypted/sdk/types';
export async function streamCamera(mediaManager: MediaManager, device: ScryptedDevice & VideoCamera, getVideo: () => HTMLVideoElement, createPeerConnection: (configuration: RTCConfiguration) => RTCPeerConnection) {
let selectedStream: MediaStreamOptions;
@@ -19,20 +19,22 @@ export async function streamCamera(mediaManager: MediaManager, device: ScryptedD
if (videoStream.mimeType.startsWith(ScryptedMimeTypes.RTCAVSignalingPrefix)) {
trickle = false;
const mic = await navigator.mediaDevices.getUserMedia({video: false, audio: true})
const buffer = await mediaManager.convertMediaObjectToBuffer(
videoStream,
videoStream.mimeType,
);
const avsource: RTCAVSource = JSON.parse(buffer.toString());
pc = createPeerConnection({})
for (const track of mic.getTracks()) {
pc.addTrack(track);
}
// pc.createDataChannel("dataSendChannel");
// const audioTrans = pc.addTransceiver("audio", {
// direction: 'sendrecv',
// });
// pc.addTransceiver("video", {
// direction: 'recvonly',
// });
// it's possible to do talkback to ring.
// const mic = await navigator.mediaDevices.getUserMedia({video: false, audio: true})
// for (const track of mic.getTracks()) {
// pc.addTrack(track);
// }
if (avsource.datachannel)
pc.createDataChannel(avsource.datachannel.label, avsource.datachannel.dict);
pc.addTransceiver("audio", avsource.audio);
pc.addTransceiver("video", avsource.video);
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);

View File

@@ -1228,6 +1228,15 @@ export enum ScryptedInterface {
}
export interface RTCAVSource {
audio: RTCRtpTransceiverInit;
video: RTCRtpTransceiverInit;
datachannel?: {
label: string;
dict?: RTCDataChannelInit;
}
}
export interface RTCAVMessage {
id: string;
description: RTCSessionDescriptionInit;

8
sdk/types.d.ts vendored
View File

@@ -1272,6 +1272,14 @@ export declare enum ScryptedInterface {
HumiditySetting = "HumiditySetting",
Fan = "Fan"
}
export interface RTCAVSource {
audio: RTCRtpTransceiverInit;
video: RTCRtpTransceiverInit;
datachannel?: {
label: string;
dict?: RTCDataChannelInit;
};
}
export interface RTCAVMessage {
id: string;
description: RTCSessionDescriptionInit;

View File

@@ -1860,6 +1860,15 @@ export enum ScryptedInterface {
}
export interface RTCAVSource {
audio: RTCRtpTransceiverInit;
video: RTCRtpTransceiverInit;
datachannel?: {
label: string;
dict?: RTCDataChannelInit;
}
}
export interface RTCAVMessage {
id: string;
description: RTCSessionDescriptionInit;