Merge pull request #179 from thecodingmachine/fixeventsfiredtwice
Fixing events fired multiple times
This commit is contained in:
commit
be3bb09f1d
@ -158,6 +158,16 @@ export class Connection implements ConnectionInterface {
|
|||||||
token: this.token
|
token: this.token
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//listen event
|
||||||
|
this.disconnectServer();
|
||||||
|
this.errorMessage();
|
||||||
|
this.groupUpdatedOrCreated();
|
||||||
|
this.groupDeleted();
|
||||||
|
this.onUserJoins();
|
||||||
|
this.onUserMoved();
|
||||||
|
this.onUserLeft();
|
||||||
|
|
||||||
return this.connectSocketServer();
|
return this.connectSocketServer();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -178,15 +188,6 @@ export class Connection implements ConnectionInterface {
|
|||||||
* @param character
|
* @param character
|
||||||
*/
|
*/
|
||||||
connectSocketServer(): Promise<ConnectionInterface>{
|
connectSocketServer(): Promise<ConnectionInterface>{
|
||||||
//listen event
|
|
||||||
this.disconnectServer();
|
|
||||||
this.errorMessage();
|
|
||||||
this.groupUpdatedOrCreated();
|
|
||||||
this.groupDeleted();
|
|
||||||
this.onUserJoins();
|
|
||||||
this.onUserMoved();
|
|
||||||
this.onUserLeft();
|
|
||||||
|
|
||||||
return new Promise<ConnectionInterface>((resolve, reject) => {
|
return new Promise<ConnectionInterface>((resolve, reject) => {
|
||||||
this.getSocket().emit(EventMessage.SET_PLAYER_DETAILS, {
|
this.getSocket().emit(EventMessage.SET_PLAYER_DETAILS, {
|
||||||
name: this.name,
|
name: this.name,
|
||||||
|
@ -188,15 +188,18 @@ export class GameManager {
|
|||||||
private timeoutCallback: NodeJS.Timeout|null = null;
|
private timeoutCallback: NodeJS.Timeout|null = null;
|
||||||
reconnectToGameScene(lastPositionShared: PointInterface) {
|
reconnectToGameScene(lastPositionShared: PointInterface) {
|
||||||
if (this.reconnectScene === null && this.currentGameScene && this.timeoutCallback === null) {
|
if (this.reconnectScene === null && this.currentGameScene && this.timeoutCallback === null) {
|
||||||
|
console.log('Reconnect called without switchToDisconnectedScene called first');
|
||||||
// In case we are asked to reconnect even if switchToDisconnectedScene was not triggered (can happen when a laptop goes to sleep)
|
// In case we are asked to reconnect even if switchToDisconnectedScene was not triggered (can happen when a laptop goes to sleep)
|
||||||
this.switchToDisconnectedScene();
|
this.switchToDisconnectedScene();
|
||||||
// Wait a bit for scene to load. Otherwise, starting ReconnectingSceneName and then starting GameScene one after the other fails for some reason.
|
// Wait a bit for scene to load. Otherwise, starting ReconnectingSceneName and then starting GameScene one after the other fails for some reason.
|
||||||
this.timeoutCallback = setTimeout(() => {
|
this.timeoutCallback = setTimeout(() => {
|
||||||
|
console.log('Reconnecting to game scene from setTimeout');
|
||||||
this.reconnectToGameScene(lastPositionShared);
|
this.reconnectToGameScene(lastPositionShared);
|
||||||
this.timeoutCallback = null;
|
this.timeoutCallback = null;
|
||||||
}, 500);
|
}, 500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log('Reconnecting to game scene');
|
||||||
const game : Phaser.Scene = GameScene.createFromUrl(this.oldMapUrlFile, this.oldInstance);
|
const game : Phaser.Scene = GameScene.createFromUrl(this.oldMapUrlFile, this.oldInstance);
|
||||||
this.reconnectScene?.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared });
|
this.reconnectScene?.scene.add(this.oldSceneKey, game, true, { initPosition: lastPositionShared });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user