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

How to use webtransport.node binary? #188

Closed
guest271314 opened this issue Jul 20, 2023 · 16 comments
Closed

How to use webtransport.node binary? #188

guest271314 opened this issue Jul 20, 2023 · 16 comments

Comments

@guest271314
Copy link

No description provided.

@martenrichter
Copy link
Member

It will be used automatically by the node code. Just use the provided js interfaces. There is no stable API and you should not call it directly.

@guest271314
Copy link
Author

I'll try to use with node. It would be interesting if the library could be generic JavaScript capable of being imported into QuickJS, txiki.js, Deno, jsshell.

@martenrichter
Copy link
Member

The problem is that each of these libraries have a different C/JS interface, so I think it is more or less impossible.
The current plugin uses napi, so all javascript engine that use this interface will work. But I am afraid, that is just node. (Electron may be compatible after some alterations).

@martenrichter
Copy link
Member

But here is a tracking bug for deno
denoland/deno#13633
I do not know all necessary functions are implemented yet.

@guest271314
Copy link
Author

The problem is that each of these libraries have a different C/JS interface, so I think it is more or less impossible.

Yes, I know. Not impossible. I wrote Native Messaging hosts for QuickJS, txiki.js, Bun, Deno, and Node.js https://github.com/guest271314/NativeMessagingHosts; Mozilla's jsshell and d8 have been challenging.

I downloaded the git repository and used npm to get this library. Not sure how to use it. So you have example usage instructions published in this repository or elsewhere?

@martenrichter
Copy link
Member

You mean for the binary part?
Not really... Most stuff is in the http3eventhandler.cc . It basically sends messages to different callbacks.
And beside this, it uses a standard nan class for communication between the threads. All are very node-specific.
The best documentation source is the files for typescript types as they document the native objects and messages.

@guest271314
Copy link
Author

WebSocketStream closes on ots own with {"code": 1001, "reason": "No response from ping frame."}. That's not going to work. I previously experimented with QuicTransport before renamed to WebTransport using aioquic, where I wasn't able to really stream. Ideally I would use fetch() for duplex streaming, now I have to send two requests to stream to and from a server. Since we can import C into QuickJS I was going to try to create a shared library of the quice code you isolated and and try to get this going in QuickJS for 5 MB.

@guest271314
Copy link
Author

You mean for the binary part?

No, I mean for the Node.js usage. How do I get this working as a server? I.e., run the tests once I have either used npm to fetch the package or downloaded the GitHub repository?

@guest271314
Copy link
Author

We should be able to call C++ quiche souce code in C https://github.com/guest271314/webserver-c/blob/quickjs-webserver/webserver.c.

@martenrichter
Copy link
Member

WebSocketStream closes on ots own with {"code": 1001, "reason": "No response from ping frame."}. That's not going to work. I previously experimented with QuicTransport before renamed to WebTransport using aioquic, where I wasn't able to really stream. Ideally I would use fetch() for duplex streaming, now I have to send two requests to stream to and from a server. Since we can import C into QuickJS I was going to try to create a shared library of the quice code you isolated and and try to get this going in QuickJS for 5 MB.

What has WebSocketStream to do with webtransport?

@martenrichter
Copy link
Member

You mean for the binary part?

No, I mean for the Node.js usage. How do I get this working as a server? I.e., run the tests once I have either used npm to fetch the package or downloaded the GitHub repository?

Use the echoserver.js in test as example how to use it. Beside this npm should handle all the downloading for you.

@guest271314
Copy link
Author

What has WebSocketStream to do with webtransport?

I'm trying to implement full duplex streaming. I tested WebSocketStream and fetch() with duplex:'half' to that end.

Use the echoserver.js in test as example how to use it. Beside this npm should handle all the downloading for you.

Node.js does not support Ecmascript import out of the box. We need to use .mjs extension for that to work without a package.json file

node echoserver.js
node:internal/errors:496
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'node-forge' imported from /home/xubuntu/localscripts/webtransport/test/fixtures/certificate.js
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:782:9)
    at moduleResolve (node:internal/modules/esm/resolve:831:20)
    at defaultResolve (node:internal/modules/esm/resolve:1036:11)
    at DefaultModuleLoader.resolve (node:internal/modules/esm/loader:252:12)
    at DefaultModuleLoader.getModuleJob (node:internal/modules/esm/loader:141:32)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:33)
    at link (node:internal/modules/esm/module_job:75:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v21.0.0-nightly202307177196946d7f

@martenrichter
Copy link
Member

It is merely an example code, so just copy it and add a package.json.
But for me most .js work without mjs and the error message just says that you are missing a package for the certificate generator.

@guest271314
Copy link
Author

I ran npm install . and got the echoserver.js running, then in a different terminal ran echoclient.js and got error.

Quic connection failed Error: Cl:Error: Connecting quic client failed
file:///home/user/webtransport/lib/webtransport.js:74
        sessionint.readyReject(new Error('Quic connection failed ' + error))
                               ^

Error: Quic connection failed Error: Cl:Error: Connecting quic client failed
    at file:///home/user/webtransport/lib/webtransport.js:74:32

It would be helpful to create a complete example connecting from the browser. I'll keep testing.

@martenrichter
Copy link
Member

LWell I do not have the time for a complete test example. Also the hardest part is generating the certificates. But the plugin works as I use it already in production.
The error message, I am afraid can be anything, you may want to increase the log level of libquiche with passing the option ""quicheLogVerbose" with an integer numerical value higher than the default "-1".

@guest271314
Copy link
Author

I have generated the certificate and key using this https://github.com/GoogleChrome/samples/blob/2bb27d915e3cbfe5ba4fc80fe4922baca16db703/webtransport/webtransport_server.py#L49-L72 when I experimented with aioquic. Did something change in WebTransport that would not allow the certificate and key generated from that to be passed to your library?

Just checked that sample code and it is broken now with this error message

 DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()

I'll keep trying on my own. If you find the time kindly create a minimal, complete, working example.

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