Skip to content

Commit

Permalink
Rename RealtimePresence module to RealtimePresenceModule
Browse files Browse the repository at this point in the history
To avoid a clash with the Types.RealtimePresence class (which describes
the realtime presence API) when we remove the Types namespace in #909.

This is ugly; it’s not consistent with the other modules, which don’t
have "Module" in their name. I’d welcome suggestions of alternative
things I could do here.
  • Loading branch information
lawrence-forooghian committed Nov 30, 2023
1 parent d246033 commit 384c6c9
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ Aimed at those who are concerned about their app’s bundle size, the modular va
The modular variant of the library provides:

- a `BaseRealtime` class;
- various modules that add functionality to a `BaseRealtime` instance, such as `Rest`, `RealtimePresence`, etc.
- various modules that add functionality to a `BaseRealtime` instance, such as `Rest`, `RealtimePresenceModule`, etc.

To use this variant of the library, import the `BaseRealtime` class from `ably/modules`, along with the modules that you wish to use. Then, pass these modules to the `BaseRealtime` constructor as shown in the example below:

```javascript
import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresence } from 'ably/modules';
import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresenceModule } from 'ably/modules';

const options = { key: 'YOUR_ABLY_API_KEY' /* Replace with a real key from the Ably dashboard */ };
const client = new BaseRealtime(options, {
WebSocketTransport,
FetchRequest,
RealtimePresence
RealtimePresenceModule
});
```

Expand Down
10 changes: 5 additions & 5 deletions modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ export declare const MsgPack: unknown;
* To create a client that includes this module, include it in the `ModulesMap` that you pass to the {@link BaseRealtime.constructor}:
*
* ```javascript
* import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresence } from 'ably/modules';
* const realtime = new BaseRealtime(options, { WebSocketTransport, FetchRequest, RealtimePresence });
* import { BaseRealtime, WebSocketTransport, FetchRequest, RealtimePresenceModule } from 'ably/modules';
* const realtime = new BaseRealtime(options, { WebSocketTransport, FetchRequest, RealtimePresenceModule });
* ```
*
* If you do not provide this module, then attempting to access a channel’s {@link Types.RealtimeChannel.presence} property will cause a runtime error.
*/
export declare const RealtimePresence: unknown;
export declare const RealtimePresenceModule: unknown;

/**
* Provides a {@link BaseRealtime} instance with the ability to establish a connection with the Ably realtime service using a [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) connection.
Expand Down Expand Up @@ -197,9 +197,9 @@ export interface ModulesMap {
MsgPack?: typeof MsgPack;

/**
* See {@link RealtimePresence | documentation for the `RealtimePresence` module}.
* See {@link RealtimePresenceModule | documentation for the `RealtimePresenceModule` module}.
*/
RealtimePresence?: typeof RealtimePresence;
RealtimePresenceModule?: typeof RealtimePresenceModule;

