Open minchopm opened 1 year ago
When I pass a room name, I'm getting, Firefox can’t establish a connection to the server at ws://localhost:5001/testroom.
It seems that the connection request will not even pass handleConnection()
in the nest gateway.
You could pass room name as param
new WebsocketProvider(this.socketPath, '', yDoc, {
params: {'roomName': subDoc.guid}
});
and read it
const parsedUrl = url.parse(req.url);
const parsedQs = querystring.parse(parsedUrl.query);
if(parsedQs.roomName){
const docName = parsedQs.roomName;
setupWSConnection(connection, req, { ...(docName && { docName }) });
}
if you handle multiple Web socket connections on same page, will be difficult to manage their rooms
Is there any way to connect with nestjs application with dynamic roomIds, my client side is running on react and backend is running on nestjs. but unable to connect to the room id.
frontend code :
provider.current = new WebsocketProvider(
ws://localhost:3030/ws/
, // Replace with your WebSocket server URL
${fileId}
,
ydoc.current,
)
Backend :
import { WebSocketGateway, OnGatewayConnection, OnGatewayDisconnect, WebSocketServer, } from '@nestjs/websockets'; // import { WebSocketServer } from 'ws'; import * as Y from 'yjs'; import { setupWSConnection } from 'y-websocket/bin/utils'; import { Server, WebSocket } from 'ws';
@WebSocketGateway({ cors: true }) export class AppGateway implements OnGatewayConnection, OnGatewayDisconnect { @WebSocketServer() server: Server;
handleConnection(client: WebSocket, ...args: any[]): void { console.log('connect'); const request = args[0]; const fileId = this.extractFileId(request.url);
// Create a new Yjs document or get an existing one
const ydoc = new Y.Doc();
// Setup WebSocket connection for Yjs
setupWSConnection(client, request, ydoc, {
gc: true, // garbage collection
});
console.log(`Client connected for document ID: ${fileId}`);
}
handleDisconnect(client: WebSocket): void { console.log('Client disconnected'); }
private extractFileId(url: string): string { // Extract fileId from URL return url.split('/').pop(); } } but not connected. is there any issue while using this with different servers.
one more thing when using
provider.current = new WebsocketProvider(
wss://demos.yjs.dev/ws/
, // Replace with your WebSocket server URL
${fileId}
,
ydoc.current,
)
its working.
Is there any way to implement support of rooms