优化
This commit is contained in:
@@ -2,10 +2,11 @@ import * as Logger from "../utils/logger.js";
|
||||
|
||||
export class Signaling extends EventTarget {
|
||||
|
||||
constructor(interval = 1000) {
|
||||
constructor(interval = 1000, baseUrl = null) {
|
||||
super();
|
||||
this.running = false;
|
||||
this.interval = interval;
|
||||
this.baseUrl = baseUrl;
|
||||
this.sleep = msec => new Promise(resolve => setTimeout(resolve, msec));
|
||||
}
|
||||
|
||||
@@ -19,7 +20,7 @@ export class Signaling extends EventTarget {
|
||||
}
|
||||
|
||||
url(method, parameter = '') {
|
||||
let ret = location.origin + '/signaling';
|
||||
let ret = (this.baseUrl || location.origin) + '/signaling';
|
||||
if (method)
|
||||
ret += '/' + method;
|
||||
if (parameter)
|
||||
@@ -151,16 +152,17 @@ export class Signaling extends EventTarget {
|
||||
|
||||
export class WebSocketSignaling extends EventTarget {
|
||||
|
||||
constructor(interval = 1000) {
|
||||
constructor(interval = 1000, websocketUrl = null) {
|
||||
super();
|
||||
this.interval = interval;
|
||||
this.sleep = msec => new Promise(resolve => setTimeout(resolve, msec));
|
||||
|
||||
let websocketUrl;
|
||||
if (location.protocol === "https:") {
|
||||
websocketUrl = "wss://" + location.host;
|
||||
} else {
|
||||
websocketUrl = "ws://" + location.host;
|
||||
if (!websocketUrl) {
|
||||
if (location.protocol === "https:") {
|
||||
websocketUrl = "wss://" + location.host;
|
||||
} else {
|
||||
websocketUrl = "ws://" + location.host;
|
||||
}
|
||||
}
|
||||
|
||||
this.websocket = new WebSocket(websocketUrl);
|
||||
|
||||
Reference in New Issue
Block a user