Skip to content

Commit

Permalink
Revert "Add TS decorator support and replace class arrow function fie…
Browse files Browse the repository at this point in the history
…lds with bound methods (#790)" (#801)

This reverts commit 41a1df1.
  • Loading branch information
lukasIO authored Jul 20, 2023
1 parent 41a1df1 commit eb17478
Show file tree
Hide file tree
Showing 19 changed files with 468 additions and 810 deletions.
5 changes: 0 additions & 5 deletions .changeset/lovely-crabs-hide.md

This file was deleted.

2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"importOrder": ["<THIRD_PARTY_MODULES>", "^[./]"],
"importOrderSeparation": false,
"importOrderSortSpecifiers": true,
"importOrderParserPlugins": ["typescript", "decorators"],
"importOrderParserPlugins": ["typescript"],
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
},
"devDependencies": {
"@babel/core": "7.22.1",
"@babel/plugin-proposal-decorators": "^7.22.7",
"@babel/preset-env": "7.22.4",
"@babel/preset-typescript": "^7.22.5",
"@bufbuild/protoc-gen-es": "^1.3.0",
"@changesets/cli": "2.26.1",
"@livekit/changesets-changelog-github": "^0.0.4",
Expand All @@ -75,7 +73,9 @@
"@size-limit/file": "^8.2.4",
"@size-limit/webpack": "^8.2.4",
"@trivago/prettier-plugin-sort-imports": "^4.1.1",
"@types/events": "^3.0.0",
"@types/sdp-transform": "2.4.6",
"@types/ua-parser-js": "0.7.36",
"@typescript-eslint/eslint-plugin": "5.59.8",
"@typescript-eslint/parser": "5.59.8",
"downlevel-dts": "^0.11.0",
Expand All @@ -92,11 +92,11 @@
"rollup-plugin-re": "1.0.7",
"rollup-plugin-typescript2": "0.34.1",
"size-limit": "^8.2.4",
"ts-proto": "1.148.2",
"typedoc": "0.24.8",
"typedoc-plugin-no-inherit": "1.4.0",
"typescript": "5.1.3",
"vite": "4.4.2",
"vite-plugin-babel": "^1.1.3",
"vite": "4.3.9",
"vitest": "^0.32.0"
}
}
17 changes: 0 additions & 17 deletions src/decorators/autoBind.ts

This file was deleted.

6 changes: 2 additions & 4 deletions src/e2ee/E2eeManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import EventEmitter from 'eventemitter3';
import { bound } from '../decorators/autoBind';
import log from '../logger';
import { Encryption_Type, TrackInfo } from '../proto/livekit_models_pb';
import type RTCEngine from '../room/RTCEngine';
Expand Down Expand Up @@ -132,11 +131,10 @@ export class E2EEManager extends EventEmitter<E2EEManagerCallbacks> {
}
};

@bound
private onWorkerError(ev: ErrorEvent) {
private onWorkerError = (ev: ErrorEvent) => {
log.error('e2ee worker encountered an error:', { error: ev.error });
this.emit(EncryptionEvent.Error, ev.error);
}
};

