Add support URL as JS player src
This commit is contained in:
+15
-13
@@ -132,16 +132,16 @@ class VideoRTC extends HTMLElement {
|
|||||||
this.ws = null;
|
this.ws = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal WebSocket connection state. Values: STOP, CONNECTING, OPEN, CLOSED
|
* Internal WebSocket connection state. Values: CONNECTING, OPEN, CLOSED
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.wsState = WebSocket.CLOSED;
|
this.wsState = WebSocket.CLOSED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal WebSocket URL.
|
* Internal WebSocket URL.
|
||||||
* @type {string}
|
* @type {string|URL}
|
||||||
*/
|
*/
|
||||||
this.wsURL = "";
|
this.url = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {RTCPeerConnection}
|
* @type {RTCPeerConnection}
|
||||||
@@ -172,16 +172,18 @@ class VideoRTC extends HTMLElement {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set video source (WebSocket URL). Support relative path.
|
* Set video source (WebSocket URL). Support relative path.
|
||||||
* @param {string} value
|
* @param {string|URL} value
|
||||||
*/
|
*/
|
||||||
set src(value) {
|
set src(value) {
|
||||||
if (value.startsWith("/")) {
|
if (typeof value === "string") {
|
||||||
value = "ws" + location.origin.substring(4) + value;
|
if (value.startsWith("/")) {
|
||||||
} else if (value.startsWith("http")) {
|
value = "ws" + location.origin.substring(4) + value;
|
||||||
value = "ws" + value.substring(4);
|
} else if (value.startsWith("http")) {
|
||||||
|
value = "ws" + value.substring(4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.wsURL = value;
|
this.url = value;
|
||||||
|
|
||||||
if (this.isConnected) this.connectedCallback();
|
if (this.isConnected) this.connectedCallback();
|
||||||
}
|
}
|
||||||
@@ -204,7 +206,7 @@ class VideoRTC extends HTMLElement {
|
|||||||
* @param {Object} value
|
* @param {Object} value
|
||||||
*/
|
*/
|
||||||
send(value) {
|
send(value) {
|
||||||
this.ws && this.ws.send(JSON.stringify(value));
|
if (this.ws) this.ws.send(JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
get closed() {
|
get closed() {
|
||||||
@@ -239,7 +241,7 @@ class VideoRTC extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.wsURL || !this.closed) return;
|
if (!this.url || !this.closed) return;
|
||||||
|
|
||||||
// CLOSED => CONNECTING
|
// CLOSED => CONNECTING
|
||||||
this.wsState = WebSocket.CONNECTING;
|
this.wsState = WebSocket.CONNECTING;
|
||||||
@@ -332,7 +334,7 @@ class VideoRTC extends HTMLElement {
|
|||||||
|
|
||||||
const ts = Date.now();
|
const ts = Date.now();
|
||||||
|
|
||||||
this.ws = new WebSocket(this.wsURL);
|
this.ws = new WebSocket(this.url);
|
||||||
|
|
||||||
this.ws.addEventListener("open", () => {
|
this.ws.addEventListener("open", () => {
|
||||||
console.debug("VideoRTC.ws.open", this.wsState);
|
console.debug("VideoRTC.ws.open", this.wsState);
|
||||||
@@ -545,7 +547,7 @@ class VideoRTC extends HTMLElement {
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.addEventListener("load", () => {
|
reader.addEventListener("load", () => {
|
||||||
this.video.poster = reader.result;
|
this.video.poster = reader.result;
|
||||||
})
|
});
|
||||||
|
|
||||||
this.ws.binaryType = "blob";
|
this.ws.binaryType = "blob";
|
||||||
this.ws.addEventListener("message", ev => {
|
this.ws.addEventListener("message", ev => {
|
||||||
|
|||||||
Reference in New Issue
Block a user