{"version":3,"file":"Room.mjs","sources":["../../src/Room.ts"],"sourcesContent":["import { Connection } from './Connection';\nimport { Protocol } from './Protocol';\nimport { getSerializer, Serializer } from './serializer/Serializer';\n\n// The unused imports here are important for better `.d.ts` file generation\n// (Later merged with `dts-bundle-generator`)\nimport { createNanoEvents } from './core/nanoevents';\nimport { createSignal } from './core/signal';\n\nimport { decode, encode, Iterator } from '@colyseus/schema';\nimport { SchemaConstructor, SchemaSerializer } from './serializer/SchemaSerializer';\nimport { CloseCode } from './errors/Errors';\n\nimport { Packr, unpack } from '@colyseus/msgpackr';\n\nexport interface RoomAvailable<Metadata = any> {\n    name: string;\n    roomId: string;\n    clients: number;\n    maxClients: number;\n    metadata?: Metadata;\n}\n\nexport class Room<State= any> {\n    public roomId: string;\n    public sessionId: string;\n    public reconnectionToken: string;\n\n    public name: string;\n    public connection: Connection;\n\n    // Public signals\n    public onStateChange = createSignal<(state: State) => void>();\n    public onError = createSignal<(code: number, message?: string) => void>();\n    public onLeave = createSignal<(code: number, reason?: string) => void>();\n    protected onJoin = createSignal();\n\n    public serializerId: string;\n    public serializer: Serializer<State>;\n\n    protected hasJoined: boolean = false;\n\n    // TODO: remove me on 1.0.0\n    protected rootSchema: SchemaConstructor<State>;\n\n    protected onMessageHandlers = createNanoEvents();\n\n    protected packr: Packr;\n\n    constructor(name: string, rootSchema?: SchemaConstructor<State>) {\n        this.roomId = null;\n        this.name = name;\n\n        this.packr = new Packr();\n\n        // msgpackr workaround: force buffer to be created.\n        this.packr.encode(undefined);\n\n        if (rootSchema) {\n            this.serializer = new (getSerializer(\"schema\"));\n            this.rootSchema = rootSchema;\n            (this.serializer as SchemaSerializer).state = new rootSchema();\n        }\n\n        this.onError((code, message) => console.warn?.(`colyseus.js - onError => (${code}) ${message}`));\n        this.onLeave(() => this.removeAllListeners());\n    }\n\n    public connect(\n        endpoint: string,\n        devModeCloseCallback?: () => void,\n        room: Room = this, // when reconnecting on devMode, re-use previous room intance for handling events.\n        options?: any,\n        headers?: any,\n    ) {\n        const connection = new Connection(options.protocol);\n        room.connection = connection;\n\n        connection.events.onmessage = Room.prototype.onMessageCallback.bind(room);\n        connection.events.onclose = function (e: CloseEvent) {\n            if (!room.hasJoined) {\n                console.warn?.(`Room connection was closed unexpectedly (${e.code}): ${e.reason}`);\n                room.onError.invoke(e.code, e.reason);\n                return;\n            }\n            if (e.code === CloseCode.DEVMODE_RESTART && devModeCloseCallback) {\n                devModeCloseCallback();\n            } else {\n                room.onLeave.invoke(e.code, e.reason);\n                room.destroy();\n            }\n        };\n        connection.events.onerror = function (e: CloseEvent) {\n            console.warn?.(`Room, onError (${e.code}): ${e.reason}`);\n            room.onError.invoke(e.code, e.reason);\n        };\n\n        // FIXME: refactor this.\n        if (options.protocol === \"h3\") {\n            const url = new URL(endpoint);\n            connection.connect(url.origin, options);\n\n        } else {\n            connection.connect(endpoint, headers);\n        }\n\n    }\n\n    public leave(consented: boolean = true): Promise<number> {\n        return new Promise((resolve) => {\n            this.onLeave((code) => resolve(code));\n\n            if (this.connection) {\n                if (consented) {\n                    this.packr.buffer[0] = Protocol.LEAVE_ROOM;\n                    this.connection.send(this.packr.buffer.subarray(0, 1));\n\n                } else {\n                    this.connection.close();\n                }\n\n            } else {\n                this.onLeave.invoke(CloseCode.CONSENTED);\n            }\n        });\n    }\n\n    public onMessage<T = any>(type: \"*\", callback: (type: string | number, message: T) => void)\n    public onMessage<T = any>(type: string | number, callback: (message: T) => void)\n    public onMessage(type: '*' | string | number, callback: (...args: any[]) => void) {\n        return this.onMessageHandlers.on(this.getMessageHandlerKey(type), callback);\n    }\n\n    public send<T = any>(type: string | number, message?: T): void {\n        const it: Iterator = { offset: 1 };\n        this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n        if (typeof(type) === \"string\") {\n            encode.string(this.packr.buffer, type, it);\n\n        } else {\n            encode.number(this.packr.buffer, type, it);\n        }\n\n        // force packr to use beginning of the buffer\n        this.packr.position = 0;\n\n        const data = (message !== undefined)\n            ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n            : this.packr.buffer.subarray(0, it.offset);\n\n        this.connection.send(data);\n    }\n\n    public sendUnreliable<T = any>(type: string | number, message?: T): void {\n        const it: Iterator = { offset: 1 };\n        this.packr.buffer[0] = Protocol.ROOM_DATA;\n\n        if (typeof(type) === \"string\") {\n            encode.string(this.packr.buffer, type, it);\n\n        } else {\n            encode.number(this.packr.buffer, type, it);\n        }\n\n        // force packr to use beginning of the buffer\n        this.packr.position = 0;\n\n        const data = (message !== undefined)\n            ? this.packr.pack(message, 2048 + it.offset) // 2048 = RESERVE_START_SPACE\n            : this.packr.buffer.subarray(0, it.offset);\n\n        this.connection.sendUnreliable(data);\n    }\n\n    public sendBytes(type: string | number, bytes: Uint8Array) {\n        const it: Iterator = { offset: 1 };\n        this.packr.buffer[0] = Protocol.ROOM_DATA_BYTES;\n\n        if (typeof(type) === \"string\") {\n            encode.string(this.packr.buffer, type, it);\n\n        } else {\n            encode.number(this.packr.buffer, type, it);\n        }\n\n        // check if buffer needs to be resized\n        // TODO: can we avoid this?\n        if (bytes.byteLength + it.offset > this.packr.buffer.byteLength) {\n            const newBuffer = new Uint8Array(it.offset + bytes.byteLength);\n            newBuffer.set(this.packr.buffer);\n            this.packr.useBuffer(newBuffer);\n        }\n\n        this.packr.buffer.set(bytes, it.offset);\n        this.connection.send(this.packr.buffer.subarray(0, it.offset + bytes.byteLength));\n    }\n\n    public get state (): State {\n        return this.serializer.getState();\n    }\n\n    public removeAllListeners() {\n        this.onJoin.clear();\n        this.onStateChange.clear();\n        this.onError.clear();\n        this.onLeave.clear();\n        this.onMessageHandlers.events = {};\n\n        if (this.serializer instanceof SchemaSerializer) {\n            // Remove callback references\n            this.serializer.decoder.root.callbacks = {};\n        }\n    }\n\n    protected onMessageCallback(event: MessageEvent) {\n        const buffer = new Uint8Array(event.data);\n\n        const it: Iterator = { offset: 1 };\n        const code = buffer[0];\n\n        if (code === Protocol.JOIN_ROOM) {\n            const reconnectionToken = decode.utf8Read(buffer, it, buffer[it.offset++]);\n            this.serializerId = decode.utf8Read(buffer, it, buffer[it.offset++]);\n\n            // Instantiate serializer if not locally available.\n            if (!this.serializer) {\n                const serializer = getSerializer(this.serializerId);\n                this.serializer = new serializer();\n            }\n\n            if (buffer.byteLength > it.offset && this.serializer.handshake) {\n                this.serializer.handshake(buffer, it);\n            }\n\n            this.reconnectionToken = `${this.roomId}:${reconnectionToken}`;\n\n            this.hasJoined = true;\n            this.onJoin.invoke();\n\n            // acknowledge successfull JOIN_ROOM\n            this.packr.buffer[0] = Protocol.JOIN_ROOM;\n            this.connection.send(this.packr.buffer.subarray(0, 1));\n\n        } else if (code === Protocol.ERROR) {\n            const code = decode.number(buffer, it);\n            const message = decode.string(buffer, it);\n\n            this.onError.invoke(code, message);\n\n        } else if (code === Protocol.LEAVE_ROOM) {\n            this.leave();\n\n        } else if (code === Protocol.ROOM_STATE) {\n            this.serializer.setState(buffer, it);\n            this.onStateChange.invoke(this.serializer.getState());\n\n        } else if (code === Protocol.ROOM_STATE_PATCH) {\n            this.serializer.patch(buffer, it);\n            this.onStateChange.invoke(this.serializer.getState());\n\n        } else if (code === Protocol.ROOM_DATA) {\n            const type = (decode.stringCheck(buffer, it))\n                ? decode.string(buffer, it)\n                : decode.number(buffer, it);\n\n            const message = (buffer.byteLength > it.offset)\n                ? unpack(buffer, { start: it.offset })\n                : undefined;\n\n            this.dispatchMessage(type, message);\n\n        } else if (code === Protocol.ROOM_DATA_BYTES) {\n            const type = (decode.stringCheck(buffer, it))\n                ? decode.string(buffer, it)\n                : decode.number(buffer, it);\n\n            this.dispatchMessage(type, buffer.subarray(it.offset));\n        }\n    }\n\n    private dispatchMessage(type: string | number, message: any) {\n        const messageType = this.getMessageHandlerKey(type);\n\n        if (this.onMessageHandlers.events[messageType]) {\n            this.onMessageHandlers.emit(messageType, message);\n\n        } else if (this.onMessageHandlers.events['*']) {\n            this.onMessageHandlers.emit('*', type, message);\n\n        } else {\n            console.warn?.(`colyseus.js: onMessage() not registered for type '${type}'.`);\n        }\n    }\n\n    private destroy () {\n        if (this.serializer) {\n            this.serializer.teardown();\n        }\n    }\n\n    private getMessageHandlerKey(type: string | number): string {\n        switch (typeof(type)) {\n            // string\n            case \"string\": return type;\n\n            // number\n            case \"number\": return `i${type}`;\n\n            default: throw new Error(\"invalid message type.\");\n        }\n    }\n\n}\n"],"names":[],"mappings":";;;;;;;;;;;MAuBa,IAAI,CAAA;AACN,IAAA,MAAM;AACN,IAAA,SAAS;AACT,IAAA,iBAAiB;AAEjB,IAAA,IAAI;AACJ,IAAA,UAAU;;IAGV,aAAa,GAAG,YAAY,EAA0B;IACtD,OAAO,GAAG,YAAY,EAA4C;IAClE,OAAO,GAAG,YAAY,EAA2C;IAC9D,MAAM,GAAG,YAAY,EAAE;AAE1B,IAAA,YAAY;AACZ,IAAA,UAAU;IAEP,SAAS,GAAY,KAAK;;AAG1B,IAAA,UAAU;IAEV,iBAAiB,GAAG,gBAAgB,EAAE;AAEtC,IAAA,KAAK;IAEf,WAAY,CAAA,IAAY,EAAE,UAAqC,EAAA;AAC3D,QAAA,IAAI,CAAC,MAAM,GAAG,IAAI;AAClB,QAAA,IAAI,CAAC,IAAI,GAAG,IAAI;AAEhB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE;;AAGxB,QAAA,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC;QAE5B,IAAI,UAAU,EAAE;YACZ,IAAI,CAAC,UAAU,GAAG,KAAK,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC/C,YAAA,IAAI,CAAC,UAAU,GAAG,UAAU;YAC3B,IAAI,CAAC,UAA+B,CAAC,KAAK,GAAG,IAAI,UAAU,EAAE;;QAGlE,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,GAAG,CAA6B,0BAAA,EAAA,IAAI,KAAK,OAAO,CAAA,CAAE,CAAC,CAAC;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