Fixing reconnection to server on back failure
This commit is contained in:
parent
2fba6956a6
commit
a19edd4dc1
6 changed files with 87 additions and 47 deletions
|
@ -3,7 +3,7 @@ import {
|
|||
GroupCreatedUpdatedMessageInterface,
|
||||
MessageUserJoined,
|
||||
MessageUserMovedInterface,
|
||||
MessageUserPositionInterface,
|
||||
MessageUserPositionInterface, OnConnectInterface,
|
||||
PointInterface,
|
||||
PositionInterface,
|
||||
RoomJoinedMessageInterface
|
||||
|
@ -521,23 +521,14 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
top: camera.scrollY,
|
||||
right: camera.scrollX + camera.width,
|
||||
bottom: camera.scrollY + camera.height,
|
||||
}).then((connection: RoomConnection) => {
|
||||
this.connection = connection;
|
||||
}).then((onConnect: OnConnectInterface) => {
|
||||
this.connection = onConnect.connection;
|
||||
|
||||
//this.connection.emitPlayerDetailsMessage(gameManager.getPlayerName(), gameManager.getCharacterSelected())
|
||||
connection.onStartRoom((roomJoinedMessage: RoomJoinedMessageInterface) => {
|
||||
//this.initUsersPosition(roomJoinedMessage.users);
|
||||
this.connectionAnswerPromiseResolve(roomJoinedMessage);
|
||||
// Analyze tags to find if we are admin. If yes, show console.
|
||||
if (this.connection.hasTag('admin')) {
|
||||
this.ConsoleGlobalMessageManager = new ConsoleGlobalMessageManager(this.connection, this.userInputManager);
|
||||
}
|
||||
/*this.connection.onStartRoom((roomJoinedMessage: RoomJoinedMessageInterface) => {
|
||||
|
||||
this.scene.wake();
|
||||
this.scene.sleep(ReconnectingSceneName);
|
||||
});
|
||||
|
||||
connection.onUserJoins((message: MessageUserJoined) => {
|
||||
});*/
|
||||
this.connection.onUserJoins((message: MessageUserJoined) => {
|
||||
const userMessage: AddPlayerInterface = {
|
||||
userId: message.userId,
|
||||
characterLayers: message.characterLayers,
|
||||
|
@ -547,7 +538,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
this.addPlayer(userMessage);
|
||||
});
|
||||
|
||||
connection.onUserMoved((message: UserMovedMessage) => {
|
||||
this.connection.onUserMoved((message: UserMovedMessage) => {
|
||||
const position = message.getPosition();
|
||||
if (position === undefined) {
|
||||
throw new Error('Position missing from UserMovedMessage');
|
||||
|
@ -562,15 +553,15 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
this.updatePlayerPosition(messageUserMoved);
|
||||
});
|
||||
|
||||
connection.onUserLeft((userId: number) => {
|
||||
this.connection.onUserLeft((userId: number) => {
|
||||
this.removePlayer(userId);
|
||||
});
|
||||
|
||||
connection.onGroupUpdatedOrCreated((groupPositionMessage: GroupCreatedUpdatedMessageInterface) => {
|
||||
this.connection.onGroupUpdatedOrCreated((groupPositionMessage: GroupCreatedUpdatedMessageInterface) => {
|
||||
this.shareGroupPosition(groupPositionMessage);
|
||||
})
|
||||
|
||||
connection.onGroupDeleted((groupId: number) => {
|
||||
this.connection.onGroupDeleted((groupId: number) => {
|
||||
try {
|
||||
this.deleteGroup(groupId);
|
||||
} catch (e) {
|
||||
|
@ -578,7 +569,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
}
|
||||
})
|
||||
|
||||
connection.onServerDisconnected(() => {
|
||||
this.connection.onServerDisconnected(() => {
|
||||
console.log('Player disconnected from server. Reloading scene.');
|
||||
|
||||
this.simplePeer.closeAllConnections();
|
||||
|
@ -599,7 +590,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
this.scene.remove(this.scene.key);
|
||||
})
|
||||
|
||||
connection.onActionableEvent((message => {
|
||||
this.connection.onActionableEvent((message => {
|
||||
const item = this.actionableItems.get(message.itemId);
|
||||
if (item === undefined) {
|
||||
console.warn('Received an event about object "' + message.itemId + '" but cannot find this item on the map.');
|
||||
|
@ -611,7 +602,7 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
/**
|
||||
* Triggered when we receive the JWT token to connect to Jitsi
|
||||
*/
|
||||
connection.onStartJitsiRoom((jwt, room) => {
|
||||
this.connection.onStartJitsiRoom((jwt, room) => {
|
||||
this.startJitsi(room, jwt);
|
||||
});
|
||||
|
||||
|
@ -641,7 +632,17 @@ export class GameScene extends ResizableScene implements CenterListener {
|
|||
this.gameMap.setPosition(event.x, event.y);
|
||||
})
|
||||
|
||||
return connection;
|
||||
//this.initUsersPosition(roomJoinedMessage.users);
|
||||
this.connectionAnswerPromiseResolve(onConnect.room);
|
||||
// Analyze tags to find if we are admin. If yes, show console.
|
||||
if (this.connection.hasTag('admin')) {
|
||||
this.ConsoleGlobalMessageManager = new ConsoleGlobalMessageManager(this.connection, this.userInputManager);
|
||||
}
|
||||
console.log('wakingup');
|
||||
this.scene.wake();
|
||||
this.scene.sleep(ReconnectingSceneName);
|
||||
|
||||
return this.connection;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue