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

socket.on('meesage') not working #347

Open
ravikinharavi opened this issue Oct 3, 2023 · 4 comments
Open

socket.on('meesage') not working #347

ravikinharavi opened this issue Oct 3, 2023 · 4 comments
Labels

Comments

@ravikinharavi
Copy link

import 'package:flutter/material.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;

class checking extends StatefulWidget {
const checking({Key? key}) : super(key: key);

@OverRide
State createState() => _checkingState();
}

class _checkingState extends State {
late IO.Socket socket;

@OverRide
void initState() {
super.initState();
initSocket();
}

var k = "click";

Future initSocket() async {
socket = IO.io("http://13.126.94.67:1000", <String, dynamic>{
'autoConnect': true,
'transports': ['websocket'],
});

 socket.onConnect((_) {
  print('Connection established');

  // Emit the "connected" event after connecting
  socket.emit('connected', {
    'livestreamId': "651674a1907e321ab7acb78a",
    'coursefieldId': "649eb48d8bfdc575a18c64c6",
  });



  socket.on('connected', (data) {
    print('Response from connected event: ${data["roomId"]}');
    socket.emit('joinRoom', {
      'roomId': data["roomId"],
    });
  });
});

socket.onDisconnect((_) => print('Connection Disconnection'));
socket.onConnectError((err) => print(err));
socket.onError((err) => print(err));

// Listen for "message" event
socket.on("message", (data) {
  print("Received message: $data");
});

var test =socket;
// Connect to the server
socket.connect();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
print(socket.connected);

        // Emit the "message" event here
        socket.emit("message", {
          "livestreamId": "651674a1907e321ab7acb78a",
          "coursefieldId": "649eb48d8bfdc575a18c64c6",
          "studentId": "64d4804b4c3c39e38865b041",
          "subjectId": "649eb5718bfdc575a18c64da",
          "message": "ravi msg emmit",
          "roomId": "S_9ShObYjjcePoBGAAGV",
        });

        print(socket.connected);
      },
      child: Text("$k"),
    ),
  ),
);

}
}

@Sneh-Paghdal
Copy link

which versions are you using for server and client?

@mohammadwadhodev
Copy link

mohammadwadhodev commented Jun 23, 2024

@ravikinharavi bro did you resolve it ?
i am unable to emit any event and getting any event. my connection is stablished with socket but events are not emiting .

@rmahmadkhan
Copy link

same issue.
socket_io_client: ^2.0.3+1
platform: web
Flutter version 3.24.0

@Fanom2813
Copy link

same issue here server version is

"express": "^4.21.2",
"socket.io": "^4.8.1"

client :

socket_io_client: ^3.0.2

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

No branches or pull requests

6 participants