janode icon indicating copy to clipboard operation
janode copied to clipboard

Type defs

Open augustblack opened this issue 3 years ago • 25 comments

Here is a potential first start at typescript definitions for janode.

I did my best to create the defs without introducing any extra tooling. All defs live under ./types. However, it does require modifying the package.json I believe that since you require a minimum of node 14, this should be fine. To use with typescript, one will need a recent 4.7 and set ["moduleResolution": "nodenext"] in the tsconfig.json

I'd be happy to do my best to maintain the types moving forward

augustblack avatar Apr 11 '22 12:04 augustblack

Thanks @augustblack for the huge work! I'll take a look in the next few days.

atoppi avatar Apr 11 '22 12:04 atoppi

Thanks @augustblack for the huge work! I'll take a look in the next few days.

Alright, let me know. Happy to make adjustments if needed. I'm concerned that the way I have it set up requires a nightly build of typescript. Only the most recent typescript will recognize the "import": { "types" :... } format in package.json

Maybe there is a better way to organize the definitions for less bleeding-edge implementations.

This is my first time trying to package ts definitions.

augustblack avatar Apr 12 '22 15:04 augustblack

I'm concerned that the way I have it set up requires a nightly build of typescript.

I agree, if a not-stable version of TS is needed I guess this can not be considered for merging now.

This is my first time trying to package ts definitions.

Me too :-) Need to gather some data before reviewing / enhancing.

I'm converting the PR to "draft" since I suspect more work is definitely needed.

atoppi avatar Apr 13 '22 09:04 atoppi

I'm concerned that the way I have it set up requires a nightly build of typescript.

I agree, if a not-stable version of TS is needed I guess this can not be considered for merging now.

This is my first time trying to package ts definitions.

Me too :-) Need to gather some data before reviewing / enhancing.

I'm converting the PR to "draft" since I suspect more work is definitely needed.

No problem. Fwiw. the definitions work great and I don't suspect it will be long before TS 4.7 is released.

AFACT, if we could pull the defs into a single .d.ts , then we shouldn't have issues with TS < 4.7

The problem is the subpath import structure you have with janode and trying to match that in the type defs.

For example, you import for JS with:

import Janode from 'janode';
import AudioBridgePlugin from 'janode/plugins/audiobridge';

Having the TS defs mimic the subpath audiobridge plugin import is the hard part. To do so, we need to afaict have the defs in a similar folder structure. However, only TS 4.7 can read package.json in such a way as I have in this pull request to define the subpath imports.

Currently, this PR does it so:

import Janode from 'janode';
import Connection from 'janode/connection';
import Session from 'janode/session';
import AudioBridgePlugin from 'janode/plugins/audiobridge';

If you like, I could clean it up into one .d.ts file and have import on the TS side do something like:

import Janode, {Connection, Session, AudioBridgePlugin } from 'janode';

That would, however, cause conflicts I imagine when you are pulling the type definition for the AudioBridgePlugin from 'janode', but the actual code from 'jandoe/plugins/audiobridge'

Maybe there is a way to do a single .d.ts file and still import from a subpath like janode/plugins/audiobridge, but I couldn't find it. The only way I could find to do the subpath import was the one proposed in this PR that requires the newest TS version.

Thanks for the consideration and happy to follow any suggestions you have.

augustblack avatar Apr 13 '22 13:04 augustblack

I fixed a few minor things. I'm sure as I test this out, there will be more.

To test, you will need to add to your project where using janode:

npm install -D typescript@beta.

nightly isn't needed, beta is enough. Fwiw, the TS 4.7 should be released by the end of May.

and then in tsconfig.json for your project, be sure to set:

"moduleResolution": "nodenext",

No hurry on my part for the merge (if at all).

From what I can tell, this PR has no intrusion on the JS side of things and should be safe to merge. If anything, it might encourage other to contribute.

augustblack avatar Apr 13 '22 21:04 augustblack

Thx i was looking for this ! Works well with typescript !

rchoffar avatar May 17 '22 14:05 rchoffar

That's great, @rchoffar

I've only been using it on the audiobridge. Please let me know if there are any type issues with the other plugins.

augustblack avatar May 20 '22 11:05 augustblack

I tried to use it with videoroom plugin and it worked well on 0.x Unfortunetly i switched to janus 1.x and Janode is not compatible with it. This is not related to your PR.

rchoffar avatar May 24 '22 11:05 rchoffar

@rchoffar what is not compatible with 1.x ? janode does not still support multistream syntax, but it should work on janus 1.x using the 0.x syntax. Indeed I regularly use janode with janus 1.x.

If you discovered something that is not working please submit a new issue.

atoppi avatar May 24 '22 12:05 atoppi

@atoppi No sry that's not what i wanted to say, i wanted to upgrade to 1.x in order to use multistream features but janode does not support multistream syntax as you said.

rchoffar avatar May 25 '22 12:05 rchoffar

fwiw, typescript 4.7 has been out for a while now.

making things work is now as simple as: npm install -D typescript

augustblack avatar Jun 08 '22 09:06 augustblack

Any news on this?

capital-G avatar Jan 07 '23 10:01 capital-G

Hello, is there any update on this PR?

alexandermaisey avatar Jun 27 '24 16:06 alexandermaisey

I just noticed that my comments have never received response @augustblack

atoppi avatar Jun 28 '24 09:06 atoppi

I've been updating the ts defs for the audiobridge and streaming plugins incrementally as I am working on my project, but I don't think I'll have the capacity to maintain the type defs for all plugins as janode develops, or even keep things up to date.

I personally think it would be less work and more appropriate to convert janode to TS. #24

Is there any desire to move in that direction? I wish I could help out more.

augustblack avatar Jul 03 '24 16:07 augustblack

@augustblack not planned migrating to TS in the short term unfortunately. I guess we need to find some time to properly support type defs.

atoppi avatar Jul 08 '24 12:07 atoppi