temp
This commit is contained in:
@@ -25,6 +25,7 @@ var TransformOperation;
|
|||||||
let activeCall;
|
let activeCall;
|
||||||
let answerTimeout = 30000;
|
let answerTimeout = 30000;
|
||||||
var useWorker = false;
|
var useWorker = false;
|
||||||
|
var isDesktop = false;
|
||||||
var localizedState = "";
|
var localizedState = "";
|
||||||
var localizedDescription = "";
|
var localizedDescription = "";
|
||||||
const processCommand = (function () {
|
const processCommand = (function () {
|
||||||
@@ -392,6 +393,7 @@ const processCommand = (function () {
|
|||||||
const pc = call.connection;
|
const pc = call.connection;
|
||||||
pc.ontrack = (event) => {
|
pc.ontrack = (event) => {
|
||||||
try {
|
try {
|
||||||
|
console.log("LALAL ONTRACK");
|
||||||
if (call.aesKey && call.key) {
|
if (call.aesKey && call.key) {
|
||||||
console.log("set up decryption for receiving");
|
console.log("set up decryption for receiving");
|
||||||
setupPeerTransform(TransformOperation.Decrypt, event.receiver, call.worker, call.aesKey, call.key);
|
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);
|
console.log("LALAL ADDED TRACK " + event.track.kind);
|
||||||
};
|
};
|
||||||
for (const track of stream.getTracks()) {
|
for (const track of stream.getTracks()) {
|
||||||
|
track.onmute = (_event) => {
|
||||||
|
console.log("LALAL ON MUTE");
|
||||||
|
};
|
||||||
call.remoteStream.addTrack(track);
|
call.remoteStream.addTrack(track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,12 +494,27 @@ const processCommand = (function () {
|
|||||||
if (!call.cameraEnabled && !call.screenShareEnabled) {
|
if (!call.cameraEnabled && !call.screenShareEnabled) {
|
||||||
enableMedia(localStream, CallMediaType.Video, false);
|
enableMedia(localStream, CallMediaType.Video, false);
|
||||||
}
|
}
|
||||||
replaceTracks(pc, audioTracks, false);
|
replaceTracks(pc, audioTracks, localStream, false);
|
||||||
replaceTracks(pc, videoTracks, call.screenShareEnabled);
|
replaceTracks(pc, videoTracks, localStream, call.screenShareEnabled);
|
||||||
call.localStream = localStream;
|
call.localStream = localStream;
|
||||||
videos.local.srcObject = 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;
|
var _a;
|
||||||
if (!tracks.length)
|
if (!tracks.length)
|
||||||
return;
|
return;
|
||||||
@@ -504,7 +524,7 @@ const processCommand = (function () {
|
|||||||
sender.replaceTrack(t);
|
sender.replaceTrack(t);
|
||||||
else if (addIfNeeded) {
|
else if (addIfNeeded) {
|
||||||
for (const track of tracks)
|
for (const track of tracks)
|
||||||
pc.addTrack(track, activeCall.localStream);
|
pc.addTrack(track, localStream);
|
||||||
const call = activeCall;
|
const call = activeCall;
|
||||||
if (call.aesKey && call.key) {
|
if (call.aesKey && call.key) {
|
||||||
console.log("set up encryption for sending");
|
console.log("set up encryption for sending");
|
||||||
@@ -537,9 +557,17 @@ const processCommand = (function () {
|
|||||||
console.log(`no ${operation}`);
|
console.log(`no ${operation}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function getLocalMediaStream(mediaType, facingMode) {
|
async function getLocalMediaStream(mediaType, facingMode) {
|
||||||
const constraints = callMediaConstraints(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() {
|
function getLocalScreenCaptureStream() {
|
||||||
const constraints /* DisplayMediaStreamConstraints */ = {
|
const constraints /* DisplayMediaStreamConstraints */ = {
|
||||||
@@ -557,10 +585,10 @@ const processCommand = (function () {
|
|||||||
return navigator.mediaDevices.getDisplayMedia(constraints);
|
return navigator.mediaDevices.getDisplayMedia(constraints);
|
||||||
}
|
}
|
||||||
function callMediaConstraints(mediaType, facingMode) {
|
function callMediaConstraints(mediaType, facingMode) {
|
||||||
switch (mediaType) {
|
if (mediaType == CallMediaType.Audio && !isDesktop) {
|
||||||
case CallMediaType.Audio:
|
|
||||||
return { audio: true, video: false };
|
return { audio: true, video: false };
|
||||||
case CallMediaType.Video:
|
}
|
||||||
|
else {
|
||||||
return {
|
return {
|
||||||
audio: true,
|
audio: true,
|
||||||
video: {
|
video: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// Override defaults to enable worker on Chrome and Safari
|
// Override defaults to enable worker on Chrome and Safari
|
||||||
useWorker = typeof window.Worker !== "undefined";
|
useWorker = typeof window.Worker !== "undefined";
|
||||||
|
isDesktop = true;
|
||||||
// Create WebSocket connection.
|
// Create WebSocket connection.
|
||||||
const socket = new WebSocket(`ws://${location.host}`);
|
const socket = new WebSocket(`ws://${location.host}`);
|
||||||
socket.addEventListener("open", (_event) => {
|
socket.addEventListener("open", (_event) => {
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ interface Call {
|
|||||||
let activeCall: Call | undefined
|
let activeCall: Call | undefined
|
||||||
let answerTimeout = 30_000
|
let answerTimeout = 30_000
|
||||||
var useWorker = false
|
var useWorker = false
|
||||||
|
var isDesktop = false
|
||||||
var localizedState = ""
|
var localizedState = ""
|
||||||
var localizedDescription = ""
|
var localizedDescription = ""
|
||||||
|
|
||||||
@@ -602,6 +603,7 @@ const processCommand = (function () {
|
|||||||
const pc = call.connection
|
const pc = call.connection
|
||||||
pc.ontrack = (event) => {
|
pc.ontrack = (event) => {
|
||||||
try {
|
try {
|
||||||
|
console.log("LALAL ONTRACK")
|
||||||
if (call.aesKey && call.key) {
|
if (call.aesKey && call.key) {
|
||||||
console.log("set up decryption for receiving")
|
console.log("set up decryption for receiving")
|
||||||
setupPeerTransform(TransformOperation.Decrypt, event.receiver as RTCRtpReceiverWithEncryption, call.worker, call.aesKey, call.key)
|
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)
|
console.log("LALAL ADDED TRACK " + event.track.kind)
|
||||||
}
|
}
|
||||||
for (const track of stream.getTracks()) {
|
for (const track of stream.getTracks()) {
|
||||||
|
track.onmute = (_event) => {
|
||||||
|
console.log("LALAL ON MUTE")
|
||||||
|
}
|
||||||
call.remoteStream.addTrack(track)
|
call.remoteStream.addTrack(track)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -699,18 +704,34 @@ const processCommand = (function () {
|
|||||||
enableMedia(localStream, CallMediaType.Video, false)
|
enableMedia(localStream, CallMediaType.Video, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceTracks(pc, audioTracks, false)
|
replaceTracks(pc, audioTracks, localStream, false)
|
||||||
replaceTracks(pc, videoTracks, call.screenShareEnabled)
|
replaceTracks(pc, videoTracks, localStream, call.screenShareEnabled)
|
||||||
call.localStream = localStream
|
call.localStream = localStream
|
||||||
videos.local.srcObject = 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
|
if (!tracks.length) return
|
||||||
const sender = pc.getSenders().find((s) => s.track?.kind === tracks[0].kind)
|
const sender = pc.getSenders().find((s) => s.track?.kind === tracks[0].kind)
|
||||||
if (sender) for (const t of tracks) sender.replaceTrack(t)
|
if (sender) for (const t of tracks) sender.replaceTrack(t)
|
||||||
else if (addIfNeeded) {
|
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!
|
const call = activeCall!
|
||||||
if (call.aesKey && call.key) {
|
if (call.aesKey && call.key) {
|
||||||
console.log("set up encryption for sending")
|
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)
|
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> {
|
function getLocalScreenCaptureStream(): Promise<MediaStream> {
|
||||||
@@ -770,10 +799,9 @@ const processCommand = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function callMediaConstraints(mediaType: CallMediaType, facingMode: VideoCamera): MediaStreamConstraints {
|
function callMediaConstraints(mediaType: CallMediaType, facingMode: VideoCamera): MediaStreamConstraints {
|
||||||
switch (mediaType) {
|
if (mediaType == CallMediaType.Audio && !isDesktop) {
|
||||||
case CallMediaType.Audio:
|
|
||||||
return {audio: true, video: false}
|
return {audio: true, video: false}
|
||||||
case CallMediaType.Video:
|
} else {
|
||||||
return {
|
return {
|
||||||
audio: true,
|
audio: true,
|
||||||
video: {
|
video: {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// Override defaults to enable worker on Chrome and Safari
|
// Override defaults to enable worker on Chrome and Safari
|
||||||
useWorker = typeof window.Worker !== "undefined"
|
useWorker = typeof window.Worker !== "undefined"
|
||||||
|
isDesktop = true
|
||||||
|
|
||||||
// Create WebSocket connection.
|
// Create WebSocket connection.
|
||||||
const socket = new WebSocket(`ws://${location.host}`)
|
const socket = new WebSocket(`ws://${location.host}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user