add msg when connection is lost
This commit is contained in:
parent
d5e0c89bf6
commit
9f7ac8d111
2 changed files with 18 additions and 2 deletions
|
|
@ -6,10 +6,15 @@ import Protocol from './../common/Protocol.js'
|
||||||
/** @type WsClient */
|
/** @type WsClient */
|
||||||
let conn
|
let conn
|
||||||
let changesCallback = () => {}
|
let changesCallback = () => {}
|
||||||
|
let connectionLostCallback = () => {}
|
||||||
|
|
||||||
|
// TODO: change these to something like on(EVT, cb)
|
||||||
function onServerChange(callback) {
|
function onServerChange(callback) {
|
||||||
changesCallback = callback
|
changesCallback = callback
|
||||||
}
|
}
|
||||||
|
function onConnectionLost(callback) {
|
||||||
|
connectionLostCallback = callback
|
||||||
|
}
|
||||||
|
|
||||||
function send(message) {
|
function send(message) {
|
||||||
conn.send(JSON.stringify(message))
|
conn.send(JSON.stringify(message))
|
||||||
|
|
@ -42,6 +47,9 @@ function connect(address, gameId, clientId) {
|
||||||
throw `[ 2021-05-09 invalid connect msgType ${msgType} ]`
|
throw `[ 2021-05-09 invalid connect msgType ${msgType} ]`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
conn.onclose(() => {
|
||||||
|
connectionLostCallback()
|
||||||
|
})
|
||||||
send([Protocol.EV_CLIENT_INIT])
|
send([Protocol.EV_CLIENT_INIT])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -87,6 +95,7 @@ export default {
|
||||||
connect,
|
connect,
|
||||||
connectReplay,
|
connectReplay,
|
||||||
disconnect,
|
disconnect,
|
||||||
onServerChange,
|
|
||||||
sendClientEvent,
|
sendClientEvent,
|
||||||
|
onServerChange,
|
||||||
|
onConnectionLost,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,15 @@ import Camera from './Camera.js'
|
||||||
import Graphics from './Graphics.js'
|
import Graphics from './Graphics.js'
|
||||||
import Debug from './Debug.js'
|
import Debug from './Debug.js'
|
||||||
import Communication from './Communication.js'
|
import Communication from './Communication.js'
|
||||||
import Util from './../common/Util.js'
|
import Util, { logger } from './../common/Util.js'
|
||||||
import PuzzleGraphics from './PuzzleGraphics.js'
|
import PuzzleGraphics from './PuzzleGraphics.js'
|
||||||
import Game from './../common/GameCommon.js'
|
import Game from './../common/GameCommon.js'
|
||||||
import fireworksController from './Fireworks.js'
|
import fireworksController from './Fireworks.js'
|
||||||
import Protocol from '../common/Protocol.js'
|
import Protocol from '../common/Protocol.js'
|
||||||
import Time from '../common/Time.js'
|
import Time from '../common/Time.js'
|
||||||
|
|
||||||
|
const log = logger('game.js')
|
||||||
|
|
||||||
export const MODE_PLAY = 'play'
|
export const MODE_PLAY = 'play'
|
||||||
export const MODE_REPLAY = 'replay'
|
export const MODE_REPLAY = 'replay'
|
||||||
|
|
||||||
|
|
@ -217,6 +219,11 @@ export async function main(gameId, clientId, wsAddress, MODE, TARGET_EL, HUD) {
|
||||||
gameStartTs: null,
|
gameStartTs: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Communication.onConnectionLost(() => {
|
||||||
|
log('connection lost ... should reload / hit reconnect button / etc.')
|
||||||
|
})
|
||||||
|
|
||||||
let TIME
|
let TIME
|
||||||
if (MODE === MODE_PLAY) {
|
if (MODE === MODE_PLAY) {
|
||||||
const game = await Communication.connect(wsAddress, gameId, clientId)
|
const game = await Communication.connect(wsAddress, gameId, clientId)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue