mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Implement playing of local files.
This commit is contained in:
parent
2c17157ea2
commit
3167c217db
3 changed files with 57 additions and 8 deletions
|
@ -191,6 +191,11 @@
|
||||||
<form>
|
<form>
|
||||||
<input id="activitybox" type="checkbox">Activity detection</input>
|
<input id="activitybox" type="checkbox">Activity detection</input>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label for="fileinput">Play local file:</label>
|
||||||
|
<input type="file" id="fileinput" accept="audio/*,video/*" multiple></input>
|
||||||
|
</form>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -524,6 +524,13 @@ getInputElement('activitybox').onchange = function(e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInputElement('fileinput').onchange = function(e) {
|
||||||
|
let input = /** @type{HTMLInputElement} */(this);
|
||||||
|
let files = input.files;
|
||||||
|
for(let i = 0; i < files.length; i++)
|
||||||
|
addFileMedia(files[i]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @this {Stream}
|
* @this {Stream}
|
||||||
* @param {Object<string,any>} stats
|
* @param {Object<string,any>} stats
|
||||||
|
@ -866,6 +873,36 @@ async function addShareMedia() {
|
||||||
setButtonsVisibility()
|
setButtonsVisibility()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {File} file
|
||||||
|
*/
|
||||||
|
async function addFileMedia(file) {
|
||||||
|
if(!getUserPass())
|
||||||
|
return;
|
||||||
|
|
||||||
|
let url = URL.createObjectURL(file);
|
||||||
|
let video = document.createElement('video');
|
||||||
|
video.src = url;
|
||||||
|
/** @ts-ignore */
|
||||||
|
let stream = video.captureStream();
|
||||||
|
|
||||||
|
let c = newUpStream();
|
||||||
|
c.kind = 'video';
|
||||||
|
c.stream = stream;
|
||||||
|
stream.onaddtrack = function(e) {
|
||||||
|
let t = e.track;
|
||||||
|
c.pc.addTrack(t, stream);
|
||||||
|
t.onended = e => {
|
||||||
|
delUpMedia(c);
|
||||||
|
}
|
||||||
|
c.labels[t.id] = t.kind;
|
||||||
|
c.onstats = gotUpStats;
|
||||||
|
c.setStatsInterval(2000);
|
||||||
|
};
|
||||||
|
setMedia(c, true, video);
|
||||||
|
video.play();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Stream} c
|
* @param {Stream} c
|
||||||
*/
|
*/
|
||||||
|
@ -947,8 +984,9 @@ function muteLocalTracks(mute) {
|
||||||
/**
|
/**
|
||||||
* @param {Stream} c
|
* @param {Stream} c
|
||||||
* @param {boolean} isUp
|
* @param {boolean} isUp
|
||||||
|
* @param {HTMLVideoElement} [video]
|
||||||
*/
|
*/
|
||||||
function setMedia(c, isUp) {
|
function setMedia(c, isUp, video) {
|
||||||
let peersdiv = document.getElementById('peers');
|
let peersdiv = document.getElementById('peers');
|
||||||
let settings = getSettings();
|
let settings = getSettings();
|
||||||
let local_media;
|
let local_media;
|
||||||
|
@ -970,15 +1008,19 @@ function setMedia(c, isUp) {
|
||||||
let media = /** @type {HTMLVideoElement} */
|
let media = /** @type {HTMLVideoElement} */
|
||||||
(document.getElementById('media-' + c.id));
|
(document.getElementById('media-' + c.id));
|
||||||
if(!media) {
|
if(!media) {
|
||||||
media = document.createElement('video');
|
if(video) {
|
||||||
media.id = 'media-' + c.id;
|
media = video;
|
||||||
|
} else {
|
||||||
|
media = document.createElement('video');
|
||||||
|
media.controls = false;
|
||||||
|
if(isUp)
|
||||||
|
media.muted = true;
|
||||||
|
}
|
||||||
media.classList.add('media');
|
media.classList.add('media');
|
||||||
media.autoplay = true;
|
media.autoplay = true;
|
||||||
/** @ts-ignore */
|
/** @ts-ignore */
|
||||||
media.playsinline = true;
|
media.playsinline = true;
|
||||||
media.controls = false;
|
media.id = 'media-' + c.id;
|
||||||
if(isUp)
|
|
||||||
media.muted = true;
|
|
||||||
div.appendChild(media);
|
div.appendChild(media);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1024,7 +1066,9 @@ function setMedia(c, isUp) {
|
||||||
camera.remove();
|
camera.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
media.srcObject = c.stream;
|
if(!video)
|
||||||
|
media.srcObject = c.stream;
|
||||||
|
|
||||||
setLabel(c);
|
setLabel(c);
|
||||||
setMediaStatus(c);
|
setMediaStatus(c);
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ func Serve(address string, dataDir string) error {
|
||||||
|
|
||||||
func mungeHeader(w http.ResponseWriter) {
|
func mungeHeader(w http.ResponseWriter) {
|
||||||
w.Header().Add("Content-Security-Policy",
|
w.Header().Add("Content-Security-Policy",
|
||||||
"connect-src ws: wss: 'self'; img-src data: 'self'; default-src 'self'")
|
"connect-src ws: wss: 'self'; img-src data: 'self'; media-src blob: 'self'; default-src 'self'")
|
||||||
}
|
}
|
||||||
|
|
||||||
func notFound(w http.ResponseWriter) {
|
func notFound(w http.ResponseWriter) {
|
||||||
|
|
Loading…
Reference in a new issue