This commit is contained in:
Avently
2024-09-02 19:09:44 +09:00
parent 4ca07338ea
commit 579bbf7abe
4 changed files with 70 additions and 53 deletions
@@ -35,6 +35,9 @@ var TransformOperation;
TransformOperation["Encrypt"] = "encrypt";
TransformOperation["Decrypt"] = "decrypt";
})(TransformOperation || (TransformOperation = {}));
function localMedia(call) {
return call.localMediaSources.camera || call.localMediaSources.screen ? CallMediaType.Video : CallMediaType.Audio;
}
let activeCall;
let answerTimeout = 30000;
var useWorker = false;
@@ -143,7 +146,11 @@ const processCommand = (function () {
const call = {
connection: pc,
iceCandidates,
localMedia: mediaType,
localMediaSources: {
mic: true,
camera: mediaType == CallMediaType.Video && !isDesktop,
screen: false,
},
localCamera,
localStream,
remoteStream,
@@ -153,8 +160,6 @@ const processCommand = (function () {
screen: false,
},
aesKey,
screenShareEnabled: false,
cameraEnabled: !isDesktop,
};
await setupMediaStreams(call);
let connectionTimeout = setTimeout(connectionHandler, answerTimeout);
@@ -339,7 +344,7 @@ const processCommand = (function () {
if (!activeCall) {
resp = { type: "error", message: "media: call not started" };
}
else if (activeCall.localMedia == CallMediaType.Audio && command.media == CallMediaType.Video && command.enable) {
else if (localMedia(activeCall) == CallMediaType.Audio && command.media == CallMediaType.Video && command.enable) {
await startSendingVideo(activeCall, activeCall.localCamera);
resp = { type: "ok" };
}
@@ -566,8 +571,7 @@ const processCommand = (function () {
//pc.addTrack(t, call.localStream)
console.log("LALAL ADDED VIDEO TRACK " + t);
}
call.localMedia = CallMediaType.Video;
call.cameraEnabled = true;
call.localMediaSources.camera = true;
}
catch (e) {
return;
@@ -590,15 +594,17 @@ const processCommand = (function () {
const audioWasEnabled = oldAudioTracks.some((elem) => elem.enabled);
let localStream;
try {
localStream = call.screenShareEnabled ? await getLocalScreenCaptureStream() : await getLocalMediaStream(call.localMedia, camera);
localStream = call.localMediaSources.screen
? await getLocalScreenCaptureStream()
: await getLocalMediaStream(localMedia(call), camera);
}
catch (e) {
if (call.screenShareEnabled) {
call.screenShareEnabled = false;
if (call.localMediaSources.screen) {
call.localMediaSources.screen = false;
}
return;
}
if (!call.screenShareEnabled) {
if (!call.localMediaSources.screen) {
for (const t of call.localStream.getTracks())
t.stop();
}
@@ -620,7 +626,7 @@ const processCommand = (function () {
if (!audioWasEnabled && oldAudioTracks.length > 0) {
audioTracks.forEach((elem) => (elem.enabled = false));
}
if (!call.cameraEnabled && !call.screenShareEnabled) {
if (!call.localMediaSources.camera && !call.localMediaSources.screen) {
videoTracks.forEach((elem) => (elem.enabled = false));
}
replaceTracks(pc, audioTracks);
@@ -793,14 +799,14 @@ const processCommand = (function () {
for (const t of tracks)
t.enabled = enable;
if (media == CallMediaType.Video && activeCall) {
activeCall.cameraEnabled = enable;
activeCall.localMediaSources.camera = enable;
}
}
toggleScreenShare = async function () {
const call = activeCall;
if (!call)
return;
call.screenShareEnabled = !call.screenShareEnabled;
call.localMediaSources.screen = !call.localMediaSources.screen;
await replaceMedia(call, call.localCamera);
};
return processCommand;
@@ -817,7 +823,7 @@ function toggleMedia(s, media) {
res = t.enabled;
}
if (media == CallMediaType.Video && activeCall) {
activeCall.cameraEnabled = res;
activeCall.localMediaSources.camera = res;
}
return res;
}
@@ -29,7 +29,7 @@ function endCallManually() {
sendMessageToNative({ resp: { type: "end" } });
}
function toggleAudioManually() {
if (activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMedia) {
if (activeCall && localMedia(activeCall)) {
document.getElementById("toggle-audio").innerHTML = toggleMedia(activeCall.localStream, CallMediaType.Audio)
? '<img src="/desktop/images/ic_mic.svg" />'
: '<img src="/desktop/images/ic_mic_off.svg" />';
@@ -43,27 +43,29 @@ function toggleSpeakerManually() {
}
}
function toggleVideoManually() {
if (activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMedia) {
if (activeCall === null || activeCall === void 0 ? void 0 : activeCall.screenShareEnabled) {
activeCall.cameraEnabled = !activeCall.cameraEnabled;
enableVideoIcon(activeCall.cameraEnabled);
if (activeCall) {
if (activeCall.localMediaSources.screen) {
activeCall.localMediaSources.camera = !activeCall.localMediaSources.camera;
enableVideoIcon(activeCall.localMediaSources.camera);
// } else if (activeCall.localMedia == CallMediaType.Video) {
// enableVideoIcon(toggleMedia(activeCall.localStream, CallMediaType.Video))
}
else {
const apiCall = { command: { type: "media", media: CallMediaType.Video, enable: activeCall.cameraEnabled != true } };
const apiCall = { command: { type: "media", media: CallMediaType.Video, enable: activeCall.localMediaSources.camera != true } };
reactOnMessageFromServer(apiCall);
processCommand(apiCall).then(() => {
enableVideoIcon((activeCall === null || activeCall === void 0 ? void 0 : activeCall.cameraEnabled) == true);
var _a;
enableVideoIcon(((_a = activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMediaSources) === null || _a === void 0 ? void 0 : _a.camera) == true);
});
}
}
}
async function toggleScreenManually() {
const was = activeCall === null || activeCall === void 0 ? void 0 : activeCall.screenShareEnabled;
var _a;
const was = activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMediaSources.screen;
await toggleScreenShare();
if (was != (activeCall === null || activeCall === void 0 ? void 0 : activeCall.screenShareEnabled)) {
document.getElementById("toggle-screen").innerHTML = (activeCall === null || activeCall === void 0 ? void 0 : activeCall.screenShareEnabled)
if (was != (activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMediaSources.screen)) {
document.getElementById("toggle-screen").innerHTML = ((_a = activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMediaSources) === null || _a === void 0 ? void 0 : _a.screen)
? '<img src="/desktop/images/ic_stop_screen_share.svg" />'
: '<img src="/desktop/images/ic_screen_share.svg" />';
}
@@ -108,9 +110,11 @@ function reactOnMessageFromServer(msg) {
}
function reactOnMessageToServer(msg) {
var _a;
if (!activeCall)
return;
switch ((_a = msg.resp) === null || _a === void 0 ? void 0 : _a.type) {
case "peerMedia":
const className = (activeCall === null || activeCall === void 0 ? void 0 : activeCall.localMedia) == CallMediaType.Video || (activeCall === null || activeCall === void 0 ? void 0 : activeCall.peerMediaSources.camera) || (activeCall === null || activeCall === void 0 ? void 0 : activeCall.peerMediaSources.screen)
const className = localMedia(activeCall) == CallMediaType.Video || activeCall.peerMediaSources.camera || activeCall.peerMediaSources.screen
? "video"
: "audio";
document.getElementById("info-block").className = className;