diff --git a/src/views/realTimeChat/realTimeChat.vue b/src/views/realTimeChat/realTimeChat.vue index 4878f81..ab47307 100644 --- a/src/views/realTimeChat/realTimeChat.vue +++ b/src/views/realTimeChat/realTimeChat.vue @@ -130,11 +130,34 @@ export default { }, socketOnLink() { - this.socket = new WebSocket("wss://43.143.227.135:8989/webrtc"); + const url = document.location.host; + this.socket = new WebSocket("wss://" + url); - this.socket.onclose = function (evt) { - console.log("连接已断开."); + this.socket.onopen = (success) => { + console.log(success, "连接成功!"); }; + + this.socket.onclose = (evt) => { + console.log(evt, "连接已断开!"); + }; + + this.socket.onerror = (evt) => { + console.log(evt, "连接失败"); + }; + + this.socket.onmessage = (e) => { + console.log(e, "e"); + }; + }, + + socketLogin() { + let req = new Object(); + req.cmd = "CMD_USER_LOGIN"; + req.username = "Passager"; + req.password = "123456"; + req.agent = "browser"; + let str = JSON.stringify(req); + this.socket.send(str); }, }, created() {},