diff --git a/.prettierrc b/.prettierrc index ed3a79adb8..82d69502c1 100644 --- a/.prettierrc +++ b/.prettierrc @@ -7,6 +7,6 @@ "importOrder": ["", "^[./]"], "importOrderSeparation": false, "importOrderSortSpecifiers": true, - "importOrderParserPlugins": ["typescript"], + "importOrderParserPlugins": ["typescript", "decorators"], "plugins": ["@trivago/prettier-plugin-sort-imports"] } diff --git a/package.json b/package.json index 9c80748f25..10d3181649 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "size-limit": "size-limit" }, "dependencies": { + "@aloreljs/bound-decorator": "^3.0.3", "@livekit/protocol": "1.16.0", "events": "^3.3.0", "loglevel": "^1.8.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca5d32a217..e591efd6cb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + '@aloreljs/bound-decorator': + specifier: ^3.0.3 + version: 3.0.3 '@livekit/protocol': specifier: 1.16.0 version: 1.16.0 @@ -151,6 +154,9 @@ packages: resolution: {integrity: sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==} engines: {node: '>=0.10.0'} + '@aloreljs/bound-decorator@3.0.3': + resolution: {integrity: sha512-ymq8Wt7DVNfI3j2cBlNWnLLDAWStDI9UdefFntx0JUGmVofXpqNmeA+xTpyzodqD5wczAQIqaIgXwtFeqE6W5w==} + '@ampproject/remapping@2.2.1': resolution: {integrity: sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==} engines: {node: '>=6.0.0'} @@ -3381,8 +3387,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - typescript@5.5.0-dev.20240513: - resolution: {integrity: sha512-EaabRW/mNcpehitpeUkoIg8mNRGl5twGUzHJEJE9qTMlvVzoctff/XFZGKrxu9PUUcYluaMQTBNdNuqOZMqvTw==} + typescript@5.5.0-dev.20240530: + resolution: {integrity: sha512-r/4r/a9tbtPRHfif0An0GLycB70C3ci3m9fhpgiv6Ekyl7mxYc4w8aX/R+vQ4OJlmPosJJUCjUbljH11g6C56g==} engines: {node: '>=14.17'} hasBin: true @@ -3658,6 +3664,8 @@ snapshots: '@aashutoshrathi/word-wrap@1.2.6': {} + '@aloreljs/bound-decorator@3.0.3': {} + '@ampproject/remapping@2.2.1': dependencies: '@jridgewell/gen-mapping': 0.3.5 @@ -5590,7 +5598,7 @@ snapshots: dependencies: semver: 7.6.0 shelljs: 0.8.5 - typescript: 5.5.0-dev.20240513 + typescript: 5.5.0-dev.20240530 electron-to-chromium@1.4.724: {} @@ -7270,7 +7278,7 @@ snapshots: typescript@5.4.5: {} - typescript@5.5.0-dev.20240513: {} + typescript@5.5.0-dev.20240530: {} ufo@1.5.3: {} diff --git a/src/room/PCTransport.ts b/src/room/PCTransport.ts index 9eb6f63a28..54cfbc6393 100644 --- a/src/room/PCTransport.ts +++ b/src/room/PCTransport.ts @@ -1,3 +1,4 @@ +import { BoundMethod } from '@aloreljs/bound-decorator'; import { EventEmitter } from 'events'; import type { MediaDescription } from 'sdp-transform'; import { parse, write } from 'sdp-transform'; @@ -431,7 +432,8 @@ export default class PCTransport extends EventEmitter { return candidates.get(selectedID); } - close = () => { + @BoundMethod() + close() { if (!this._pc) { return; } @@ -448,7 +450,7 @@ export default class PCTransport extends EventEmitter { this._pc.onconnectionstatechange = null; this._pc.oniceconnectionstatechange = null; this._pc = null; - }; + } private async setMungedSDP(sd: RTCSessionDescriptionInit, munged?: string, remote?: boolean) { if (munged) { diff --git a/src/room/Room.ts b/src/room/Room.ts index f697aeba30..e1266ce04c 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -1,3 +1,4 @@ +import { BoundMethod } from '@aloreljs/bound-decorator'; import { ConnectionQualityUpdate, type DataPacket, @@ -716,7 +717,8 @@ class Room extends (EventEmitter as new () => TypedEmitter) /** * disconnects the room, emits [[RoomEvent.Disconnected]] */ - disconnect = async (stopTracks = true) => { + @BoundMethod() + async disconnect(stopTracks = true) { const unlock = await this.disconnectLock.lock(); try { if (this.state === ConnectionState.Disconnected) { @@ -752,7 +754,7 @@ class Room extends (EventEmitter as new () => TypedEmitter) } finally { unlock(); } - }; + } /** * retrieves a participant by identity @@ -903,9 +905,11 @@ class Room extends (EventEmitter as new () => TypedEmitter) * some form of user interaction (click/tap/etc). * In those cases, audio will be silent until a click/tap triggering one of the following * - `startAudio` + * * - `getUserMedia` */ - startAudio = async () => { + @BoundMethod() + async startAudio() { const elements: Array = []; const browser = getBrowser(); if (browser && browser.os === 'iOS') { @@ -974,7 +978,7 @@ class Room extends (EventEmitter as new () => TypedEmitter) this.handleAudioPlaybackFailed(err); throw err; } - }; + } startVideo = async () => { const elements: HTMLMediaElement[] = [];