replace chat polling with websocket
This commit is contained in:
16
web/lib/chatSocket.js
Normal file
16
web/lib/chatSocket.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Client } from "@stomp/stompjs";
|
||||
|
||||
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || "";
|
||||
|
||||
export function createStompClient(token) {
|
||||
return new Client({
|
||||
webSocketFactory: () => {
|
||||
const SockJS = require("sockjs-client");
|
||||
return new SockJS(`${BACKEND_URL}/ws/chat-sockjs`);
|
||||
},
|
||||
connectHeaders: { Authorization: `Bearer ${token}` },
|
||||
reconnectDelay: 5000,
|
||||
heartbeatIncoming: 10000,
|
||||
heartbeatOutgoing: 10000,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user