Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Nov 13, 2023
1 parent 62cd815 commit 5e455bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 67 deletions.
4 changes: 1 addition & 3 deletions src/room/PCTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export default class PCTransport extends EventEmitter {

private get pc() {
if (!this._pc) {
console.warn('creating new peer connection');
this._pc = this.createPC(); // FIXME this seems to leak peer connections
this._pc = this.createPC();
}
return this._pc;
}
Expand Down Expand Up @@ -426,7 +425,6 @@ export default class PCTransport extends EventEmitter {
}

close = () => {
console.warn('closing pc transport');
if (!this._pc) {
return;
}
Expand Down
34 changes: 8 additions & 26 deletions src/room/PCTransportManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,14 @@ export class PCTransportManager {

async ensurePCTransportConnection(abortController?: AbortController, timeout?: number) {
const unlock = await this.connectionLock.lock();

try {
if (
this.isPublisherConnectionRequired &&
this.publisher.getConnectionState() !== 'connected' &&
this.publisher.getConnectionState() !== 'connecting'
) {
console.log('negotiation required, start negotiating');
log.debug('negotiation required, start negotiating');
this.publisher.negotiate();
} else {
console.log(
'no negotiation required',
this.isPublisherConnectionRequired,
this.publisher.getConnectionState(),
);
}
await Promise.all(
this.requiredTransports?.map((transport) =>
Expand All @@ -196,7 +189,6 @@ export class PCTransportManager {
}

async negotiate(abortController: AbortController) {
console.log('negotiation requested');
return new Promise<void>(async (resolve, reject) => {
const negotiationTimeout = setTimeout(() => {
reject('negotiation timed out');
Expand Down Expand Up @@ -269,11 +261,13 @@ export class PCTransportManager {
} else if (connectionStates.every((st) => st === 'new')) {
this.state = PCTransportState.NEW;
}
log.info(`pc state: ${PCTransportState[this.state]}`, {
publisher: this.publisher.getConnectionState(),
subscriber: this.subscriber.getConnectionState(),
});

if (previousState !== this.state) {
log.debug(
`pc state change: from ${PCTransportState[previousState]} to ${
PCTransportState[this.state]
}`,
);
this.onStateChange?.(
this.state,
this.publisher.getConnectionState(),
Expand All @@ -291,11 +285,7 @@ export class PCTransportManager {
if (connectionState === 'connected') {
return;
}
// if (this.pcState !== PCState.New) {
// throw new UnexpectedConnectionState(
// 'Expected peer connection to be new on initial connection',
// );
// }

return new Promise<void>(async (resolve, reject) => {
const abortHandler = () => {
log.warn('abort transport connection');
Expand Down Expand Up @@ -336,11 +326,3 @@ export class PCTransportManager {
});
}
}

// function getPCState(pcTransport: PCTransport) {
// return {
// connectionState: pcTransport.getConnectionState(),
// iceState: pcTransport.getICEConnectionState(),
// signallingState: pcTransport.getSignallingState(),
// };
// }
38 changes: 0 additions & 38 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -978,41 +978,6 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
throw new UnexpectedConnectionState('PC manager is closed');
}
await this.pcManager.ensurePCTransportConnection(abortController, timeout);
// if (this.pcState === PCState.Connected) {
// return;
// }
// if (this.pcState !== PCState.New) {
// throw new UnexpectedConnectionState(
// 'Expected peer connection to be new on initial connection',
// );
// }
// return new Promise<void>((resolve, reject) => {
// const abortHandler = () => {
// log.warn('closing engine');
// CriticalTimers.clearTimeout(connectTimeout);

// reject(
// new ConnectionError(
// 'room connection has been cancelled',
// ConnectionErrorReason.Cancelled,
// ),
// );
// };
// if (abortController?.signal.aborted) {
// abortHandler();
// }
// abortController?.signal.addEventListener('abort', abortHandler);
// const onConnected = () => {
// CriticalTimers.clearTimeout(connectTimeout);
// abortController?.signal.removeEventListener('abort', abortHandler);
// resolve();
// };
// const connectTimeout = CriticalTimers.setTimeout(() => {
// this.off(EngineEvent.Connected, onConnected);
// reject(new ConnectionError('could not establish pc connection'));
// }, timeout ?? this.peerConnectionTimeout);
// this.once(EngineEvent.Connected, onConnected);
// });
}

private async waitForPCReconnected() {
Expand Down Expand Up @@ -1140,14 +1105,11 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
}
// primary connection
if (this.pcManager.currentState !== PCTransportState.CONNECTED) {
console.log('pc man state', this.pcManager.currentState);
return false;
}

// ensure signal is connected
if (!this.client.ws || this.client.ws.readyState === WebSocket.CLOSED) {
console.log('ws state', this.client.ws?.readyState);

return false;
}
return true;
Expand Down

0 comments on commit 5e455bf

Please sign in to comment.