mirror of
https://github.com/vdalex25/rtsp-to-web-player.git
synced 2025-09-26 12:51:21 +08:00
add wsClose handler
This commit is contained in:
2
dist/RTSPtoWEBPlayer.js
vendored
2
dist/RTSPtoWEBPlayer.js
vendored
File diff suppressed because one or more lines are too long
3
dist/index.html
vendored
3
dist/index.html
vendored
@@ -35,6 +35,9 @@
|
||||
parentElement: document.getElementById('player'),
|
||||
autoplay: true,
|
||||
debug: true,
|
||||
onWsClose: (code,reason)=>{
|
||||
console.log(code,reason);
|
||||
},
|
||||
getPresets: (video, audio) => {
|
||||
document.getElementById("control").innerHTML = '';
|
||||
for (let i = 0; i < video.length; i++) {
|
||||
|
@@ -31,7 +31,10 @@
|
||||
|
||||
const options = {
|
||||
parentElement: document.getElementById('player'),
|
||||
debug: true
|
||||
debug: true,
|
||||
onWsClose: (code,reason)=>{
|
||||
console.log(code,reason);
|
||||
},
|
||||
};
|
||||
const player = new RTSPtoWEBPlayer(options);
|
||||
const play = () => {
|
||||
|
@@ -43,6 +43,7 @@ export default class RTSPtoWEBPlayer {
|
||||
getPresets: null,
|
||||
onResolutionChange: null,
|
||||
latency: null,
|
||||
onWsClose: null,
|
||||
};
|
||||
|
||||
constructor(options) {
|
||||
@@ -117,6 +118,9 @@ export default class RTSPtoWEBPlayer {
|
||||
this.webSocket = new WebSocket(this.options.source);
|
||||
|
||||
this.webSocket.onclose = e => {
|
||||
if (typeof this.options.onWsClose === 'function') {
|
||||
this.options.onWsClose(e.code, e.reason);
|
||||
}
|
||||
this.debugLogger(e);
|
||||
};
|
||||
|
||||
@@ -133,6 +137,9 @@ export default class RTSPtoWEBPlayer {
|
||||
this.webRtcSocket.onclose = e => {
|
||||
this.debugLogger(e);
|
||||
this.webRtcSocket.onmessage = null;
|
||||
if (typeof this.options.onWsClose === 'function') {
|
||||
this.options.onWsClose(e.code, e.reason);
|
||||
}
|
||||
};
|
||||
this.webRtcSocket.onerror = e => {
|
||||
this.debugLogger(e);
|
||||
@@ -312,8 +319,11 @@ export default class RTSPtoWEBPlayer {
|
||||
websocketEvents = () => {
|
||||
this.webSocket = new WebSocket(this.options.source);
|
||||
this.webSocket.binaryType = 'arraybuffer';
|
||||
this.webSocket.onclose = () => {
|
||||
this.webSocket.onclose = e => {
|
||||
this.webSocket.onmessage = null;
|
||||
if (typeof this.options.onWsClose === 'function') {
|
||||
this.options.onWsClose(e.code, e.reason);
|
||||
}
|
||||
};
|
||||
this.webSocket.onmessage = ({data}) => {
|
||||
if (this.codec === null) {
|
||||
|
Reference in New Issue
Block a user