项目备份

This commit is contained in:
林觅
2026-04-09 10:37:51 +08:00
parent 7ed8d2dcb4
commit 4eab443148
32 changed files with 9468 additions and 0 deletions

68
module/main.js Normal file
View File

@@ -0,0 +1,68 @@
// 导入类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);