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

livekit-client 1.14.0 broken in Angular app #893

Closed
pabloFuente opened this issue Oct 17, 2023 · 9 comments
Closed

livekit-client 1.14.0 broken in Angular app #893

pabloFuente opened this issue Oct 17, 2023 · 9 comments

Comments

@pabloFuente
Copy link
Contributor

pabloFuente commented Oct 17, 2023

Describe the bug

What I'm expecting

Adding livekit-client: 1.14.0 dependency to an Angular 16 project should work fine.

What happens instead

Compilation of Angular 16 app (ng build) fails with the following error

Error: node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:24:51 - error TS2304: Cannot find name 'this'.

24     setProcessor(processor: TrackProcessor<typeof this.kind>): Promise<void>;
                                                     ~~~~

Which seems related to the track-processors API.

Reproduction

The error is easily replicable with the following steps:

# Create new Angular 16 project
ng new test-project --defaults

# Install livekit-client dependency
cd test-project && npm i livekit-client@1.14.0

# Add an import of the livekit-client in the project
sed -i '1s/^/import * as LiveKit from "livekit-client";\n/' src/app/app.component.ts

# Try to build. THIS FAILS
ng build

Logs

user@user-pro:~/Desktop/test-project$ ng build
✔ Browser application bundle generation complete.

Error: node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:24:51 - error TS2304: Cannot find name 'this'.

24     setProcessor(processor: TrackProcessor<typeof this.kind>): Promise<void>;
                                                     ~~~~

System Info

Versions:

- OS: linux x64 (Ubuntu 22.04.3 LTS)
- Node: 18.18.2
- Package Manager: npm 9.8.1
- Angular: 16.2.9
- livekit-client: 1.14.0

Severity

blocking all usage of LiveKit

Additional Information

There is a way of fixing the issue manually, which is making an import in file node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:

import *  as TrackKind from './Track';

And replacing <typeof this.kind> with <TrackKind.Track.Kind> in line node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:24:51

But of course this is far from ideal.

@lukasIO
Copy link
Contributor

lukasIO commented Oct 17, 2023

Hi,

could you post the exact error message you get? It can't be the same as in #166 because we have since replaced the protobuf library that imported those paths.
Are you seeing "only" the logger error at first?

@pabloFuente
Copy link
Contributor Author

pabloFuente commented Oct 17, 2023

Ouch, I just realized that the first error is actually happening when adding livekit-server-sdk library to the Angular project, which of course may fail.
I have already updated the issue to only focus on the second error.

@lukasIO
Copy link
Contributor

lukasIO commented Oct 18, 2023

had a closer look at this. Solving it differently without breaking backwards compatibility seems tricky.
I found this thread talking about the whole thing, one suggestion is to use TrackProcessor<this['kind']> instead of the typeof this.kind approach. Could you give that a try?

@pabloFuente
Copy link
Contributor Author

Well, that solution is pretty much the same as I described in my Additional Information section in my first comment:

Additional Information

There is a way of fixing the issue manually, which is making an import in file node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:

import *  as TrackKind from './Track';

And replacing <typeof this.kind> with <TrackKind.Track.Kind> in line node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:24:51

Basically changing the way file LocalAudioTrack.d.ts declares that typing, which seems unsupported in the latest Angular version (probably due to its TypeScript version). It fixes the problem, but of course it means that the latest version of livekit-client does not work out-of-the-box in the latest version of an Angular project. Not a real blocking issue, but I guess it might be for Angular developers who decide to give LiveKit a quick try.

@lukasIO
Copy link
Contributor

lukasIO commented Oct 23, 2023

Well, that solution is pretty much the same as I described in my Additional Information section in my first comment:

It's not the same, as it will keep the actual type information. TrackKind.Track.Kind as you suggested doesn't specify whether the track is an audio or a video track.

Did you confirm that TrackProcessor<this['kind']> works for your Angular setup? If that's the case then I can open a PR with that change and change it in the client sdk directly.

@pabloFuente
Copy link
Contributor Author

pabloFuente commented Oct 24, 2023

I have confirmed that replacing TrackProcessor<typeof this.kind> with TrackProcessor<this['kind']> in node_modules/livekit-client/dist/src/room/track/LocalAudioTrack.d.ts:24:51 fixes the TypeScript compilation problem.
I am guessing that replacing these occurrences with this['kind'] should be enough to bypass this TypeScript "limitation".

@lukasIO
Copy link
Contributor

lukasIO commented Oct 25, 2023

nice, thanks! would you want to open a PR for it?

@pabloFuente
Copy link
Contributor Author

Sure. I've already opened this one for a typo fix in the documentation, so I'm familiar with the process 😃

@lukasIO
Copy link
Contributor

lukasIO commented Oct 26, 2023

closed via #901

@lukasIO lukasIO closed this as completed Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants