-
Notifications
You must be signed in to change notification settings - Fork 21
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
How to listen event onOpen in server? #5
Comments
I'm implementing this method in But this is true, I never met this use case, so actually it's hard to do it as is, because the I think we should be able to listen to an So if you could do something like this: $dispatcher->addListener(ServerEvent::ON_OPEN, function (ConnectionInterface $conn) {
// resourceId or somethings
}); Could it be suffisant ? |
I could test your use case and it works:
You can test it by:
"require": {
"eole/sandstone": "dev-feature/connection-events@dev",
}
use Eole\Sandstone\Websocket\Event\ConnectionEvent;
$this['dispatcher']->addListener(ConnectionEvent::ON_OPEN, function (ConnectionEvent $event) {
$conn = $event->getConn();
}); Or, if you get the "dispatcher service is frozen" error, do: $this->on(ConnectionEvent::ON_OPEN, function (ConnectionEvent $event) {
$conn = $event->getConn();
}); If all is ok for you, I'll integrate all connection events in Sandstone. |
Hi @alcalyn |
Okey, just wanted to be sure that, this way, it covers your use case. I'll disptach all other events (onClose, onSubscribe, onError, ...) and release it. Until next release, |
Thank @alcalyn, I will test on this branch too. |
@tranphuoctien I opened a PR where we can listen to I let you test and let me know if it fits your need. |
I have been tested on this branch. It's working @alcalyn with both: $this['dispatcher']->addListener(ConnectionEvent::ON_OPEN, function (ConnectionEvent $event) {
$conn = $event->getConn();
});
$this->on(ConnectionEvent::ON_OPEN, function (ConnectionEvent $event) {
$conn = $event->getConn();
}); I got it! |
Good, I'll release it soon. I already upgraded to Ratchet 0.4 (in a branch) in order to try a |
(Oh, I just remembered that upgrading to Ratchet 0.4 will probably bump Sandstone to v2.0.0) |
Thank you @alcalyn !!! |
Reelased in 1.3.0 https://github.com/eole-io/sandstone/releases/tag/1.3.0 |
How to listen event onOpen in server? Because some time i need to save resourceId or somethings. Please help me ?
public function onOpen(ConnectionInterface $conn){
}
Where we can listen this event?
The text was updated successfully, but these errors were encountered: