add wsClose handler

This commit is contained in:
vdalex
2024-02-13 15:09:18 +03:00
parent 5dbdbdb612
commit 11bedf4f17
4 changed files with 19 additions and 3 deletions

File diff suppressed because one or more lines are too long

3
dist/index.html vendored
View File

@@ -35,6 +35,9 @@
parentElement: document.getElementById('player'), parentElement: document.getElementById('player'),
autoplay: true, autoplay: true,
debug: true, debug: true,
onWsClose: (code,reason)=>{
console.log(code,reason);
},
getPresets: (video, audio) => { getPresets: (video, audio) => {
document.getElementById("control").innerHTML = ''; document.getElementById("control").innerHTML = '';
for (let i = 0; i < video.length; i++) { for (let i = 0; i < video.length; i++) {

View File

@@ -31,7 +31,10 @@
const options = { const options = {
parentElement: document.getElementById('player'), parentElement: document.getElementById('player'),
debug: true debug: true,
onWsClose: (code,reason)=>{
console.log(code,reason);
},
}; };
const player = new RTSPtoWEBPlayer(options); const player = new RTSPtoWEBPlayer(options);
const play = () => { const play = () => {

View File

@@ -43,6 +43,7 @@ export default class RTSPtoWEBPlayer {
getPresets: null, getPresets: null,
onResolutionChange: null, onResolutionChange: null,
latency: null, latency: null,
onWsClose: null,
}; };
constructor(options) { constructor(options) {
@@ -117,6 +118,9 @@ export default class RTSPtoWEBPlayer {
this.webSocket = new WebSocket(this.options.source); this.webSocket = new WebSocket(this.options.source);
this.webSocket.onclose = e => { this.webSocket.onclose = e => {
if (typeof this.options.onWsClose === 'function') {
this.options.onWsClose(e.code, e.reason);
}
this.debugLogger(e); this.debugLogger(e);
}; };
@@ -133,6 +137,9 @@ export default class RTSPtoWEBPlayer {
this.webRtcSocket.onclose = e => { this.webRtcSocket.onclose = e => {
this.debugLogger(e); this.debugLogger(e);
this.webRtcSocket.onmessage = null; this.webRtcSocket.onmessage = null;
if (typeof this.options.onWsClose === 'function') {
this.options.onWsClose(e.code, e.reason);
}
}; };
this.webRtcSocket.onerror = e => { this.webRtcSocket.onerror = e => {
this.debugLogger(e); this.debugLogger(e);
@@ -312,8 +319,11 @@ export default class RTSPtoWEBPlayer {
websocketEvents = () => { websocketEvents = () => {
this.webSocket = new WebSocket(this.options.source); this.webSocket = new WebSocket(this.options.source);
this.webSocket.binaryType = 'arraybuffer'; this.webSocket.binaryType = 'arraybuffer';
this.webSocket.onclose = () => { this.webSocket.onclose = e => {
this.webSocket.onmessage = null; this.webSocket.onmessage = null;
if (typeof this.options.onWsClose === 'function') {
this.options.onWsClose(e.code, e.reason);
}
}; };
this.webSocket.onmessage = ({data}) => { this.webSocket.onmessage = ({data}) => {
if (this.codec === null) { if (this.codec === null) {