public setupEngine(engine: RTCEngine) {
engine.on(EngineEvent.RTPVideoMapUpdate, (rtpMap) => {
Expand Down
46 changes: 18 additions & 28 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import EventEmitter from 'eventemitter3';
import type { MediaAttributes } from 'sdp-transform';
import type { SignalOptions } from '../api/SignalClient';
import { SignalClient } from '../api/SignalClient';
import { bound } from '../decorators/autoBind';
import log from '../logger';
import type { InternalRoomOptions } from '../options';
import {
Expand Down Expand Up @@ -604,8 +603,7 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
this.reliableDC.onbufferedamountlow = this.handleBufferedAmountLow;
}

@bound
private async handleDataChannel({ channel }: RTCDataChannelEvent) {
private handleDataChannel = async ({ channel }: RTCDataChannelEvent) => {
if (!channel) {
return;
}
Expand All @@ -618,10 +616,9 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
}
log.debug(`on data channel ${channel.id}, ${channel.label}`);
channel.onmessage = this.handleDataMessage;
}
};

@bound
private async handleDataMessage(message: MessageEvent) {
private handleDataMessage = async (message: MessageEvent) => {
// make sure to respect incoming data message order by processing message events one after the other
const unlock = await this.dataProcessLock.lock();
try {
Expand All @@ -645,10 +642,9 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
} finally {
unlock();
}
}
};

@bound
private handleDataError(event: Event) {
private handleDataError = (event: Event) => {
const channel = event.currentTarget as RTCDataChannel;
const channelKind = channel.maxRetransmits === 0 ? 'lossy' : 'reliable';

Expand All @@ -658,16 +654,15 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
} else {
log.error(`Unknown DataChannel Error on ${channelKind}`, event);
}
}
};

@bound
private handleBufferedAmountLow(event: Event) {
private handleBufferedAmountLow = (event: Event) => {
const channel = event.currentTarget as RTCDataChannel;
const channelKind =
channel.maxRetransmits === 0 ? DataPacket_Kind.LOSSY : DataPacket_Kind.RELIABLE;

this.updateAndEmitDCBufferStatus(channelKind);
}
};

private setPreferredCodec(
transceiver: RTCRtpTransceiver,
Expand Down Expand Up @@ -816,8 +811,7 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
// websocket reconnect behavior. if websocket is interrupted, and the PeerConnection
// continues to work, we can reconnect to websocket to continue the session
// after a number of retries, we'll close and give up permanently
@bound
private handleDisconnect(connection: string, disconnectReason?: ReconnectReason) {
private handleDisconnect = (connection: string, disconnectReason?: ReconnectReason) => {
if (this._isClosed) {
return;
}
Expand Down Expand Up @@ -862,7 +856,7 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
() => this.attemptReconnect(disconnectReason),
delay,
);
}
};

private async attemptReconnect(reason?: ReconnectReason) {
if (this._isClosed) {
Expand Down Expand Up @@ -1111,8 +1105,7 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
throw new ConnectionError('could not establish PC connection');
}

@bound
waitForRestarted() {
waitForRestarted = () => {
return new Promise<void>((resolve, reject) => {
if (this.pcState === PCState.Connected) {
resolve();
Expand All @@ -1129,7 +1122,7 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
this.once(EngineEvent.Disconnected, onDisconnected);
this.once(EngineEvent.Closing, onDisconnected);
});
}
};

/* @internal */
async sendDataPacket(packet: DataPacket, kind: DataPacket_Kind) {
Expand All @@ -1146,22 +1139,20 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
this.updateAndEmitDCBufferStatus(kind);
}

@bound
private updateAndEmitDCBufferStatus(kind: DataPacket_Kind) {
private updateAndEmitDCBufferStatus = (kind: DataPacket_Kind) => {
const status = this.isBufferStatusLow(kind);
if (typeof status !== 'undefined' && status !== this.dcBufferStatus.get(kind)) {
this.dcBufferStatus.set(kind, status);
this.emit(EngineEvent.DCBufferStatusChanged, status, kind);
}
}
};

@bound
private isBufferStatusLow(kind: DataPacket_Kind): boolean | undefined {
private isBufferStatusLow = (kind: DataPacket_Kind): boolean | undefined => {
const dc = this.dataChannelForKind(kind);
if (dc) {
return dc.bufferedAmount <= dc.bufferedAmountLowThreshold;
}
}
};

/**
* @internal
Expand Down Expand Up @@ -1341,14 +1332,13 @@ export default class RTCEngine extends EventEmitter<EngineEventCallbacks> {
this.reconnectAttempts = 0;
}

@bound
private handleBrowserOnLine() {
private handleBrowserOnLine = () => {
// in case the engine is currently reconnecting, attempt a reconnect immediately after the browser state has changed to 'onLine'
if (this.client.isReconnecting) {
this.clearReconnectTimeout();
this.attemptReconnect(ReconnectReason.RR_SIGNAL_DISCONNECTED);
}
}
};

private registerOnLineListener() {
if (isWeb()) {
Expand Down
Loading

0 comments on commit eb17478

Please sign in to comment.