Skip to content

Commit

Permalink
feat(chat):修复ws连接bug
Browse files Browse the repository at this point in the history
  • Loading branch information
li1553770945 committed Oct 16, 2024
1 parent 467855e commit 4e0ea9a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VITE_WS_BASE_URL=wss://socket.peacesheep.xyz/ws
VITE_WS_BASE_URL=wss://socket.peacesheep.xyz/socket
VITE_API_BASE_URL=https://api.peacesheep.xyz/api
22 changes: 4 additions & 18 deletions src/pages/chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import { reactive, ref, nextTick } from 'vue';
import { ElNotification } from 'element-plus';
import { stringify } from 'querystring';
import useClipboard from 'vue-clipboard3'
const wsURL = import.meta.env.VITE_WS_BASE_URLL;
const { toClipboard } = useClipboard()
interface ClientMessage {
id: string;
Expand Down Expand Up @@ -114,29 +116,13 @@ const handleMessage = (e: MessageEvent) => {
}
}
const createChat = () => {
if (window.location.host.match("localhost") != null || window.location.host.match("127.0.0.1") != null) {
globalWs = new WebSocket('ws://' + window.location.host + "/socket/new-chat")
}
else {
globalWs = new WebSocket('wss://' + window.location.host + "/socket/new-chat")
}
globalWs = new WebSocket(`${wsURL}/new-chat`)
initWs(globalWs)
}
const joinChat = (joinChatID: string, joinClientID: string = "") => {
console.log("加入聊天");
var addr = ""
if (window.location.host.match("localhost") != null || window.location.host.match("127.0.0.1") != null) {
addr = "ws:"
}
else {
addr = "wss:"
}
addr = addr + window.location.host + "/socket/join-chat?chat_id=" + joinChatID;
let addr = `${wsURL}/join-chat?chat_id=${joinChatID}`;
if (joinClientID != "") {
addr = addr + "&client_id=" + joinClientID;
}
Expand Down

0 comments on commit 4e0ea9a

Please sign in to comment.