diff --git a/sync-server/package-lock.json b/sync-server/package-lock.json index 4fcfd18..8220dba 100644 --- a/sync-server/package-lock.json +++ b/sync-server/package-lock.json @@ -1,12 +1,12 @@ { "name": "simple-room", - "version": "3.1.1", + "version": "3.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "simple-room", - "version": "3.1.1", + "version": "3.1.2", "license": "MIT", "dependencies": { "@google-cloud/agones-sdk": "^1.35.0", diff --git a/sync-server/package.json b/sync-server/package.json index 537012d..16c3648 100644 --- a/sync-server/package.json +++ b/sync-server/package.json @@ -1,6 +1,6 @@ { "name": "simple-room", - "version": "3.1.1", + "version": "3.1.2", "description": "", "main": "./lib/index.js", "types": "./lib/index.d.ts", diff --git a/sync-server/src/world.ts b/sync-server/src/world.ts index bef9a21..8db23b7 100644 --- a/sync-server/src/world.ts +++ b/sync-server/src/world.ts @@ -147,7 +147,7 @@ export class WorldClass { for (let [_, room] of this.rooms) { const obj = room.$currentState() if (Object.keys(obj).length == 0) { - return + continue } Transmitter.addPacket(room, obj) for (let id in room.users) { diff --git a/sync-server/tests/room.spec.ts b/sync-server/tests/room.spec.ts index 566ef9a..f26b60e 100644 --- a/sync-server/tests/room.spec.ts +++ b/sync-server/tests/room.spec.ts @@ -2,10 +2,14 @@ import { World } from '../src/world' import { Transmitter } from '../src/transmitter' import MockSocketIo from '../src/testing/mock-socket' import { testSend } from './fixture' -import { beforeEach, test, expect, afterEach } from 'vitest' +import { beforeEach, test, expect, afterEach, vi } from 'vitest' + +let auth = vi.fn() beforeEach(() => { - World.transport(MockSocketIo.serverIo) + World.transport(MockSocketIo.serverIo, { + auth + }) Transmitter.encode = false }) @@ -206,6 +210,49 @@ test('change current state', () => { }) }) +test('World send: All Rooms', async () => { + class Room { + $schema = { + test: String + } + test = 'aa' + } + + const firstPlayerId = 'first' + const secondPlayerId = 'second' + + auth.mockReturnValue(firstPlayerId) + const socket1 = new MockSocketIo.ClientIo(firstPlayerId) + await socket1.connection() + + auth.mockReturnValue(secondPlayerId) + const socket2 = new MockSocketIo.ClientIo(secondPlayerId) + await socket2.connection() + + const room1 = World.addRoom('room1', new Room()) + const room2 = World.addRoom('room2', new Room()) + + const watch = vi.fn() + socket2.on('w', watch) + + //await World.joinRoom('room1', firstPlayerId) + await World.joinRoom('room2', secondPlayerId) + + await World.send() + + room2.test = 'bb' + + await World.send() + + expect(watch).toHaveBeenCalledTimes(3) + expect(watch).toHaveBeenLastCalledWith([ + 'room2', + expect.any(Number), + { test: 'bb' }, + ], undefined) + +}) + afterEach(() => { World.clear() })