Coder Social home page Coder Social logo

Comments (9)

itaispector avatar itaispector commented on May 21, 2024 4

Came across the same issue. Apparently calling .connect() causes all event handlers to get registered/fired twice.

Try removing the connect() call, the socket should automatically connect.

still fired twice

from socket.io-client-dart.

bastibense avatar bastibense commented on May 21, 2024 2

Came across the same issue. Apparently calling .connect() causes all event handlers to get registered/fired twice.

Try removing the connect() call, the socket should automatically connect.

from socket.io-client-dart.

jabonge avatar jabonge commented on May 21, 2024

in Flutter i dont really know why log called twice i will wait answer thank you for your attention

from socket.io-client-dart.

leonidl avatar leonidl commented on May 21, 2024

You can also add "'autoConnect': false" option to optional parameters list to stop socket from auto-connecting. In that case you will have to call connect() manually.

from socket.io-client-dart.

bastibense avatar bastibense commented on May 21, 2024

Still, shouldn't this at least print out a warning to the log or just ignore a second call to connect()?

from socket.io-client-dart.

jumperchen avatar jumperchen commented on May 21, 2024

@bastibense I reopen it, and it looks like the behavior is not the same as JS version.

from socket.io-client-dart.

RIddhiIroid avatar RIddhiIroid commented on May 21, 2024

Came across the same issue. Apparently calling .connect() causes all event handlers to get registered/fired twice.
Try removing the connect() call, the socket should automatically connect.

still fired twice

Hello
Did you manage to solve this?

from socket.io-client-dart.

akshayindia avatar akshayindia commented on May 21, 2024

Facing the same issue flutter...

from socket.io-client-dart.

akshayindia avatar akshayindia commented on May 21, 2024

front end ----

IO.Socket? socket;
@OverRide
void initState() {
super.initState();
// connect();

focusNode.addListener(() {
  if (focusNode.hasFocus) {
    setState(() {
      show = false;
    });
  }
});
connect();

}

void connect() {
// MessageModel messageModel = MessageModel(sourceId: widget.sourceChat.id.toString(),targetId: );
socket = IO.io("https://studiovity.com/", <String, dynamic>{
"transports": ["websocket"],
// "autoConnect": true,
});
// socket!.connect();
socket!.emit("signin", widget.sourchat.id);
socket!.onConnect((data) {
print("Connected");
socket!.on("message", (msg) {
print(msg);
setMessage("destination", msg["message"]);
_scrollController.animateTo(_scrollController.position.maxScrollExtent,
duration: Duration(milliseconds: 300), curve: Curves.easeOut);
});
});
print(socket!.connected);
}

Backend

const express = require("express");
var http = require("http");
const app = express();
const port = process.env.PORT || 5000;
var server = http.createServer(app);
var io = require("socket.io")(server);

//middlewre
app.use(express.json());
var clients = {};

io.on("connection", (socket) => {
console.log("connetetd");
// accept();
console.log(socket.id, "has joined");
socket.on("signin", (id) => {
console.log(id);
clients[id] = socket;
console.log(clients);
});
socket.on("message", (msg) => {
console.log(msg);
let targetId = msg.targetId;
if (clients[targetId]) clients[targetId].emit("message", msg);
});
});

server.listen(port, "0.0.0.0", () => {
console.log("server started");
});

from socket.io-client-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.