Skip to content
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

Auto-reconnect colyseus.js to server #62

Closed
seiyria opened this issue Jun 26, 2017 · 8 comments
Closed

Auto-reconnect colyseus.js to server #62

seiyria opened this issue Jun 26, 2017 · 8 comments

Comments

@seiyria
Copy link
Contributor

seiyria commented Jun 26, 2017

In my development environment, any time I save/restart the server (I'm using nodemon), it reboots. The client will disconnect and then I have to refresh the page to reconnect. In a live game, this means that if I push an update to the server every player will disconnect and not attempt to reconnect automatically.

Automatic reconnection (with exponential backoff configurable, as primus has) would help this a lot.

@endel
Copy link
Member

endel commented Jun 26, 2017

That'd be useful indeed, thanks for the request @seiyria (I thought we'd have it in the new structure, but this feature is still missing)

@seiyria
Copy link
Contributor Author

seiyria commented Oct 12, 2017

any chance this will make it in with an update to the 0.5.x branch?

@endel
Copy link
Member

endel commented Oct 13, 2017

hopefully, we'll have it in a couple of weeks!

@seiyria
Copy link
Contributor Author

seiyria commented Oct 29, 2017

Right now, this kinda works. If the server reboots, the client will predictably disconnect, and then it will reconnect but it will get BUFFER_SHORTAGE errors. To make this work again, the page has to be refreshed and a new connection has to be created.

endel added a commit to colyseus/colyseus.js that referenced this issue Nov 2, 2017
@endel
Copy link
Member

endel commented Nov 2, 2017

@seiyria can you try colyseus.js@0.7.6?

When reconnecting automatically, the WebSocket was loosing the binaryType property. The BUFFER_SHORTAGE was happening because the data was coming as Blob instead of ArrayBuffer, and couldn't be decoded because of that.

Cheers!

@seiyria
Copy link
Contributor Author

seiyria commented Nov 2, 2017

@endel it looks like I will still get it during those other conditions (ie, randomly on joining a room). However, it no longer happens on reset! I'll try to dig in on why this is happening.

Now, on refresh, I get:

core.es5.js:1084 ERROR TypeError: Cannot read property 'id' of undefined

Here:

    Client.prototype.onMessageCallback = function (event) {
        var _this = this;
        var message = msgpack.decode(new Uint8Array(event.data));
        var code = message[0];
        if (code == Protocol_1.Protocol.USER_ID) {
            this.storage.setItem('colyseusid', message[1]);
            this.id = message[1];
            this.onOpen.dispatch();
        }
        else if (code == Protocol_1.Protocol.JOIN_ROOM) {
            var requestId = message[2];
            var room_1 = this.connectingRooms[requestId];
            this.rooms[room_1.id] = room_1; // <------------------------ this line
            room_1.id = message[1];
            room_1.connect(new Connection_1.Connection(this.hostname + "/" + room_1.id + "?colyseusid=" + this.id));
            room_1.onLeave.add(function () { return delete _this.rooms[room_1.id]; });
            delete this.connectingRooms[requestId];
        }
        else if (code == Protocol_1.Protocol.JOIN_ERROR) {
            console.error("server error:", message[2]);
            // general error
            this.onError.dispatch(message[2]);
        }
        else {
            this.onMessage.dispatch(message);
        }
    };

@seiyria
Copy link
Contributor Author

seiyria commented Dec 11, 2017

This looks like it's working now, with no side effects!

@endel
Copy link
Member

endel commented Mar 30, 2018

Closing as this seems to be solved. Feel free to re-open if you'd like to!

@endel endel closed this as completed Mar 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants