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

adding a getter and types for AuthBundle #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions rtvi-client-js/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface RTVIClientOptions {
params: RTVIClientParams,
timeout: ReturnType<typeof setTimeout> | undefined,
abortController: AbortController
) => Promise<void>;
) => Promise<AuthBundle>;

// ----- @deprecated options

Expand Down Expand Up @@ -141,6 +141,11 @@ export interface RTVIClientOptions {
customBodyParams?: object;
}

export type AuthBundle = {
room_url: string;
token: string;
};

export type RTVIEventCallbacks = Partial<{
onGenericMessage: (data: unknown) => void;
onMessageError: (message: RTVIMessage) => void;
Expand Down Expand Up @@ -199,6 +204,7 @@ export class RTVIClient extends RTVIEventEmitter {
private _helpers: RTVIClientHelpers;
private _startResolve: ((value: unknown) => void) | undefined;
protected _transport: Transport;
protected _authBundle: AuthBundle | undefined;
protected declare _messageDispatcher: MessageDispatcher;

constructor(options: RTVIClientOptions) {
Expand All @@ -214,6 +220,7 @@ export class RTVIClient extends RTVIEventEmitter {

this._helpers = {};
this._transport = options.transport;
this._authBundle = undefined;

// Wrap transport callbacks with event triggers
// This allows for either functional callbacks or .on / .off event listeners
Expand Down Expand Up @@ -442,7 +449,7 @@ export class RTVIClient extends RTVIEventEmitter {
}, this._options.timeout);
}

let authBundle: unknown;
let authBundle: AuthBundle;
const customConnectHandler = this._options.customConnectHandler;
const connectUrl = this.constructUrl("connect");

Expand Down Expand Up @@ -511,7 +518,8 @@ export class RTVIClient extends RTVIEventEmitter {
}
return;
}

this._authBundle = authBundle;
logger.debug("[RTVI Client] Auth bundle stored", this._authBundle);
logger.debug("[RTVI Client] Auth bundle received", authBundle);

try {
Expand Down Expand Up @@ -540,7 +548,7 @@ export class RTVIClient extends RTVIEventEmitter {
}

clearTimeout(this._handshakeTimeout);

this._authBundle = undefined;
await this._transport.disconnect();

this._initialize();
Expand Down Expand Up @@ -570,6 +578,10 @@ export class RTVIClient extends RTVIEventEmitter {
return packageJson.version;
}

public get authBundle() {
return this._authBundle;
}

// ------ Device methods

public async getAllMics(): Promise<MediaDeviceInfo[]> {
Expand Down