fix possible lost messages (OOS)
This commit is contained in:
parent
c6f47c9b25
commit
472113ad74
6 changed files with 21 additions and 10 deletions
|
|
@ -16,19 +16,31 @@ const CONN_STATE_CONNECTING = 3 // connecting
|
|||
const CONN_STATE_CLOSED = 4 // not connected (closed on purpose)
|
||||
|
||||
let ws: WebSocket
|
||||
|
||||
let missedMessages: Array<any> = []
|
||||
let changesCallback = (msg: Array<any>) => {
|
||||
// empty
|
||||
}
|
||||
let connectionStateChangeCallback = (state: number) => {
|
||||
// empty
|
||||
missedMessages.push(msg)
|
||||
}
|
||||
|
||||
let missedStateChanges: Array<number> = []
|
||||
let connectionStateChangeCallback = (state: number) => {
|
||||
missedStateChanges.push(state)
|
||||
}
|
||||
|
||||
// TODO: change these to something like on(EVT, cb)
|
||||
function onServerChange(callback: (msg: Array<any>) => void): void {
|
||||
changesCallback = callback
|
||||
for (const missedMessage of missedMessages) {
|
||||
changesCallback(missedMessage)
|
||||
}
|
||||
missedMessages = []
|
||||
}
|
||||
|
||||
function onConnectionStateChange(callback: (state: number) => void): void {
|
||||
connectionStateChangeCallback = callback
|
||||
for (const missedStateChange of missedStateChanges) {
|
||||
connectionStateChangeCallback(missedStateChange)
|
||||
}
|
||||
missedStateChanges = []
|
||||
}
|
||||
|
||||
let connectionState = CONN_STATE_NOT_CONNECTED
|
||||
|
|
@ -48,7 +60,6 @@ function send(message: ClientEvent): void {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
let clientSeq: number
|
||||
let events: Record<number, GameEvent>
|
||||
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ app.post('/api/upload', (req, res) => {
|
|||
})
|
||||
})
|
||||
|
||||
app.post('/newgame', express.json(), async (req, res) => {
|
||||
app.post('/api/newgame', express.json(), async (req, res) => {
|
||||
const gameSettings = req.body as GameSettings
|
||||
log.log(gameSettings)
|
||||
const gameId = Util.uniqId()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue