Skip to content

Commit

Permalink
Add LiveObjectsPool to LiveObjects and naive implementation of `getRo…
Browse files Browse the repository at this point in the history
…ot` method
  • Loading branch information
VeskeR committed Oct 2, 2024
1 parent 1c9f0ff commit 3e95eb1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/moduleReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ async function checkLiveObjectsPluginFiles() {
const allowedFiles = new Set([
'src/plugins/liveobjects/index.ts',
'src/plugins/liveobjects/liveobject.ts',
'src/plugins/liveobjects/liveobjects.ts',
'src/plugins/liveobjects/liveobjectspool.ts',
]);

Expand Down
9 changes: 9 additions & 0 deletions src/plugins/liveobjects/liveobjects.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import type BaseClient from 'common/lib/client/baseclient';
import type RealtimeChannel from 'common/lib/client/realtimechannel';
import { LiveMap } from './livemap';
import { LiveObjectsPool, ROOT_OBJECT_ID } from './liveobjectspool';

export class LiveObjects {
private _client: BaseClient;
private _channel: RealtimeChannel;
private _liveObjectsPool: LiveObjectsPool;

constructor(channel: RealtimeChannel) {
this._channel = channel;
this._client = channel.client;
this._liveObjectsPool = new LiveObjectsPool(this);
}

async getRoot(): Promise<LiveMap> {
// TODO: wait for SYNC sequence to finish to return root
return this._liveObjectsPool.get(ROOT_OBJECT_ID) as LiveMap;
}
}
1 change: 1 addition & 0 deletions test/common/modules/private_api_recorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ define(['test/support/output_directory_paths'], function (outputDirectoryPaths)
'call.http._getHosts',
'call.http.checkConnectivity',
'call.http.doUri',
'call.LiveObject.getObjectId',
'call.msgpack.decode',
'call.msgpack.encode',
'call.presence._myMembers.put',
Expand Down
39 changes: 39 additions & 0 deletions test/realtime/live_objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,45 @@ define(['ably', 'shared_helper', 'async', 'chai', 'live_objects'], function (
const channel = client.channels.get('channel');
expect(channel.liveObjects.constructor.name).to.equal('LiveObjects');
});

describe('LiveObjects instance', () => {
/** @nospec */
it('getRoot() returns LiveMap instance', async function () {
const helper = this.test.helper;
const client = LiveObjectsRealtime(helper);

await monitorConnectionThenCloseAndFinish(
helper,
async () => {
const channel = client.channels.get('channel');
const liveObjects = channel.liveObjects;
const root = await liveObjects.getRoot();

expect(root.constructor.name).to.equal('LiveMap');
},
client,
);
});

/** @nospec */
it('getRoot() returns live object with id "root"', async function () {
const helper = this.test.helper;
const client = LiveObjectsRealtime(helper);

await monitorConnectionThenCloseAndFinish(
helper,
async () => {
const channel = client.channels.get('channel');
const liveObjects = channel.liveObjects;
const root = await liveObjects.getRoot();

helper.recordPrivateApi('call.LiveObject.getObjectId');
expect(root.getObjectId()).to.equal('root');
},
client,
);
});
});
});
});
});

0 comments on commit 3e95eb1

Please sign in to comment.