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

Modernize #23

Merged
merged 13 commits into from
Sep 15, 2023
Merged

Modernize #23

merged 13 commits into from
Sep 15, 2023

Conversation

ibc
Copy link
Member

@ibc ibc commented Sep 14, 2023

Make it be similar to mediasoup-client repo.

  • Update NPM deps.
  • Update TypeScript.
  • Update ESLint.
  • Remove lib from the repo.
  • Remove src and temp files/folders in worker from the NPM package.
  • Move test to TypeScript.
  • Add CI.

Breaking Changes

  • PYTHON3 env is now PYTHON.
  • PYP3 env (note that it was a typo anyway) is now PIP.

Notes

ibc added 5 commits September 14, 2023 14:00
Make it be similar to mediasoup-client repo.

- [x] Update NPM deps.
- [x] Update TypeScript.
- [x] Update ESLint.
- [x] Remove `lib` from the repo.
- [x] Move test to TypeScript.
- [ ] Make `FakeRTCDataChannel` properly implement `RTCDataChannel` (see below).
- [ ] Add event listener TS types.
- [ ] Probably add a `types.ts` and export it.
- [ ] Update Python deps?.
- [ ] Add CI.

### TODO 1: TypeScript error in `FakeRTCDataChannel`

It doesn't implement properly the official `RTCDataChannel` interface. Probably related to its events:

```
src/FakeRTCDataChannel.ts:23:14 - error TS2420: Class 'FakeRTCDataChannel' incorrectly implements interface 'RTCDataChannel'.
  Types of property 'addEventListener' are incompatible.
    Type '{ <T extends string>(type: T, callback?: EventListener<this, Event<string>> | null | undefined, options?: AddOptions | undefined): void; (type: string, callback?: EventListener<...> | ... 1 more ... | undefined, options?: AddOptions | undefined): void; <T extends string>(type: T, callback: EventListener<...> | ... 1...' is not assignable to type '{ <K extends keyof RTCDataChannelEventMap>(type: K, listener: (this: RTCDataChannel, ev: RTCDataChannelEventMap[K]) => any, options?: boolean | ... 1 more ... | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
      Types of parameters 'callback' and 'listener' are incompatible.
        Type '(this: RTCDataChannel, ev: any) => any' is not assignable to type 'EventListener<this, Event<string>> | null | undefined'.
          Type '(this: RTCDataChannel, ev: any) => any' is not assignable to type 'CallbackFunction<this, Event<string>>'.
            The 'this' types of each signature are incompatible.
              Type 'this' is not assignable to type 'RTCDataChannel'.
                Type 'FakeRTCDataChannel' is not assignable to type 'RTCDataChannel'.
                  Types of property 'addEventListener' are incompatible.
                    Type '{ <T extends string>(type: T, callback?: EventListener<this, Event<string>> | null | undefined, options?: AddOptions | undefined): void; (type: string, callback?: EventListener<...> | ... 1 more ... | undefined, options?: AddOptions | undefined): void; <T extends string>(type: T, callback: EventListener<...> | ... 1...' is not assignable to type '{ <K extends keyof RTCDataChannelEventMap>(type: K, listener: (this: RTCDataChannel, ev: RTCDataChannelEventMap[K]) => any, options?: boolean | ... 1 more ... | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
                      Types of parameters 'callback' and 'listener' are incompatible.
                        Type '(this: RTCDataChannel, ev: any) => any' is not assignable to type 'EventListener<this, Event<string>> | null | undefined'.

23 export class FakeRTCDataChannel extends EventTarget implements RTCDataChannel
```
@ibc ibc requested a review from jmillan September 14, 2023 16:53
Copy link
Contributor

@ggoldens ggoldens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Is there any reason for keep passing loop in channel.py since now it's not used anymore?

@ibc
Copy link
Member Author

ibc commented Sep 14, 2023

LGTM. Is there any reason for keep passing loop in channel.py since now it's not used anymore?

No, and in fact I forgot to remove it. I'll do tomorrow.

RTCPeerConnection,
RTCRtpTransceiver,
RTCSessionDescription,
RTCStatsReport
)
from aiortc import RTCDataChannel # noqa: F401
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this to make linter happy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Let me explain:

npm run lint:python

which runs:

executeCmd(`cd worker && ${PYTHON} -m flake8 && cd ..`);
executeCmd(`cd worker && ${PYTHON} -m mypy . && cd ..`);

Indeed we don't use RTCDataChannel in hander.py so flake8 complains due to "unused var". However we cannot remove it since this:

# dictionary of dataChannelds mapped by internal id
self._dataChannels = dict()  # type: Dict[str, RTCDataChannel]

Believe me or not, but such a # type: Dict[str, RTCDataChannel] comment is checked by mypy and it needs to know what RTCDataChannel is. So here two conflicting linters / type checkers / whatever. So we must make both happy.

Then you may thing "why not this instead of importing twice from aiortc?":

from aiortc import (
    RTCConfiguration,
    RTCPeerConnection,
    RTCRtpTransceiver,
    RTCSessionDescription,
    RTCStatsReport,
    RTCDataChannel  # noqa: F401
)

or this:

from aiortc import (
    RTCConfiguration,
    RTCPeerConnection,
    RTCRtpTransceiver,
    RTCSessionDescription,
    RTCStatsReport,
    # noqa: F401
    RTCDataChannel
)

or this:

# noqa: F401
from aiortc import (
    RTCConfiguration,
    RTCPeerConnection,
    RTCRtpTransceiver,
    RTCSessionDescription,
    RTCStatsReport,
    RTCDataChannel
)

Well, because none of those work. I've tried everything. Python ecosystem sucks a lot.

@ibc
Copy link
Member Author

ibc commented Sep 15, 2023

LGTM. Is there any reason for keep passing loop in channel.py since now it's not used anymore?

Done.

@ibc ibc merged commit 0bc25ef into v3 Sep 15, 2023
2 of 4 checks passed
@ibc ibc deleted the modernize branch September 15, 2023 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants