Code Monkey home page Code Monkey logo

Comments (4)

albertcht avatar albertcht commented on May 18, 2024 1

Hi @lostncg ,

You don't need another websocket handler for that. There's a special event name disconnect preserved for disconnect event callback. (not disconnecting)

The sender will leave all related rooms automatically. So basically you don't need to leave the rooms by yourself. And this action is before calling disconnect callback, so you are not able to get the room list for current sender.

Thanks a lot for your support! Welcome to open another issue if you still have any questions.

from laravel-swoole.

albertcht avatar albertcht commented on May 18, 2024

Hi @lostncg ,

Not sure where did you call Room facade? I tested it in websocket closure, websocket controller, http route closure and http controller, and it worked fine.

Did you access this page via Swoole server?

from laravel-swoole.

lostncg avatar lostncg commented on May 18, 2024

@albertcht , you are right, I access the page on wrong port.
The sender will leave the rooms automatically after disconnect event right?
If yes, how can I do if I need to trigger some function (like remove user from online name list)
like:

Websocket::on('disconnecting', function ($websocket) {
    // get disconected user
    $fd = $websocket->getSender();
    // get user's rooms
    $rooms = Room::getRooms($fd);
    // loop rooms name
    foreach ($rooms as $room) {
        // a function to grab room instance implments in adapter design
        $channel = $this->getChannel($room, $fd, auth()->user());
        // trigger leave room event, like remove user from online list
        $channel->leave();
    }
});

As I can understand from documentation, I need to implement my own websocket handler right?

BTW, thank for your fast response on anytime, enjoy your 🍺

from laravel-swoole.

lostncg avatar lostncg commented on May 18, 2024

Currently, I will store user's room joined in redis table, I think this is the easier implementation by now.

from laravel-swoole.

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.