1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-14 04:35:57 +01:00

Make presenting files a chat command.

This commit is contained in:
Juliusz Chroboczek 2022-02-21 17:32:32 +01:00
parent 5ecb3a1f93
commit cbcfbb3f74
2 changed files with 38 additions and 27 deletions

View file

@ -233,11 +233,6 @@
</form> </form>
</fieldset> </fieldset>
<form id="fileform">
<label for="fileinput" class=".sidenav-label-first">Play local file:</label>
<input type="file" id="fileinput" accept="audio/*,video/*" multiple/>
</form>
</div> </div>
</div> </div>

View file

@ -405,11 +405,6 @@ function setButtonsVisibility() {
let present = permissions.indexOf('present') >= 0; let present = permissions.indexOf('present') >= 0;
let local = !!findUpMedia('camera'); let local = !!findUpMedia('camera');
let canWebrtc = !(typeof RTCPeerConnection === 'undefined'); let canWebrtc = !(typeof RTCPeerConnection === 'undefined');
let canFile =
/** @ts-ignore */
!!HTMLVideoElement.prototype.captureStream ||
/** @ts-ignore */
!!HTMLVideoElement.prototype.mozCaptureStream;
let mediacount = document.getElementById('peers').childElementCount; let mediacount = document.getElementById('peers').childElementCount;
let mobilelayout = isMobileLayout(); let mobilelayout = isMobileLayout();
@ -426,7 +421,6 @@ function setButtonsVisibility() {
setVisibility('mediaoptions', present); setVisibility('mediaoptions', present);
setVisibility('sendform', present); setVisibility('sendform', present);
setVisibility('simulcastform', present); setVisibility('simulcastform', present);
setVisibility('fileform', canFile && present);
setVisibility('collapse-video', mediacount && mobilelayout); setVisibility('collapse-video', mediacount && mobilelayout);
} }
@ -617,21 +611,6 @@ getInputElement('activitybox').onchange = function(e) {
} }
}; };
getInputElement('fileinput').onchange = function(e) {
if(!(this instanceof HTMLInputElement))
throw new Error('Unexpected type for this');
let input = this;
let files = input.files;
for(let i = 0; i < files.length; i++) {
addFileMedia(files[i]).catch(e => {
console.error(e);
displayError(e);
});
}
input.value = '';
closeNav();
};
/** /**
* @this {Stream} * @this {Stream}
* @param {Object<string,any>} stats * @param {Object<string,any>} stats
@ -3375,6 +3354,43 @@ commands.unraise = {
} }
} }
function presentFile() {
let input = document.createElement('input');
input.type = 'file';
input.accept="audio/*,video/*";
input.onchange = function(e) {
if(!(this instanceof HTMLInputElement))
throw new Error('Unexpected type for this');
let files = this.files;
for(let i = 0; i < files.length; i++) {
addFileMedia(files[i]).catch(e => {
console.error(e);
displayError(e);
});
}
};
input.click();
}
commands.presentfile = {
description: 'broadcast a video or audio file',
f: (c, r) => {
presentFile();
},
predicate: () => {
if(!serverConnection || !serverConnection.permissions ||
serverConnection.permissions.indexOf('present') < 0)
return 'You are not authorised to present';
/** @ts-ignore */
if(!HTMLVideoElement.prototype.captureStream &&
/** @ts-ignore */
!HTMLVideoElement.prototype.mozCaptureStream)
return 'Your browser does not support presenting arbitrary files';
return null;
},
};
/** /**
* @param {string} id * @param {string} id
*/ */
@ -3384,7 +3400,7 @@ function sendFile(id) {
input.onchange = function(e) { input.onchange = function(e) {
if(!(this instanceof HTMLInputElement)) if(!(this instanceof HTMLInputElement))
throw new Error('Unexpected type for this'); throw new Error('Unexpected type for this');
let files = input.files; let files = this.files;
for(let i = 0; i < files.length; i++) { for(let i = 0; i < files.length; i++) {
try { try {
offerFile(id, files[i]); offerFile(id, files[i]);