-
Notifications
You must be signed in to change notification settings - Fork 52
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
Add WebSocket plugin #1092
Add WebSocket plugin #1092
Conversation
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.
LGTM! Can you reply on my comment?
# optional fields are `Number | null` instead of `Option<i32>` | ||
type Number { | ||
value: Int! | ||
} |
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.
Why are we doing this?
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.
Optional Int is currently implemented as Option<i32>
in wasm and schema/bind.
But to omit optional fields from the function parameters we need a | null
union type.
So we wrap Int in a reference type and make it optional, Number | null
.
I mentioned this in #944, but now I think we might want to implement Optional Int as Option<i32> | null
and always use null instead of Option.None<i32>()
, to no longer require wrapping such as this one.
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.
Why don't we use Box instead in that case?
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.
i.e. Box<i32> | null
instead of Option<i32> | null
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.
Exactly, created an issue for that #1132.
Resolves #575. WebSocket plugin allows Polywrap Client to interact with WebSocket servers.
Every incoming WebSocket message can be passed to a callback function in another wrapper. Use
addCallback
to start passing messages andremoveCallback
to stop. The callback function is expected to have a parameterdata
, i.e.foo(data: string)
.Incoming WebSocket messages can also be stored in the plugin and retrieved as an array later. Use
addCache
to start caching messages andremoveCache
to stop. Usereceive
to get an array of cached messages and empty the cache. Optionally, wait for a timeout, or a minimum number of cached messages before retrieving the array.See the README.md and src/tests/e2e/e2e.spec.ts for more info.