Skip to content

Commit

Permalink
Rename RoomOptionsDefault -> DefaultRoomOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvelici committed Feb 5, 2025
1 parent 372c217 commit ed6ff19
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 102 deletions.
4 changes: 2 additions & 2 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, useEffect, useState } from 'react';
import { Chat } from './containers/Chat';
import { OccupancyComponent } from './components/OccupancyComponent';
import { UserPresenceComponent } from './components/UserPresenceComponent';
import { RoomOptionsDefaults, ChatRoomProvider } from '@ably/chat';
import { DefaultRoomOptions, ChatRoomProvider } from '@ably/chat';

// We read the roomID from the URL query string and default to 'abcd' if none
// provided. We make sure the URL is updated to always include the roomId. This
Expand Down Expand Up @@ -52,7 +52,7 @@ const App: FC<AppProps> = () => {
id={roomIdState}
release={true}
attach={true}
options={RoomOptionsDefaults}
options={DefaultRoomOptions}
>
<div
style={{ display: 'flex', justifyContent: 'space-between', width: '800px', margin: 'auto', height: '650px' }}
Expand Down
2 changes: 1 addition & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export type {
RoomReactionsOptions,
TypingOptions,
} from './room-options.js';
export { RoomOptionsDefaults } from './room-options.js';
export { DefaultRoomOptions } from './room-options.js';
export type {
RoomReactionListener,
RoomReactions,
Expand Down
10 changes: 5 additions & 5 deletions src/core/room-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as Ably from 'ably';
/**
* Represents the default options for a chat room.
*/
export const RoomOptionsDefaults = {
export const DefaultRoomOptions = {
/**
* The default presence options for a chat room.
*/
Expand Down Expand Up @@ -89,26 +89,26 @@ export type OccupancyOptions = object;
export interface RoomOptions {
/**
* The presence options for the room. To enable presence in the room, set this property. You may
* use {@link RoomOptionsDefaults.presence} to enable presence with default options.
* use {@link DefaultRoomOptions.presence} to enable presence with default options.
* @defaultValue undefined
*/
presence?: PresenceOptions;

/**
* The typing options for the room. To enable typing in the room, set this property. You may use
* {@link RoomOptionsDefaults.typing} to enable typing with default options.
* {@link DefaultRoomOptions.typing} to enable typing with default options.
*/
typing?: TypingOptions;

/**
* The reactions options for the room. To enable reactions in the room, set this property. You may use
* {@link RoomOptionsDefaults.reactions} to enable reactions with default options.
* {@link DefaultRoomOptions.reactions} to enable reactions with default options.
*/
reactions?: RoomReactionsOptions;

/**
* The occupancy options for the room. To enable occupancy in the room, set this property. You may use
* {@link RoomOptionsDefaults.occupancy} to enable occupancy with default options.
* {@link DefaultRoomOptions.occupancy} to enable occupancy with default options.
*/
occupancy?: OccupancyOptions;
}
Expand Down
10 changes: 5 additions & 5 deletions src/react/providers/chat-room-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatClient } from '../../core/chat.js';
import { Logger } from '../../core/logger.js';
import { Room } from '../../core/room.js';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { RoomOptions, type RoomOptionsDefaults } from '../../core/room-options.js';
import { type DefaultRoomOptions, RoomOptions } from '../../core/room-options.js';
import { ChatRoomContext, ChatRoomContextType } from '../contexts/chat-room-context.js';
import { useChatClient } from '../hooks/use-chat-client.js';
import { useLogger } from '../hooks/use-logger.js';
Expand All @@ -19,15 +19,15 @@ export interface ChatRoomProviderProps {

/**
* The options to use when creating the room. A convenient default value is
* provided by {@link RoomOptionsDefaults}, but it must explicitly be set
* provided by {@link DefaultRoomOptions}, but it must explicitly be set
* here.
*
* {@link RoomOptionsDefaults} can also be used partially, for example:
* {@link DefaultRoomOptions} can also be used partially, for example:
*
* ```tsx
* <ChatRoomProvider id="room-id" options={{
* presence: RoomOptionsDefaults.presence,
* reactions: RoomOptionsDefaults.reactions,
* presence: DefaultRoomOptions.presence,
* reactions: DefaultRoomOptions.reactions,
* }} />
* ```
*
Expand Down
4 changes: 2 additions & 2 deletions test/core/messages.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ChatMessageActions, MessageEvents } from '../../src/core/events.ts';
import { Message } from '../../src/core/message.ts';
import { OrderBy } from '../../src/core/messages.ts';
import { RealtimeChannelWithOptions } from '../../src/core/realtime-extensions.ts';
import { RoomOptionsDefaults } from '../../src/core/room-options.ts';
import { DefaultRoomOptions } from '../../src/core/room-options.ts';
import { RoomStatus } from '../../src/core/room-status.ts';
import { CHANNEL_OPTIONS_AGENT_STRING } from '../../src/core/version.ts';
import { newChatClient } from '../helper/chat.ts';
Expand Down Expand Up @@ -781,7 +781,7 @@ describe('messages integration', { timeout: 10000 }, () => {
it<TestContext>('handles the room being released before getPreviousMessages is called', async (context) => {
const chat = context.chat;
const roomId = randomRoomId();
const room = await chat.rooms.get(roomId, RoomOptionsDefaults);
const room = await chat.rooms.get(roomId, DefaultRoomOptions);

// Create a subscription to messages
room.messages.subscribe(() => {});
Expand Down
4 changes: 2 additions & 2 deletions test/core/presence.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ChatClient } from '../../src/core/chat.ts';
import { PresenceEvents } from '../../src/core/events.ts';
import { PresenceData, PresenceEvent } from '../../src/core/presence.ts';
import { Room } from '../../src/core/room.ts';
import { RoomOptionsDefaults } from '../../src/core/room-options.ts';
import { DefaultRoomOptions } from '../../src/core/room-options.ts';
import { RoomStatus } from '../../src/core/room-status.ts';
import { newChatClient } from '../helper/chat.ts';
import { randomRoomId } from '../helper/identifier.ts';
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('UserPresence', { timeout: 10000 }, () => {
const roomId = randomRoomId();
context.chat = newChatClient(undefined, context.realtime);
context.defaultTestClientId = context.realtime.auth.clientId;
context.chatRoom = await context.chat.rooms.get(roomId, { presence: RoomOptionsDefaults.presence });
context.chatRoom = await context.chat.rooms.get(roomId, { presence: DefaultRoomOptions.presence });
});

// Test for successful entering with clientId and custom user data
Expand Down
12 changes: 6 additions & 6 deletions test/core/room.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ChatApi } from '../../src/core/chat-api.ts';
import { randomId } from '../../src/core/id.ts';
import { DefaultRoom, Room } from '../../src/core/room.ts';
import { RoomLifecycleManager } from '../../src/core/room-lifecycle-manager.ts';
import { RoomOptions, RoomOptionsDefaults } from '../../src/core/room-options.ts';
import { DefaultRoomOptions, RoomOptions } from '../../src/core/room-options.ts';
import { RoomStatus } from '../../src/core/room-status.ts';
import { DefaultTyping } from '../../src/core/typing.ts';
import { CHANNEL_OPTIONS_AGENT_STRING, DEFAULT_CHANNEL_OPTIONS } from '../../src/core/version.ts';
Expand Down Expand Up @@ -44,10 +44,10 @@ describe('Room', () => {

describe.each([
['messages', {}, (room: Room) => room.messages],
['presence', { presence: RoomOptionsDefaults.presence }, (room: Room) => room.presence],
['occupancy', { occupancy: RoomOptionsDefaults.occupancy }, (room: Room) => room.occupancy],
['typing', { typing: RoomOptionsDefaults.typing }, (room: Room) => room.typing],
['reactions', { reactions: RoomOptionsDefaults.reactions }, (room: Room) => room.reactions],
['presence', { presence: DefaultRoomOptions.presence }, (room: Room) => room.presence],
['occupancy', { occupancy: DefaultRoomOptions.occupancy }, (room: Room) => room.occupancy],
['typing', { typing: DefaultRoomOptions.typing }, (room: Room) => room.typing],
['reactions', { reactions: DefaultRoomOptions.reactions }, (room: Room) => room.reactions],
])('feature configured', (description: string, options: RoomOptions, featureLoader: (room: Room) => unknown) => {
it<TestContext>(`should not throw an error when trying to access ${description} whilst enabled`, (context) => {
const room = context.getRoom(options);
Expand Down Expand Up @@ -251,7 +251,7 @@ describe('Room', () => {
});

it<TestContext>('should only release with enabled features', async (context) => {
const room = context.getRoom({ typing: RoomOptionsDefaults.typing }) as DefaultRoom;
const room = context.getRoom({ typing: DefaultRoomOptions.typing }) as DefaultRoom;
const lifecycleManager = (room as unknown as { _lifecycleManager: RoomLifecycleManager })._lifecycleManager;

// Setup spies on the realtime client and the room lifecycle manager
Expand Down
8 changes: 4 additions & 4 deletions test/core/rooms.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';

import { LogLevel } from '../../src/core/logger.ts';
import { RoomStatus } from '../../src/core/room-status.ts';
import { RoomOptionsDefaults } from '../../src/index.ts';
import { DefaultRoomOptions } from '../../src/index.ts';
import { newChatClient } from '../helper/chat.ts';
import { waitForRoomStatus } from '../helper/room.ts';

Expand Down Expand Up @@ -36,15 +36,15 @@ describe('Rooms', () => {
// We include presence options here because that invokes a change to channel modes - which would flag up
// an error if we were doing releases in the wrong order etc
const chat = newChatClient();
const room1 = await chat.rooms.get('test', { typing: { timeoutMs: 1000 }, presence: RoomOptionsDefaults.presence });
const room1 = await chat.rooms.get('test', { typing: { timeoutMs: 1000 }, presence: DefaultRoomOptions.presence });
await room1.attach();
await chat.rooms.release('test');

const room2 = await chat.rooms.get('test', { typing: { timeoutMs: 2000 }, presence: RoomOptionsDefaults.presence });
const room2 = await chat.rooms.get('test', { typing: { timeoutMs: 2000 }, presence: DefaultRoomOptions.presence });
await room2.attach();
await chat.rooms.release('test');

await chat.rooms.get('test', { typing: { timeoutMs: 3000 }, presence: RoomOptionsDefaults.presence });
await chat.rooms.get('test', { typing: { timeoutMs: 3000 }, presence: DefaultRoomOptions.presence });
await chat.rooms.release('test');
});

Expand Down
4 changes: 2 additions & 2 deletions test/core/typing.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { beforeEach, describe, expect, it } from 'vitest';

import { normalizeClientOptions } from '../../src/core/config.ts';
import { Room } from '../../src/core/room.ts';
import { RoomOptionsDefaults } from '../../src/core/room-options.ts';
import { DefaultRoomOptions } from '../../src/core/room-options.ts';
import { RoomStatus } from '../../src/core/room-status.ts';
import { DefaultRooms, Rooms } from '../../src/core/rooms.ts';
import { TypingEvent } from '../../src/core/typing.ts';
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('Typing', () => {
it<TestContext>('handles discontinuities', async (context) => {
const { chat } = context;

const room = await chat.get(randomRoomId(), { typing: RoomOptionsDefaults.typing });
const room = await chat.get(randomRoomId(), { typing: DefaultRoomOptions.typing });

// Attach the room
await room.attach();
Expand Down
4 changes: 2 additions & 2 deletions test/helper/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ChatApi } from '../../src/core/chat-api.ts';
import { ErrorCodes } from '../../src/core/errors.ts';
import { randomId } from '../../src/core/id.ts';
import { DefaultRoom, Room } from '../../src/core/room.ts';
import { RoomOptions, RoomOptionsDefaults } from '../../src/core/room-options.ts';
import { DefaultRoomOptions, RoomOptions } from '../../src/core/room-options.ts';
import { RoomLifecycle, RoomStatus } from '../../src/core/room-status.ts';
import { randomRoomId } from './identifier.ts';
import { makeTestLogger } from './logger.ts';
Expand All @@ -32,7 +32,7 @@ export const getRandomRoom = async (chat: ChatClient): Promise<Room> =>

// Return a default set of room options
export const defaultRoomOptions: RoomOptions = {
...RoomOptionsDefaults,
...DefaultRoomOptions,
};

// Makes a room with the given (or default) options, as a standalone room aside from the chat client
Expand Down
8 changes: 4 additions & 4 deletions test/react/helper/use-eventual-room.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { Logger } from '../../../src/core/logger.ts';
import { Room } from '../../../src/core/room.ts';
import { RoomOptionsDefaults } from '../../../src/core/room-options.ts';
import { DefaultRoomOptions } from '../../../src/core/room-options.ts';
import { useEventualRoom, useEventualRoomProperty } from '../../../src/react/helper/use-eventual-room.ts';
import { makeTestLogger } from '../../helper/logger.ts';
import { makeRandomRoom } from '../../helper/room.ts';
Expand All @@ -30,7 +30,7 @@ const updateMockRoom = (newRoom: Room) => {
describe('eventual rooms', () => {
beforeEach(() => {
mockLogger = makeTestLogger();
updateMockRoom(makeRandomRoom({ options: RoomOptionsDefaults }));
updateMockRoom(makeRandomRoom({ options: DefaultRoomOptions }));
});

afterEach(() => {
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('eventual rooms', () => {
});

// Now update the room and re-render
const newRoom = makeRandomRoom({ options: RoomOptionsDefaults });
const newRoom = makeRandomRoom({ options: DefaultRoomOptions });
updateMockRoom(newRoom);

rerender();
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('eventual rooms', () => {
});

// Now update the room and re-render
const newRoom = makeRandomRoom({ options: RoomOptionsDefaults });
const newRoom = makeRandomRoom({ options: DefaultRoomOptions });
updateMockRoom(newRoom);

rerender();
Expand Down
6 changes: 3 additions & 3 deletions test/react/helper/use-room-context.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cleanup, render } from '@testing-library/react';
import { afterEach, describe, expect, it } from 'vitest';

import { RoomOptionsDefaults } from '../../../src/core/room-options.ts';
import { DefaultRoomOptions } from '../../../src/core/room-options.ts';
import { useRoomContext } from '../../../src/react/helper/use-room-context.ts';
import { ChatRoomProvider } from '../../../src/react/index.ts';
import { ChatClientProvider } from '../../../src/react/providers/chat-client-provider.tsx';
Expand Down Expand Up @@ -39,15 +39,15 @@ describe('useRoom', () => {
const context = useRoomContext('foo');
expect(context).toBeDefined();
expect(context.roomId).toBe('foo');
expect(context.options).toBe(RoomOptionsDefaults);
expect(context.options).toBe(DefaultRoomOptions);
return null;
};

const TestProvider = () => (
<ChatClientProvider client={chatClient}>
<ChatRoomProvider
id="foo"
options={RoomOptionsDefaults}
options={DefaultRoomOptions}
>
<TestUseRoom />
</ChatRoomProvider>
Expand Down
4 changes: 2 additions & 2 deletions test/react/helper/use-room-status.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { Logger } from '../../../src/core/logger.ts';
import { Room } from '../../../src/core/room.ts';
import { RoomOptionsDefaults } from '../../../src/core/room-options.ts';
import { DefaultRoomOptions } from '../../../src/core/room-options.ts';
import { InternalRoomLifecycle, RoomStatus, RoomStatusChange } from '../../../src/core/room-status.ts';
import { useRoomStatus } from '../../../src/react/helper/use-room-status.ts';
import { makeTestLogger } from '../../helper/logger.ts';
Expand Down Expand Up @@ -33,7 +33,7 @@ const updateMockRoom = (newRoom: Room) => {
describe('useRoomStatus', () => {
beforeEach(() => {
mockLogger = makeTestLogger();
updateMockRoom(makeRandomRoom({ options: RoomOptionsDefaults }));
updateMockRoom(makeRandomRoom({ options: DefaultRoomOptions }));
});

afterEach(() => {
Expand Down
Loading

0 comments on commit ed6ff19

Please sign in to comment.