尝试websocket支持登陆

This commit is contained in:
648540858
2024-11-02 12:11:52 +08:00
parent 84be003a8f
commit 9789fcd3fa
3 changed files with 18 additions and 5 deletions

View File

@@ -13,6 +13,8 @@
<script>
import userService from "./service/UserService";
export default {
name: 'log',
components: {},
@@ -39,9 +41,13 @@ export default {
console.log(window.location.host)
let url = "ws://localhost:18080/channel/log";
if (process.env.NODE_ENV !== 'development') {
url = `ws://${window.location.host}/channel/log`
if (location.protocol === "https:") {
url = `wss://${window.location.host}/channel/log`
}else {
url = `ws://${window.location.host}/channel/log`
}
}
window.websocket = new WebSocket(url);
window.websocket = new WebSocket(url, userService.getToken());
window.websocket.onclose = e => {
console.log(`conn closed: code=${e.code}, reason=${e.reason}, wasClean=${e.wasClean}`)
}