peertube
Namekuji 2022-12-18 06:12:59 -05:00
rodzic 5baa26086d
commit 28f616839d
5 zmienionych plików z 30 dodań i 182 usunięć

11
audon-fe/package-lock.json wygenerowano
Wyświetl plik

@ -9,6 +9,7 @@
"version": "0.1.0-dev",
"dependencies": {
"@intlify/unplugin-vue-i18n": "^0.8.1",
"@uriopass/nosleep.js": "^0.12.2",
"@vuelidate/core": "^2.0.0",
"@vuelidate/validators": "^2.0.0",
"@vueuse/core": "^9.6.0",
@ -411,6 +412,11 @@
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.16.tgz",
"integrity": "sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ=="
},
"node_modules/@uriopass/nosleep.js": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@uriopass/nosleep.js/-/nosleep.js-0.12.2.tgz",
"integrity": "sha512-aMrhyZ/pO1L0EGxI3EaQhijKDi2LZd++FtrHQItP5+lVSRD3EpwaXlDoBvCBCO9+U1E6gOxo400OC79yRHzR/A=="
},
"node_modules/@vitejs/plugin-vue": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-3.2.0.tgz",
@ -3818,6 +3824,11 @@
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.16.tgz",
"integrity": "sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ=="
},
"@uriopass/nosleep.js": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@uriopass/nosleep.js/-/nosleep.js-0.12.2.tgz",
"integrity": "sha512-aMrhyZ/pO1L0EGxI3EaQhijKDi2LZd++FtrHQItP5+lVSRD3EpwaXlDoBvCBCO9+U1E6gOxo400OC79yRHzR/A=="
},
"@vitejs/plugin-vue": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-3.2.0.tgz",

Wyświetl plik

