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 => {
|
||||||
this.users[uid].userJoined(connector.userId, connector.role)
|
let user = this.users[uid]
|
||||||
connector.userJoined(uid, this.users[uid].role)
|
if (user.role === 'master') {
|
||||||
|
this.users[uid].userJoined(connector.userId, connector.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,13 +132,14 @@ 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)
|
||||||
for (let j = 0; j < messages.length; j++) {
|
for (let j = 0; j < messages.length; j++) {
|
||||||
let p = super.receiveMessage(userId, messages[j])
|
let p = super.receiveMessage(userId, messages[j])
|
||||||
finished.push(p)
|
finished.push(p)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user