-
Notifications
You must be signed in to change notification settings - Fork 2
Implement websocket API #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
e7e5e60
implement websocket
afsalthaj 79c0a4a
implement websocket
afsalthaj 881d377
delete comments
afsalthaj 24b1906
Merge branch 'main' into web_socket
afsalthaj 7e0fad8
implement websocket stream, rexport all in node http, and enable vend…
afsalthaj e50bf74
Merge branch 'main' into web_socket
afsalthaj 014be2b
Merge branch 'main' into web_socket
afsalthaj 3c3a632
add golden files
afsalthaj 26da5ea
try fixing ci errors again
afsalthaj 2bf961f
try fixing ci errors again
afsalthaj aa7e860
use golem rust api
afsalthaj 2548f27
avoid changes in golem-rust
afsalthaj 9c1f8bd
separate crate for golem-websocket
afsalthaj bbe488d
reformat code
afsalthaj 71c0526
reformat code
afsalthaj f717e4c
remove assistant mistakes
afsalthaj cf3bd16
reformat and add docs
afsalthaj ec0a1ed
avoid golem feature gate for websocket
afsalthaj 35b7f3d
remove other pointless code
afsalthaj 3789eac
mock websocket
afsalthaj cc0a8ce
reformat code
afsalthaj 8b46903
remove stub for websocket
afsalthaj cd08044
revert
afsalthaj 8aeb0bd
Add define_unknown_imports_as_traps to handle WebSocket and other Gol…
afsalthaj 4ca1fd0
Revert "Add define_unknown_imports_as_traps to handle WebSocket and o…
afsalthaj 8a38448
add mock
afsalthaj 121516a
Merge remote-tracking branch 'origin/web_socket' into web_socket
afsalthaj a24e2ca
reformat code
afsalthaj acbb74c
Skip test-websocket-disabled.js as WebSocket is now always available
afsalthaj c5058a2
update README
afsalthaj e999d01
update README
afsalthaj f467974
remove comments
afsalthaj f785ee5
enable vendor tests
afsalthaj fffdccd
fix re-export
afsalthaj a9c36bc
try fixing tests
afsalthaj 299ce64
try fixing tests
afsalthaj 71dbe00
try fixing tests
afsalthaj 3b3c50e
fix more ci errors
afsalthaj d84d77c
Fix node:http WebSocket re-exports using lazy getters
afsalthaj bcfa1fb
reduce the chance of stack overflow
afsalthaj bb47559
Merge branch 'main' into web_socket
afsalthaj b238c5e
make golem-websocket under golem feature flag
afsalthaj bb22031
revert feature gate
afsalthaj f9abeab
Merge branch 'main' into web_socket
vigoo f6f7cf7
Feature gated websockets and updated to the latest golem wit interfaces
vigoo 29b9624
Proper async receive loop
vigoo 2f8a2e4
Fixes
vigoo 4a2264a
Git dependency for golem-websockets temporarily
vigoo ce126bc
Optimization
vigoo c3b4423
Fix
vigoo a99c707
Regenerated dts
vigoo 71dd581
Fix
vigoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [package] | ||
| name = "golem-websocket" | ||
| version = "0.0.2" | ||
| edition.workspace = true | ||
| license.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| description = "Packages golem:websocket as a simple Rust crate" | ||
|
|
||
| [dependencies] | ||
| wit-bindgen-rt = { version = "0.42.1" } | ||
| wit-bindgen = { version = "0.51.0", default-features = false, features = ["macros"] } | ||
| wasip2 = "1.0" | ||
|
|
||
| [package.metadata.component.target.dependencies] | ||
| "golem:websocket" = { path = "wit/deps/golem-websocket" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #[allow(unsafe_op_in_unsafe_fn)] | ||
| mod bindings { | ||
| wit_bindgen::generate!({ | ||
| world: "golem-websocket", | ||
| path: "wit", | ||
| generate_all, | ||
| pub_export_macro: true, | ||
| default_bindings_module: "crate::bindings", | ||
| with: { | ||
| "wasi:io/poll@0.2.3": wasip2::io::poll, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| pub use bindings::golem::websocket::client::{CloseInfo, Error, Message, WebsocketConnection}; |
51 changes: 51 additions & 0 deletions
51
crates/golem-websocket/wit/deps/golem-websocket/websocket.wit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package golem:websocket@1.5.0; | ||
|
|
||
| interface client { | ||
| use wasi:io/poll@0.2.3.{pollable}; | ||
|
|
||
| variant error { | ||
| connection-failure(string), | ||
| send-failure(string), | ||
| receive-failure(string), | ||
| protocol-error(string), | ||
| closed(option<close-info>), | ||
| other(string), | ||
| } | ||
|
|
||
| record close-info { | ||
| code: u16, | ||
| reason: string, | ||
| } | ||
|
|
||
| /// A WebSocket message — text or binary | ||
| variant message { | ||
| text(string), | ||
| binary(list<u8>), | ||
| } | ||
|
|
||
| /// A WebSocket connection resource | ||
| resource websocket-connection { | ||
| /// Connect to a WebSocket server at the given URL (ws:// or wss://) | ||
| /// Optional headers for auth, subprotocols, etc. | ||
| connect: static func( | ||
| url: string, | ||
| headers: option<list<tuple<string, string>>> | ||
| ) -> result<websocket-connection, error>; | ||
|
|
||
| /// Send a message (text or binary) | ||
| send: func(message: message) -> result<_, error>; | ||
|
|
||
| /// Receive the next message (blocks until available) | ||
| receive: func() -> result<message, error>; | ||
|
|
||
| /// Receive the next message with a timeout in milliseconds. | ||
| /// Returns none if the timeout expires before a message arrives. | ||
| receive-with-timeout: func(timeout-ms: u64) -> result<option<message>, error>; | ||
|
|
||
| /// Send a close frame with optional code and reason | ||
| close: func(code: option<u16>, reason: option<string>) -> result<_, error>; | ||
|
|
||
| /// Returns a pollable that resolves when a message is available to read | ||
| subscribe: func() -> pollable; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package wasi:io@0.2.3; | ||
|
|
||
| /// A poll API intended to let users wait for I/O events on multiple handles | ||
| /// at once. | ||
| @since(version = 0.2.0) | ||
| interface poll { | ||
| /// `pollable` represents a single I/O event which may be ready, or not. | ||
| @since(version = 0.2.0) | ||
| resource pollable { | ||
|
|
||
| /// Return the readiness of a pollable. This function never blocks. | ||
| /// | ||
| /// Returns `true` when the pollable is ready, and `false` otherwise. | ||
| @since(version = 0.2.0) | ||
| ready: func() -> bool; | ||
|
|
||
| /// `block` returns immediately if the pollable is ready, and otherwise | ||
| /// blocks until ready. | ||
| /// | ||
| /// This function is equivalent to calling `poll.poll` on a list | ||
| /// containing only this pollable. | ||
| @since(version = 0.2.0) | ||
| block: func(); | ||
| } | ||
|
|
||
| /// Poll for completion on a set of pollables. | ||
| /// | ||
| /// This function takes a list of pollables, which identify I/O sources of | ||
| /// interest, and waits until one or more of the events is ready for I/O. | ||
| /// | ||
| /// The result `list<u32>` contains one or more indices of handles in the | ||
| /// argument list that is ready for I/O. | ||
| /// | ||
| /// This function traps if either: | ||
| /// - the list is empty, or: | ||
| /// - the list contains more elements than can be indexed with a `u32` value. | ||
| /// | ||
| /// A timeout can be implemented by adding a pollable from the | ||
| /// wasi-clocks API to the list. | ||
| /// | ||
| /// This function does not return a `result`; polling in itself does not | ||
| /// do any I/O so it doesn't fail. If any of the I/O sources identified by | ||
| /// the pollables has an error, it is indicated by marking the source as | ||
| /// being ready for I/O. | ||
| @since(version = 0.2.0) | ||
| poll: func(in: list<borrow<pollable>>) -> list<u32>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package golem-websocket-rust:golem-websocket; | ||
|
|
||
| world golem-websocket { | ||
| import golem:websocket/client@1.5.0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be feature gated with
golemThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I actually tried it, but golemcloud/golem#3076 was failing with "Websocket not found". I guess the generated crate during base-wasm generation in Golem has only "normal" features included. I will try and understand a bit more soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, #83 (comment) answered that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#83 (comment)