implemented client-server model (untested)
This commit is contained in:
parent
c8bca15d72
commit
bbf5e39408
@ -14,8 +14,11 @@ export class TestRoom {
|
|||||||
connector.setUserId('' + (this.nextUserId++))
|
connector.setUserId('' + (this.nextUserId++))
|
||||||
}
|
}
|
||||||
Object.keys(this.users).forEach(uid => {
|
Object.keys(this.users).forEach(uid => {
|
||||||
|
let user = this.users[uid]
|
||||||
|
if (user.role === 'master') {
|
||||||
this.users[uid].userJoined(connector.userId, connector.role)
|
this.users[uid].userJoined(connector.userId, connector.role)
|
||||||
connector.userJoined(uid, this.users[uid].role)
|
connector.userJoined(uid, this.users[uid].role)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
this.users[connector.userId] = connector
|
this.users[connector.userId] = connector
|
||||||
}
|
}
|
||||||
@ -73,6 +76,7 @@ export default function extendTestConnector (Y) {
|
|||||||
this.chance = options.chance
|
this.chance = options.chance
|
||||||
this.testRoom = getTestRoom(this.room)
|
this.testRoom = getTestRoom(this.room)
|
||||||
this.testRoom.join(this)
|
this.testRoom.join(this)
|
||||||
|
this.forwardAppliedOperations = this.role === 'master'
|
||||||
}
|
}
|
||||||
disconnect () {
|
disconnect () {
|
||||||
this.testRoom.leave(this)
|
this.testRoom.leave(this)
|
||||||
@ -128,7 +132,7 @@ export default function extendTestConnector (Y) {
|
|||||||
var finished = []
|
var finished = []
|
||||||
for (let i = 0; i < flushUsers.length; i++) {
|
for (let i = 0; i < flushUsers.length; i++) {
|
||||||
let userId = flushUsers[i].connector.userId
|
let userId = flushUsers[i].connector.userId
|
||||||
if (userId === this.userId) continue
|
if (userId !== this.userId && this.connections[userId] != null) {
|
||||||
let buffer = this.connections[userId].buffer
|
let buffer = this.connections[userId].buffer
|
||||||
if (buffer != null) {
|
if (buffer != null) {
|
||||||
var messages = buffer.splice(0)
|
var messages = buffer.splice(0)
|
||||||
@ -138,6 +142,7 @@ export default function extendTestConnector (Y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await Promise.all(finished)
|
await Promise.all(finished)
|
||||||
await this.y.db.whenTransactionsFinished()
|
await this.y.db.whenTransactionsFinished()
|
||||||
return finished.length > 0 ? 'flushing' : 'done'
|
return finished.length > 0 ? 'flushing' : 'done'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user