Files
deskflow/module/main.js
2026-04-09 10:37:51 +08:00

69 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 导入类ES6 模块化)
import { webSocket_ModuleSimple } from "./newWebRtcSync.js";
class rtcCallee {
constructor(userIdentity, user_id) {
this.current_time = new Date();
this.identity = userIdentity;
// websocket对象
this.wsClient = null;
// WebRTC 核心对象
this.rtcPeer = null;
this.dataChannel = null;
this.state;
// webRTC 信令
this.clientCandidates = [];
this.remoteOffer;
this.localAnswer;
this.localStream;
this.remoteStream;
this._init_ws(user_id);
}
_init_ws(user_id) {
// websocket初始化
if (this.wsClient) {
this.wsClient = null;
}
console.info(`初始化websocket`);
// const wsService = `ws://localhost:8000/wsSignaling/${user_id}/`
const wsService = `wss://api.vlos.net/wsSignaling/${user_id}/`;
this.wsClient = new webSocket_ModuleSimple(wsService);
this.wsClient.connect();
this.handlerWsSignalingLisioner();
}
/**
* 监听websocket信息 回调函数方式监控websocket数据
*/
async handlerWsSignalingLisioner() {
this.wsClient.on({
onMessage: async (msg) => {
const res_dict = JSON.parse(msg);
console.info(
`[exportWebRtcCallee.js]->[handlerWsSignalingLisioner函数][${this.identity}][${this.current_time.toLocaleTimeString()}]>>>收到信息`,
"type:",
res_dict.type,
"长度",
msg.length,
);
switch (res_dict.type) {
case "candidate":
console.info(
`[exportWebRtcCallee.js][${this.identity}][${this.current_time.toLocaleTimeString()}]>>>监听candidate`,
res_dict.data,
);
break;
case "offer":
this.remoteOffer = res_dict.data;
console.info(
`[exportWebRtcCallee.js][${this.identity}][${this.current_time.toLocaleTimeString()}]>>>收到远程offer`,
);
console.warn(`收到的offer,`, this.remoteOffer);
break;
}
},
});
}
}
new rtcCallee("callee", 123);