Closed inyong1 closed 5 months ago
Well, your approach shouldn't work (not in the current version). In theory, everything related to the socket should be managed within the socket, since requests are executed within isolation. Dart has a limitation with isolates, where neither the Websockets class nor the HttpRequest can be sent by isolates. In the past there was a big problem when we used isolates and rooms, to be honest, this approach was impossible. If we have a room There is no way to send the websockets class via isolates, so it is not possible to delegate responsibility outside the isolate. So the only certainty we have is that this is not possible. After analyzing all possibilities, wasting more than 20 hours of my scarce time, analyzing hypotheses, talking to developers and AIs, I came to the conclusion that:
The only way to get around this would be to run it on the main thread, but this would harm anyone using the server on the mobile.
I can try to make this "configurable", but it will make the project more complex.
BTW what is the best way to beable to send message to a socket or a room from outside of socket scope, Let say we create a rest api route to send an event to a spesific room. Or let say we need to send sync event trigger to a connected socket of a room when some data in the database changed.
As for now my idea is to create a global list variable to keep connected socket. I use onOpen and onClose event to add and remove from the list. But I think this is not the best way because it create duplicate rooms collections.