1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // import { io } from "https://cdn.socket.io/4.4.1/socket.io.esm.min.js";
- export class Connection {
- constructor() {
- socket: null;
- client: null;
- userSig: null;
- }
- startSocket(config) {
- //192.168.0.52:9099/?userId=123
- console.log("init-startSocket");
- const { sdkAppId, roomId, userId } = config;
- this.socket = io("wss://demo-kms.4dage.com", {
- reconnectionDelayMax: 10000,
- transports: ["websocket"],
- query: {
- userId: userId,
- roomId: roomId,
- },
- });
- this.socket.on("connect", (data) => {
- console.log("111", data);
- });
- this.socket.on("connect_error", (error) => {
- console.log("error", error);
- });
- // setTimeout(() => {
- // console.log("this.socket", this.socket);
- // }, 3000);
- }
- async init(config, callback) {
- console.log("init-trtc");
- this.startSocket(config);
- const { sdkAppId, roomId, userId, role } = config;
- this.socket.on("getSign", async (data) => {
- const userSig = data;
- this.userSig = userSig;
- try {
- const client = TRTC.createClient({
- mode: "live",
- sdkAppId: sdkAppId,
- userId: userId,
- role: role,
- useStringRoomId: true,
- userSig,
- });
- this.client = client;
- callback();
- } catch (error) {
- console.log("joinRoom error", error);
- callback(error);
- }
- });
- }
- }
|