lajosbencz / vue-wamp

AutobahnJS wrapper library fo Vue.js
MIT License
48 stars 13 forks source link

Resubscribing still not working #11

Closed xiopt closed 6 years ago

xiopt commented 6 years ago

I have a problem with resubscribing after reconnect. I know someone opened a ticket and a commit was pushed for this but I still face the problem.

Sever part:

$loop   = \React\EventLoop\Factory::create();
$pusher = new \Thruway\Peer\Client("sediu", $loop);

$pusher->on('open', function ($session) use ($loop) {
    $context = new React\ZMQ\Context($loop);
    $pull    = $context->getSocket(ZMQ::SOCKET_PULL);
    $pull->bind("tcp://127.0.0.1:5555");

    $pull->on('message', function ($entry) use ($session) {
        $entryData = json_decode($entry, true);
        if (isset($entryData['EVENT_KEY'])) {
            $session->publish(strtolower($entryData['EVENT_KEY']), [$entryData]);
        }
    });

    $internalPusher = new Pusher();
    $session->register('requestSocketData', [$internalPusher, 'processIncomingEvent']);
});

$router = new Thruway\Peer\Router($loop);
$router->addInternalClient($pusher);
$router->addTransportProvider(new Thruway\Transport\RatchetTransportProvider("0.0.0.0", 8080));
$router->start();

Vuejs main.js

import VueWamp from 'vue-wamp'
import {
    options
} from '@/utils/wamp'

Vue.use(VueWamp, options({
    onopen(session, details) {
        console.log('WAMP client connected', session, details);
    },
    onclose(reason, details) {
        console.log('WAMP client closed: ' + reason, details);
    }
}));

Vuejs component

  wamp: {
        subscribe: {
            [RPC.ER]: {
                acknowledge: true,
                function(args, kwArgs, details) {
                    window.location.reload()
                }
            },
            [RPC.ED](args, kwArgs, details) {
                if (args.length > 0 && _.has(args[0], 'message') && typeof args[0].message === 'object') this.parseSocketData(args[0].message)
            }
        }
    },

Server debug on client reconnect:

2017-11-27T17:14:16.5807960 debug      [Thruway\Transport\RatchetTransportProvider 26041] RatchetTransportProvider::onOpen
2017-11-27T17:14:16.5928090 debug      [Thruway\Transport\RatchetTransportProvider 26041] onMessage: ([1,"sediu",{"roles":{"caller":{"features":{"caller_identification":true,"progressive_call_results":true}},"callee":{"features":{"caller_identification":true,"pattern_based_registration":true,"shared_registration":true,"progressive_call_results":true,"registration_revocation":true}},"publisher":{"features":{"publisher_identification":true,"subscriber_blackwhite_listing":true,"publisher_exclusion":true}},"subscriber":{"features":{"publisher_identification":true,"pattern_based_subscription":true,"subscription_revocation":true}}}}])
2017-11-27T17:14:16.5928610 info       [Thruway\RealmManager 26041] Got prehello...

The reconnection works but I don't get any event. I need to refresh page to resubscribe

lajosbencz commented 6 years ago

Should be fixed now

xiopt commented 6 years ago

I tested a few days ago and have the same problem. I found a workaround by storing the queue in a different variable and check it every time on reconnect. Apparently after the connection is lost the the subscriptions are lost.