@ -11,6 +11,7 @@
},
"dependencies": {
"@intlify/unplugin-vue-i18n": "^0.8.1",
"@uriopass/nosleep.js": "^0.12.2",
"@vuelidate/core": "^2.0.0",
"@vuelidate/validators": "^2.0.0",
"@vueuse/core": "^9.6.0",

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -1,153 +0,0 @@
import { webm, mp4 } from "./media.js";
// Detect iOS browsers < version 10
const oldIOS = () =>
typeof navigator !== "undefined" &&
parseFloat(
(
"" +
(/CPU.*OS ([0-9_]{3,4})[0-9_]{0,1}|(CPU like).*AppleWebKit.*Mobile/i.exec(
navigator.userAgent
) || [0, ""])[1]
)
.replace("undefined", "3_2")
.replace("_", ".")
.replace("_", "")
) < 10 &&
!window.MSStream;
// Detect native Wake Lock API support (Samsung Browser supports it but cannot use it)
const nativeWakeLock = () =>
"wakeLock" in navigator &&
window.navigator.userAgent.indexOf("Samsung") === -1;
class NoSleep {
constructor() {
this.enabled = false;
if (nativeWakeLock()) {
this._wakeLock = null;
const handleVisibilityChange = () => {
if (this._wakeLock !== null && document.visibilityState === "visible") {
this.enable();
}
};
document.addEventListener("visibilitychange", handleVisibilityChange);
document.addEventListener("fullscreenchange", handleVisibilityChange);
} else if (oldIOS()) {
this.noSleepTimer = null;
} else {
// Set up no sleep video element
this.noSleepVideo = document.createElement("video");
this.noSleepVideo.setAttribute("title", "No Sleep");
this.noSleepVideo.setAttribute("playsinline", "");
this._addSourceToVideo(this.noSleepVideo, "webm", webm);
this._addSourceToVideo(this.noSleepVideo, "mp4", mp4);
// For iOS >15 video needs to be on the document to work as a wake lock
Object.assign(this.noSleepVideo.style, {
position: "absolute",
left: "-100%",
top: "-100%",
});
document.querySelector("body").append(this.noSleepVideo);
this.noSleepVideo.addEventListener("loadedmetadata", () => {
if (this.noSleepVideo.duration <= 1) {
// webm source
this.noSleepVideo.setAttribute("loop", "");
} else {
// mp4 source
this.noSleepVideo.addEventListener("timeupdate", () => {
if (this.noSleepVideo.currentTime > 0.5) {
this.noSleepVideo.currentTime = Math.random();
}
});
}
});
}
}
_addSourceToVideo(element, type, dataURI) {
var source = document.createElement("source");
source.src = dataURI;
source.type = `video/${type}`;
element.appendChild(source);
}
get isEnabled() {
return this.enabled;
}
enable() {
if (nativeWakeLock()) {
return navigator.wakeLock
.request("screen")
.then((wakeLock) => {
this._wakeLock = wakeLock;
this.enabled = true;
console.log("Wake Lock active.");
this._wakeLock.addEventListener("release", () => {
// ToDo: Potentially emit an event for the page to observe since
// Wake Lock releases happen when page visibility changes.
// (https://web.dev/wakelock/#wake-lock-lifecycle)
console.log("Wake Lock released.");
});
})
.catch((err) => {
this.enabled = false;
console.error(`${err.name}, ${err.message}`);
throw err;
});
} else if (oldIOS()) {
this.disable();
console.warn(`
NoSleep enabled for older iOS devices. This can interrupt
active or long-running network requests from completing successfully.
See https://github.com/richtr/NoSleep.js/issues/15 for more details.
`);
this.noSleepTimer = window.setInterval(() => {
if (!document.hidden) {
window.location.href = window.location.href.split("#")[0];
window.setTimeout(window.stop, 0);
}
}, 15000);
this.enabled = true;
return Promise.resolve();
} else {
let playPromise = this.noSleepVideo.play();
return playPromise
.then((res) => {
this.enabled = true;
return res;
})
.catch((err) => {
this.enabled = false;
throw err;
});
}
}
disable() {
if (nativeWakeLock()) {
if (this._wakeLock) {
this._wakeLock.release();
}
this._wakeLock = null;
} else if (oldIOS()) {
if (this.noSleepTimer) {
console.warn(`
NoSleep now disabled for older iOS devices.
`);
window.clearInterval(this.noSleepTimer);
this.noSleepTimer = null;
}
} else {
this.noSleepVideo.pause();
}
this.enabled = false;
}
}
export default NoSleep;

Wyświetl plik

@ -28,7 +28,7 @@ import {
import { login } from "masto";
import { useVuelidate } from "@vuelidate/core";
import { helpers, maxLength, required } from "@vuelidate/validators";
import NoSleep from "../assets/nosleep";
import NoSleep from "@uriopass/nosleep.js";
const publishOpts = {
audioBitrate: AudioPresets.music,
@ -36,8 +36,8 @@ const publishOpts = {
};
const captureOpts = {
autoGainControl: false,
echoCancellation: false,
// autoGainControl: false,
// echoCancellation: false,
// sampleRate: 48000,
// sampleSize: 16,
// channelCount: 2
@ -45,6 +45,15 @@ const captureOpts = {
export default {
setup() {
const noSleep = new NoSleep();
document.addEventListener(
"click",
function enableNoSleep() {
document.removeEventListener("click", enableNoSleep, false);
noSleep.enable();
},
false
);
return {
v$: useVuelidate(),
donStore: useMastodonStore(),
@ -122,7 +131,6 @@ export default {
showRequestedNotification: false,
isEditLoading: false,
showEditDialog: false,
noSleepHandler: new NoSleep(),
};
},
created() {
@ -139,15 +147,6 @@ export default {
this.onResize();
},
async mounted() {
if (!this.noSleepHandler.isEnabled) {
try {
await this.noSleepHandler.enable();
} catch (err) {
// alert(err)
}
}
},
computed: {
iamMuted() {
const myAudonID = this.donStore.oauth.audon_id;
@ -198,12 +197,12 @@ export default {
try {
const resp = await axios.get(`/api/room/${this.roomID}`);
const room = new Room({
adaptiveStream: true,
dynacast: true,
publishDefaults: {
stopMicTrackOnMute: true,
simulcast: false,
},
// adaptiveStream: false,
// dynacast: false,
// publishDefaults: {
// stopMicTrackOnMute: false,
// simulcast: false,
// },
});
const self = this;
room
@ -543,11 +542,6 @@ export default {
try {
await this.roomClient.startAudio();
this.autoplayDisabled = false;
try {
await this.noSleepHandler.enable();
} catch (err) {
// alert(err);
}
} catch {
alert(this.$t("errors.connectionFailed"));
await this.roomClient.disconnect();