Skip to content

Commit

Permalink
Modernize
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
ibc committed Sep 14, 2023
1 parent 8c28003 commit 13e1ab7
Show file tree
Hide file tree
Showing 43 changed files with 12,053 additions and 2,692 deletions.
90 changes: 45 additions & 45 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
const os = require('os');

const isWindows = os.platform() === 'win32';

const eslintConfig =
{
env :
{
es6 : true,
node : true
browser : true,
es6 : true,
node : true
},
plugins : [],
settings : {},
parserOptions :
{
ecmaVersion : 2018,
ecmaVersion : 2022,
sourceType : 'module',
ecmaFeatures :
{
impliedStrict : true
},
lib : [ 'es2018', 'dom' ]
lib : [ 'es2022', 'dom' ],
project : 'tsconfig.json'
},
rules :
{
Expand All @@ -35,6 +41,7 @@ const eslintConfig =
'comma-style' : 2,
'computed-property-spacing' : 2,
'constructor-super' : 2,
'curly' : [ 2, 'all' ],
'func-call-spacing' : 2,
'generator-star-spacing' : 2,
'guard-for-in' : 2,
Expand All @@ -50,12 +57,13 @@ const eslintConfig =
{
beforeColon : true,
afterColon : true,
mode : 'minimum',
align : 'colon'
}
}
],
'keyword-spacing' : 2,
'linebreak-style' : [ 2, 'unix' ],
'linebreak-style' : [ 2, isWindows ? 'windows' : 'unix' ],
'lines-around-comment' : [ 2,
{
allowBlockStart : true,
Expand Down Expand Up @@ -171,70 +179,62 @@ const eslintConfig =
'strict' : 2,
'valid-typeof' : 2,
'yoda' : 2
}
},
overrides : []
};

switch (process.env.MEDIASOUP_NODE_LANGUAGE)
{
case 'typescript':
eslintConfig.overrides.push(
{
eslintConfig.parser = '@typescript-eslint/parser';
eslintConfig.plugins =
[
files : [ '*.ts' ],
parser : '@typescript-eslint/parser',
plugins : [
...eslintConfig.plugins,
'@typescript-eslint'
];
eslintConfig.extends =
[
],
extends : [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
];
eslintConfig.rules =
{
],
rules : {
...eslintConfig.rules,
'camelcase' : 0,
'no-unused-vars' : 0,
'@typescript-eslint/ban-ts-comment' : 0,
'@typescript-eslint/ban-ts-ignore' : 0,
'@typescript-eslint/member-delimiter-style' : [ 2,
'no-unused-vars' : 0,
'@typescript-eslint/ban-types' : 0,
'@typescript-eslint/ban-ts-comment' : 0,
'@typescript-eslint/ban-ts-ignore' : 0,
'@typescript-eslint/explicit-module-boundary-types' : 0,
'@typescript-eslint/semi' : 2,
'@typescript-eslint/member-delimiter-style' : [ 2,
{
multiline : { delimiter: 'semi', requireLast: true },
singleline : { delimiter: 'semi', requireLast: false }
}
],
'@typescript-eslint/no-empty-function' : 0,
'@typescript-eslint/no-explicit-any' : 0,
'@typescript-eslint/no-unused-vars' : [ 2,
'@typescript-eslint/no-explicit-any' : 0,
'@typescript-eslint/no-unused-vars' : [ 2,
{
vars : 'all',
args : 'after-used',
ignoreRestSiblings : false
}
],
'@typescript-eslint/no-use-before-define' : 0,
'@typescript-eslint/no-use-before-define' : [ 2, { functions: false } ],
'@typescript-eslint/no-empty-function' : 0,
'@typescript-eslint/no-non-null-assertion' : 0
};

break;
}
}
});

case 'javascript':
eslintConfig.overrides.push(
{
eslintConfig.env['jest/globals'] = true;
eslintConfig.plugins =
[
files : [ '*.ts' ],
env : {
...eslintConfig.env,
'jest/globals' : true
},
plugins : [
...eslintConfig.plugins,
'jest'
];

break;
}

default:
{
throw new TypeError('wrong/missing MEDIASOUP_NODE_LANGUAGE env');
}
}
]
});

module.exports = eslintConfig;
17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/node_modules/
/coverage/
/node_modules
/lib
/coverage

# Vim temporal files.
*.swp
Expand All @@ -9,9 +10,11 @@
.DS_Store

# Vistual Studio Code stuff.
/.vscode/
/.vscode

# Python cache
/.mypy_cache/
/worker/__pycache__/
/worker/.mypy_cache/
# Cache.
/.cache
/.mypy_cache
/worker/__pycache__
/worker/.mypy_cache
/worker/mediasoup_client_aiortc.egg-info
5 changes: 4 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
package-lock=false
# Generate package-lock.json.
package-lock=true
# For bad node/npm version to throw actual error.
engine-strict=true
25 changes: 0 additions & 25 deletions lib/AiortcMediaStream.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/AiortcMediaStream.d.ts.map

This file was deleted.

73 changes: 0 additions & 73 deletions lib/AiortcMediaStream.js

This file was deleted.

19 changes: 0 additions & 19 deletions lib/Channel.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion lib/Channel.d.ts.map

This file was deleted.

Loading

0 comments on commit 13e1ab7

Please sign in to comment.