Skip to content
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
32 changes: 21 additions & 11 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ export class SignalClient {

private streamWriter: WritableStreamDefaultWriter<ArrayBuffer | string> | undefined;

private useV0SignalPath = false;

constructor(useJSON: boolean = false, loggerOptions: LoggerOptions = {}) {
this.log = getLogger(loggerOptions.loggerName ?? LoggerNames.Signal);
this.loggerContextCb = loggerOptions.loggerContextCb;
Expand All @@ -245,13 +247,13 @@ export class SignalClient {
token: string,
opts: SignalOptions,
abortSignal?: AbortSignal,
forceV0Path?: boolean,
useV0Path: boolean = false,
): Promise<JoinResponse> {
// during a full reconnect, we'd want to start the sequence even if currently
// connected
this.state = SignalConnectionState.CONNECTING;
this.options = opts;
const res = await this.connect(url, token, opts, abortSignal, forceV0Path);
const res = await this.connect(url, token, opts, abortSignal, useV0Path);
return res as JoinResponse;
}

Expand All @@ -272,12 +274,18 @@ export class SignalClient {
// clear ping interval and restart it once reconnected
this.clearPingInterval();

const res = (await this.connect(url, token, {
...this.options,
reconnect: true,
sid,
reconnectReason: reason,
})) as ReconnectResponse | undefined;
const res = (await this.connect(
url,
token,
{
...this.options,
reconnect: true,
sid,
reconnectReason: reason,
},
undefined,
this.useV0SignalPath,
)) as ReconnectResponse | undefined;
return res;
}

Expand All @@ -287,16 +295,18 @@ export class SignalClient {
opts: ConnectOpts,
abortSignal?: AbortSignal,
/** setting this to true results in dual peer connection mode being used */
forceV0Path?: boolean,
useV0Path: boolean = false,
): Promise<JoinResponse | ReconnectResponse | undefined> {
const unlock = await this.connectionLock.lock();

this.connectOptions = opts;
this.useV0SignalPath = useV0Path;

const clientInfo = getClientInfo();
const params = forceV0Path
const params = useV0Path
? createConnectionParams(token, clientInfo, opts)
: createJoinRequestConnectionParams(token, clientInfo, opts);
const rtcUrl = createRtcUrl(url, params, forceV0Path).toString();
const rtcUrl = createRtcUrl(url, params, useV0Path).toString();
const validateUrl = createValidateUrl(rtcUrl).toString();

return new Promise<JoinResponse | ReconnectResponse | undefined>(async (resolve, reject) => {
Expand Down
8 changes: 4 additions & 4 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
opts: SignalOptions,
abortSignal?: AbortSignal,
/** setting this to true results in dual peer connection mode being used */
forceV0Path?: boolean,
useV0Path: boolean = false,
): Promise<JoinResponse> {
this.url = url;
this.token = token;
Expand All @@ -277,13 +277,13 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
this.joinAttempts += 1;

this.setupSignalClientCallbacks();
const joinResponse = await this.client.join(url, token, opts, abortSignal, forceV0Path);
const joinResponse = await this.client.join(url, token, opts, abortSignal, useV0Path);
this._isClosed = false;
this.latestJoinResponse = joinResponse;

this.subscriberPrimary = joinResponse.subscriberPrimary;
if (!this.pcManager) {
await this.configure(joinResponse, !forceV0Path);
await this.configure(joinResponse, !useV0Path);
}

// create offer
Expand All @@ -305,7 +305,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
this.logContext,
);
if (this.joinAttempts < this.maxJoinAttempts) {
return this.join(url, token, opts, abortSignal, forceV0Path);
return this.join(url, token, opts, abortSignal, useV0Path);
}
} else if (e.reason === ConnectionErrorReason.ServiceNotFound) {
this.log.warn(`Initial connection failed: ${e.message} – Retrying`);
Expand Down
Loading