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

Add WebSocket plugin #1092

Merged
merged 5 commits into from
Aug 18, 2022
Merged

Add WebSocket plugin #1092

merged 5 commits into from
Aug 18, 2022

Conversation

fetsorn
Copy link
Contributor

@fetsorn fetsorn commented Aug 2, 2022

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 and removeCallback to stop. The callback function is expected to have a parameter data, 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 and removeCache to stop. Use receive 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.

Niraj-Kamdar
Niraj-Kamdar previously approved these changes Aug 10, 2022
Copy link
Contributor

@Niraj-Kamdar Niraj-Kamdar left a 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?

Comment on lines +21 to +24
# optional fields are `Number | null` instead of `Option<i32>`
type Number {
value: Int!
}
Copy link
Contributor

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?

Copy link
Contributor Author

@fetsorn fetsorn Aug 10, 2022

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.

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

@dOrgJelli dOrgJelli merged commit d7f896d into origin-dev Aug 18, 2022
@dOrgJelli dOrgJelli deleted the fetsorn/575-websocket-plugin branch August 22, 2022 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants