Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add agent param #220

Merged
merged 3 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ describe('Space', () => {
const channelSpy = vi.spyOn(channels, 'get');
const space = new Space('test', client);

expect(channelSpy).toHaveBeenNthCalledWith(1, 'test-space');
expect(channelSpy).toHaveBeenNthCalledWith(
1,
'test-space',
expect.objectContaining({
params: expect.objectContaining({
agent: expect.stringContaining('spaces'),
}),
}),
);
expectTypeOf(space).toMatchTypeOf<Space>();
});
});
Expand Down
4 changes: 3 additions & 1 deletion src/Space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { isFunction, isObject } from './utilities/is.js';
import type { SpaceOptions, SpaceMember, ProfileData } from './types.js';
import type { Subset, PresenceMember } from './utilities/types.js';

import { VERSION } from './version.js';

// Replace by ::$space when that channel tag will be available
const SPACE_CHANNEL_TAG = '-space';

Expand Down Expand Up @@ -68,7 +70,7 @@ class Space extends EventEmitter<SpaceEventMap> {
this.name = name;
this.channelName = `${name}${SPACE_CHANNEL_TAG}`;

this.channel = this.client.channels.get(this.channelName);
this.channel = this.client.channels.get(this.channelName, { params: { agent: `spaces/${VERSION}` } });
this.onPresenceUpdate = this.onPresenceUpdate.bind(this);
this.channel.presence.subscribe(this.onPresenceUpdate);

Expand Down
10 changes: 9 additions & 1 deletion src/Spaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ describe('Spaces', () => {
await spaces.get('test');

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith('test-space');
expect(spy).toHaveBeenNthCalledWith(
1,
'test-space',
expect.objectContaining({
params: expect.objectContaining({
agent: expect.stringContaining('spaces'),
}),
}),
);
});

it<SpacesTestContext>('applies the agent header to an existing SDK instance', ({ client }) => {
Expand Down
4 changes: 3 additions & 1 deletion src/Spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Space from './Space.js';
import type { SpaceOptions } from './types.js';
import type { Subset } from './utilities/types.js';

import { VERSION } from './version.js';

export interface ClientWithOptions extends Types.RealtimePromise {
options: {
agents?: Record<string, string | boolean>;
Expand All @@ -17,7 +19,7 @@ class Spaces {
client: Types.RealtimePromise;
connection: Types.ConnectionPromise;

readonly version = '0.1.3';
readonly version = VERSION;

constructor(client: Types.RealtimePromise) {
this.client = client;
Expand Down
10 changes: 10 additions & 0 deletions src/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, it, expect } from 'vitest';

import { VERSION } from './version.js';
import packageJson from '../package.json';

describe('VERSION', () => {
it('runtime version matches package.json entry', () => {
expect(packageJson.version).toEqual(VERSION);
});
});
3 changes: 3 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Manually update when bumping version
const VERSION = '0.1.3';
export { VERSION };
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": ["./src/**/*.ts"],
"exclude": ["./src/**/*.test.tsx", "./src/fakes/**/*.ts"],
"exclude": ["./src/**/*.test.tsx", "./src/**/*.test.ts", "./src/fakes/**/*.ts"],
"compilerOptions": {
"target": "es6",
"rootDir": "./src",
Expand Down
Loading