refactor: Incorporate minor go2rtc client changes (#2158)
- Closes: #1957
This commit is contained in:
@@ -390,8 +390,8 @@ export class VideoRTC extends HTMLElement {
|
|||||||
|
|
||||||
this.ws = new WebSocket(this.wsURL);
|
this.ws = new WebSocket(this.wsURL);
|
||||||
this.ws.binaryType = 'arraybuffer';
|
this.ws.binaryType = 'arraybuffer';
|
||||||
this.ws.addEventListener('open', (ev) => this.onopen(ev));
|
this.ws.addEventListener('open', () => this.onopen());
|
||||||
this.ws.addEventListener('close', (ev) => this.onclose(ev));
|
this.ws.addEventListener('close', () => this.onclose());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -543,25 +543,31 @@ export class VideoRTC extends HTMLElement {
|
|||||||
const sb = ms.addSourceBuffer(msg.value);
|
const sb = ms.addSourceBuffer(msg.value);
|
||||||
sb.mode = 'segments'; // segments or sequence
|
sb.mode = 'segments'; // segments or sequence
|
||||||
sb.addEventListener('updateend', () => {
|
sb.addEventListener('updateend', () => {
|
||||||
if (sb.updating) return;
|
if (!sb.updating && bufLen > 0) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (bufLen > 0) {
|
|
||||||
const data = buf.slice(0, bufLen);
|
const data = buf.slice(0, bufLen);
|
||||||
bufLen = 0;
|
|
||||||
sb.appendBuffer(data);
|
sb.appendBuffer(data);
|
||||||
} else if (sb.buffered && sb.buffered.length) {
|
bufLen = 0;
|
||||||
const end = sb.buffered.end(sb.buffered.length - 1) - 15;
|
|
||||||
const start = sb.buffered.start(0);
|
|
||||||
if (end > start) {
|
|
||||||
sb.remove(start, end);
|
|
||||||
ms.setLiveSeekableRange(end, end + 15);
|
|
||||||
}
|
|
||||||
// console.debug("VideoRTC.buffered", start, end);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// console.debug(e);
|
// console.debug(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sb.updating && sb.buffered && sb.buffered.length) {
|
||||||
|
const end = sb.buffered.end(sb.buffered.length - 1);
|
||||||
|
const start = end - 5;
|
||||||
|
const start0 = sb.buffered.start(0);
|
||||||
|
if (start > start0) {
|
||||||
|
sb.remove(start0, start);
|
||||||
|
ms.setLiveSeekableRange(start, end);
|
||||||
|
}
|
||||||
|
if (this.video.currentTime < start) {
|
||||||
|
this.video.currentTime = start;
|
||||||
|
}
|
||||||
|
const gap = end - this.video.currentTime;
|
||||||
|
this.video.playbackRate = gap > 0.1 ? gap : 0.1;
|
||||||
|
// console.debug('VideoRTC.buffered', gap, this.video.playbackRate, this.video.readyState);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const buf = new Uint8Array(2 * 1024 * 1024);
|
const buf = new Uint8Array(2 * 1024 * 1024);
|
||||||
|
|||||||
Reference in New Issue
Block a user