temp
This commit is contained in:
@@ -25,6 +25,7 @@ var TransformOperation;
|
||||
let activeCall;
|
||||
let answerTimeout = 30000;
|
||||
var useWorker = false;
|
||||
var isDesktop = false;
|
||||
var localizedState = "";
|
||||
var localizedDescription = "";
|
||||
const processCommand = (function () {
|
||||
@@ -392,6 +393,7 @@ const processCommand = (function () {
|
||||
const pc = call.connection;
|
||||
pc.ontrack = (event) => {
|
||||
try {
|
||||
console.log("LALAL ONTRACK");
|
||||
if (call.aesKey && call.key) {
|
||||
console.log("set up decryption for receiving");
|
||||
setupPeerTransform(TransformOperation.Decrypt, event.receiver, call.worker, call.aesKey, call.key);
|
||||
@@ -403,6 +405,9 @@ const processCommand = (function () {
|
||||
console.log("LALAL ADDED TRACK " + event.track.kind);
|
||||
};
|
||||
for (const track of stream.getTracks()) {
|
||||
track.onmute = (_event) => {
|
||||
console.log("LALAL ON MUTE");
|
||||
};
|
||||
call.remoteStream.addTrack(track);
|
||||
}
|
||||
}
|
||||
@@ -489,12 +494,27 @@ const processCommand = (function () {
|
||||
if (!call.cameraEnabled && !call.screenShareEnabled) {
|
||||
enableMedia(localStream, CallMediaType.Video, false);
|
||||
}
|
||||
replaceTracks(pc, audioTracks, false);
|
||||
replaceTracks(pc, videoTracks, call.screenShareEnabled);
|
||||
replaceTracks(pc, audioTracks, localStream, false);
|
||||
replaceTracks(pc, videoTracks, localStream, call.screenShareEnabled);
|
||||
call.localStream = localStream;
|
||||
videos.local.srcObject = localStream;
|
||||
// const offer = await pc.createOffer()
|
||||
// await pc.setLocalDescription(offer)
|
||||
// // const resp: WCallRenegotiateOffer = {
|
||||
// // type: "renegotiate-offer",
|
||||
// // offer: serialize(offer),
|
||||
// // }
|
||||
// const encryption = supportsInsertableStreams(useWorker)
|
||||
// const resp: WCallOffer = {
|
||||
// type: "offer",
|
||||
// offer: serialize(offer),
|
||||
// iceCandidates: await call.iceCandidates,
|
||||
// capabilities: {encryption},
|
||||
// }
|
||||
// const apiResp: WVApiMessage = {corrId: undefined, resp, command: undefined}
|
||||
// sendMessageToNative(apiResp)
|
||||
}
|
||||
function replaceTracks(pc, tracks, addIfNeeded) {
|
||||
function replaceTracks(pc, tracks, localStream, addIfNeeded) {
|
||||
var _a;
|
||||
if (!tracks.length)
|
||||
return;
|
||||
@@ -504,7 +524,7 @@ const processCommand = (function () {
|
||||
sender.replaceTrack(t);
|
||||
else if (addIfNeeded) {
|
||||
for (const track of tracks)
|
||||
pc.addTrack(track, activeCall.localStream);
|
||||
pc.addTrack(track, localStream);
|
||||
const call = activeCall;
|
||||
if (call.aesKey && call.key) {
|
||||
console.log("set up encryption for sending");
|
||||
@@ -537,9 +557,17 @@ const processCommand = (function () {
|
||||
console.log(`no ${operation}`);
|
||||
}
|
||||
}
|
||||
function getLocalMediaStream(mediaType, facingMode) {
|
||||
async function getLocalMediaStream(mediaType, facingMode) {
|
||||
const constraints = callMediaConstraints(mediaType, facingMode);
|
||||
return navigator.mediaDevices.getUserMedia(constraints);
|
||||
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||
if (isDesktop) {
|
||||
stream
|
||||
.getTracks()
|
||||
.filter((elem) => elem.kind == "video")
|
||||
.forEach((elem) => (elem.enabled = false));
|
||||
stream.getTracks().forEach((elem) => console.log("LALAL TRACK EN " + elem.enabled));
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
function getLocalScreenCaptureStream() {
|
||||
const constraints /* DisplayMediaStreamConstraints */ = {
|
||||
@@ -557,23 +585,23 @@ const processCommand = (function () {
|
||||
return navigator.mediaDevices.getDisplayMedia(constraints);
|
||||
}
|
||||
function callMediaConstraints(mediaType, facingMode) {
|
||||
switch (mediaType) {
|
||||
case CallMediaType.Audio:
|
||||
return { audio: true, video: false };
|
||||
case CallMediaType.Video:
|
||||
return {
|
||||
audio: true,
|
||||
video: {
|
||||
frameRate: 24,
|
||||
width: {
|
||||
min: 480,
|
||||
ideal: 720,
|
||||
max: 1280,
|
||||
},
|
||||
aspectRatio: 1.33,
|
||||
facingMode,
|
||||
if (mediaType == CallMediaType.Audio && !isDesktop) {
|
||||
return { audio: true, video: false };
|
||||
}
|
||||
else {
|
||||
return {
|
||||
audio: true,
|
||||
video: {
|
||||
frameRate: 24,
|
||||
width: {
|
||||
min: 480,
|
||||
ideal: 720,
|
||||
max: 1280,
|
||||
},
|
||||
};
|
||||
aspectRatio: 1.33,
|
||||
facingMode,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
function supportsInsertableStreams(useWorker) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
// Override defaults to enable worker on Chrome and Safari
|
||||
useWorker = typeof window.Worker !== "undefined";
|
||||
isDesktop = true;
|
||||
// Create WebSocket connection.
|
||||
const socket = new WebSocket(`ws://${location.host}`);
|
||||
socket.addEventListener("open", (_event) => {
|
||||
|
||||
@@ -216,6 +216,7 @@ interface Call {
|
||||
let activeCall: Call | undefined
|
||||
let answerTimeout = 30_000
|
||||
var useWorker = false
|
||||
var isDesktop = false
|
||||
var localizedState = ""
|
||||
var localizedDescription = ""
|
||||
|
||||
@@ -602,6 +603,7 @@ const processCommand = (function () {
|
||||
const pc = call.connection
|
||||
pc.ontrack = (event) => {
|
||||
try {
|
||||
console.log("LALAL ONTRACK")
|
||||
if (call.aesKey && call.key) {
|
||||
console.log("set up decryption for receiving")
|
||||
setupPeerTransform(TransformOperation.Decrypt, event.receiver as RTCRtpReceiverWithEncryption, call.worker, call.aesKey, call.key)
|
||||
@@ -613,6 +615,9 @@ const processCommand = (function () {
|
||||
console.log("LALAL ADDED TRACK " + event.track.kind)
|
||||
}
|
||||
for (const track of stream.getTracks()) {
|
||||
track.onmute = (_event) => {
|
||||
console.log("LALAL ON MUTE")
|
||||
}
|
||||
call.remoteStream.addTrack(track)
|
||||
}
|
||||
}
|
||||
@@ -699,18 +704,34 @@ const processCommand = (function () {
|
||||
enableMedia(localStream, CallMediaType.Video, false)
|
||||
}
|
||||
|
||||
replaceTracks(pc, audioTracks, false)
|
||||
replaceTracks(pc, videoTracks, call.screenShareEnabled)
|
||||
replaceTracks(pc, audioTracks, localStream, false)
|
||||
replaceTracks(pc, videoTracks, localStream, call.screenShareEnabled)
|
||||
call.localStream = localStream
|
||||
videos.local.srcObject = localStream
|
||||
|
||||
// const offer = await pc.createOffer()
|
||||
// await pc.setLocalDescription(offer)
|
||||
// // const resp: WCallRenegotiateOffer = {
|
||||
// // type: "renegotiate-offer",
|
||||
// // offer: serialize(offer),
|
||||
// // }
|
||||
// const encryption = supportsInsertableStreams(useWorker)
|
||||
// const resp: WCallOffer = {
|
||||
// type: "offer",
|
||||
// offer: serialize(offer),
|
||||
// iceCandidates: await call.iceCandidates,
|
||||
// capabilities: {encryption},
|
||||
// }
|
||||
// const apiResp: WVApiMessage = {corrId: undefined, resp, command: undefined}
|
||||
// sendMessageToNative(apiResp)
|
||||
}
|
||||
|
||||
function replaceTracks(pc: RTCPeerConnection, tracks: MediaStreamTrack[], addIfNeeded: boolean) {
|
||||
function replaceTracks(pc: RTCPeerConnection, tracks: MediaStreamTrack[], localStream: MediaStream, addIfNeeded: boolean) {
|
||||
if (!tracks.length) return
|
||||
const sender = pc.getSenders().find((s) => s.track?.kind === tracks[0].kind)
|
||||
if (sender) for (const t of tracks) sender.replaceTrack(t)
|
||||
else if (addIfNeeded) {
|
||||
for (const track of tracks) pc.addTrack(track, activeCall!.localStream)
|
||||
for (const track of tracks) pc.addTrack(track, localStream)
|
||||
const call = activeCall!
|
||||
if (call.aesKey && call.key) {
|
||||
console.log("set up encryption for sending")
|
||||
@@ -748,9 +769,17 @@ const processCommand = (function () {
|
||||
}
|
||||
}
|
||||
|
||||
function getLocalMediaStream(mediaType: CallMediaType, facingMode: VideoCamera): Promise<MediaStream> {
|
||||
async function getLocalMediaStream(mediaType: CallMediaType, facingMode: VideoCamera): Promise<MediaStream> {
|
||||
const constraints = callMediaConstraints(mediaType, facingMode)
|
||||
return navigator.mediaDevices.getUserMedia(constraints)
|
||||
const stream = await navigator.mediaDevices.getUserMedia(constraints)
|
||||
if (isDesktop) {
|
||||
stream
|
||||
.getTracks()
|
||||
.filter((elem) => elem.kind == "video")
|
||||
.forEach((elem) => (elem.enabled = false))
|
||||
stream.getTracks().forEach((elem) => console.log("LALAL TRACK EN " + elem.enabled))
|
||||
}
|
||||
return stream
|
||||
}
|
||||
|
||||
function getLocalScreenCaptureStream(): Promise<MediaStream> {
|
||||
@@ -770,23 +799,22 @@ const processCommand = (function () {
|
||||
}
|
||||
|
||||
function callMediaConstraints(mediaType: CallMediaType, facingMode: VideoCamera): MediaStreamConstraints {
|
||||
switch (mediaType) {
|
||||
case CallMediaType.Audio:
|
||||
return {audio: true, video: false}
|
||||
case CallMediaType.Video:
|
||||
return {
|
||||
audio: true,
|
||||
video: {
|
||||
frameRate: 24,
|
||||
width: {
|
||||
min: 480,
|
||||
ideal: 720,
|
||||
max: 1280,
|
||||
},
|
||||
aspectRatio: 1.33,
|
||||
facingMode,
|
||||
if (mediaType == CallMediaType.Audio && !isDesktop) {
|
||||
return {audio: true, video: false}
|
||||
} else {
|
||||
return {
|
||||
audio: true,
|
||||
video: {
|
||||
frameRate: 24,
|
||||
width: {
|
||||
min: 480,
|
||||
ideal: 720,
|
||||
max: 1280,
|
||||
},
|
||||
}
|
||||
aspectRatio: 1.33,
|
||||
facingMode,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Override defaults to enable worker on Chrome and Safari
|
||||
useWorker = typeof window.Worker !== "undefined"
|
||||
isDesktop = true
|
||||
|
||||
// Create WebSocket connection.
|
||||
const socket = new WebSocket(`ws://${location.host}`)
|
||||
|
||||
Reference in New Issue
Block a user