Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to access events in the custom rooms #362

Open
sadhan46 opened this issue Feb 8, 2024 · 3 comments
Open

Not able to access events in the custom rooms #362

sadhan46 opened this issue Feb 8, 2024 · 3 comments

Comments

@sadhan46
Copy link

sadhan46 commented Feb 8, 2024

This is my sever code

socket.on('join', (data) => {
        console.log('socket join')
        console.log('USERID to join ------>>>>>>' + data)
        const userId = data;
        // Check if the user already exists in the database
        if (userId != null && !io.sockets.adapter.rooms.has(userId)) {
            console.log(userId);
            console.log('userId' + userId);
            socket.join(userId);
        } else {
            console.log(socket.id + 'tried to join ' + userId + 'but the room already exist.');
            // Socket.join is not executed, hence the room not created.
        };
        console.log(io.sockets.adapter.rooms);
    });```


////.  This is where i'm trying to emit an event to a room created which is basically a userID
    
`
socket.on('roomTest', (data) => {
        console.log('RoomTest join')
        console.log('ROOOOM Test to join ------>>>>>>' + data)
        io.to('65bf75e048180ac736b89aab').emit('room', { "room_test": "DONE TEST" });
    });`
    
    
////.  On my app side in flutter this is the code structure 
    
    ``
import 'package:after/utils/secureDb.utils.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:socket_io_client/socket_io_client.dart' as io;

final socketProvider = Provider((ref) => SocketService());

class SocketService {
  late io.Socket socket;

  SocketService() {
    initSocket();
  }

  void initSocket() {
    print('socket initialized');
    socket = io.io('http://localhost:4000', <String, dynamic>{
      'transports': ['websocket'],
      'autoConnect': false,
    });

    socket.connect();

    socket.onConnect((_) async {
      print('Connected');
    });

    socket.on('65bf75e048180ac736b89aab', (data) {
      print('New Message: $data');
      // Handle new message received from the server
    });

  void disposeSocket() {
    socket.dispose();
  }
}

``
@jumperchen
Copy link
Member

Which client and server version are you using?

@sadhan46
Copy link
Author

sadhan46 commented Feb 9, 2024

In flutter :
socket_io_client: ^2.0.3+1

in node js :
"socket.io": "^4.7.2"

@jumperchen
Copy link
Member

Could you please try this v3.0.0-beta.0, and see if it solves your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants