import { ClientOptions, Room, RoomOptions, Rooms } from '@ably/chat'; import { jsonRpc, jsonRpcBlocking } from './jsonrpc'; import { RpcRoom } from './RpcRoom'; export class RpcRooms implements Rooms { private readonly _instanceId: string; constructor(instanceId: string) { this._instanceId = instanceId; } get(roomId: string, options: RoomOptions): Room { const { refId } = jsonRpcBlocking.request('Rooms.get', { refId: this._instanceId, args: { roomId, options }, }); return new RpcRoom(refId); } async release(roomId: string): Promise { await jsonRpc.request('Rooms.release', { refId: this._instanceId, args: { roomId, }, }); } get clientOptions(): ClientOptions { // temporary solution: client options are not fully serializable (they contain callback functions), // so they will be missing such parts when returned over RPC. const { response } = jsonRpcBlocking.request('Rooms#clientOptions', { refId: this._instanceId }); return response; } }