This commit is contained in:
2026-05-25 22:58:11 +08:00
parent e6dfb28ef2
commit d74a0c8121
12 changed files with 347 additions and 189 deletions

View File

@@ -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);