mirror of
https://github.com/vdalex25/rtsp-to-web-player.git
synced 2025-09-26 21:01:42 +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'),
|
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++) {
|
||||||
|
@@ -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 = () => {
|
||||||
|
@@ -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) {
|
||||||
|
Reference in New Issue
Block a user