/**
* See {@link WebSocketTransport | documentation for the `WebSocketTransport` module}.
Expand Down
2 changes: 1 addition & 1 deletion src/common/lib/client/baserealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BaseRealtime extends BaseClient {
super(options, modules);
Logger.logAction(Logger.LOG_MINOR, 'Realtime()', '');
this._additionalTransportImplementations = BaseRealtime.transportImplementationsFromModules(modules);
this._RealtimePresence = modules.RealtimePresence ?? null;
this._RealtimePresence = modules.RealtimePresenceModule ?? null;
this._decodeVcdiff = (modules.Vcdiff ?? (Platform.Vcdiff.supported && Platform.Vcdiff.bundledDecode)) || null;
this.connection = new Connection(this, this.options);
this._channels = new Channels(this);
Expand Down
2 changes: 1 addition & 1 deletion src/common/lib/client/defaultrealtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DefaultRealtime extends BaseRealtime {
...allCommonModules,
Crypto: DefaultRealtime.Crypto ?? undefined,
MsgPack,
RealtimePresence: {
RealtimePresenceModule: {
RealtimePresence,
presenceMessageFromValues,
presenceMessagesFromValuesArray,
Expand Down
2 changes: 1 addition & 1 deletion src/common/lib/client/modulesmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface ModulesMap {
Rest?: typeof Rest;
Crypto?: IUntypedCryptoStatic;
MsgPack?: MsgPack;
RealtimePresence?: RealtimePresenceModule;
RealtimePresenceModule?: RealtimePresenceModule;
WebSocketTransport?: TransportInitialiser;
XHRPolling?: TransportInitialiser;
XHRStreaming?: TransportInitialiser;
Expand Down
2 changes: 1 addition & 1 deletion src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class RealtimeChannel extends EventEmitter {
private _presence: RealtimePresence | null;
get presence(): RealtimePresence {
if (!this._presence) {
Utils.throwMissingModuleError('RealtimePresence');
Utils.throwMissingModuleError('RealtimePresenceModule');
}
return this._presence;
}
Expand Down
2 changes: 1 addition & 1 deletion src/platform/web/modules/realtimepresence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const RealtimePresence: RealtimePresenceModule = {
presenceMessagesFromValuesArray,
};

export { RealtimePresence };
export { RealtimePresence as RealtimePresenceModule };
18 changes: 9 additions & 9 deletions test/browser/modules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
decodeEncryptedMessages,
Crypto,
MsgPack,
RealtimePresence,
RealtimePresenceModule,
decodePresenceMessage,
decodePresenceMessages,
constructPresenceMessage,
Expand Down Expand Up @@ -86,7 +86,7 @@ function registerAblyModulesTests(helper, registerDeltaTests) {
},
{
description: 'call channel’s `presence.history()`',
additionalRealtimeModules: { RealtimePresence },
additionalRealtimeModules: { RealtimePresenceModule },
action: (client) => client.channels.get('channel').presence.history(),
},
{
Expand Down Expand Up @@ -452,13 +452,13 @@ function registerAblyModulesTests(helper, registerDeltaTests) {
});
});

describe('RealtimePresence', () => {
describe('BaseRealtime without RealtimePresence', () => {
describe('RealtimePresenceModule', () => {
describe('BaseRealtime without RealtimePresenceModule', () => {
it('throws an error when attempting to access the `presence` property', () => {
const client = new BaseRealtime(ablyClientOptions(), { WebSocketTransport, FetchRequest });
const channel = client.channels.get('channel');

expect(() => channel.presence).to.throw('RealtimePresence module not provided');
expect(() => channel.presence).to.throw('RealtimePresenceModule module not provided');
});

it('doesn’t break when it receives a PRESENCE ProtocolMessage', async () => {
Expand All @@ -472,7 +472,7 @@ function registerAblyModulesTests(helper, registerDeltaTests) {
const txClient = new BaseRealtime(ablyClientOptions({ clientId: randomString() }), {
WebSocketTransport,
FetchRequest,
RealtimePresence,
RealtimePresenceModule,
});
const txChannel = txClient.channels.get('channel');

Expand All @@ -485,18 +485,18 @@ function registerAblyModulesTests(helper, registerDeltaTests) {
});
});

describe('BaseRealtime with RealtimePresence', () => {
describe('BaseRealtime with RealtimePresenceModule', () => {
it('offers realtime presence functionality', async () => {
const rxChannel = new BaseRealtime(ablyClientOptions(), {
WebSocketTransport,
FetchRequest,
RealtimePresence,
RealtimePresenceModule,
}).channels.get('channel');
const txClientId = randomString();
const txChannel = new BaseRealtime(ablyClientOptions({ clientId: txClientId }), {
WebSocketTransport,
FetchRequest,
RealtimePresence,
RealtimePresenceModule,
}).channels.get('channel');

let resolveRxPresenceMessagePromise;
Expand Down

0 comments on commit 384c6c9

Please sign in to comment.