-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dev: (22 commits) chat example: Working Disconnect button Bump version to 0.2.0 Fix: Correctly wake up tasks waiting for a next message if the connection gets closed externally. chat example: fix reset button chat example: Connect form chat example: nicks must be unique and valid chat example: Show times before messages chat example: Only log in debug builds show available commands chat example: Don't autoscroll if the user scrolled up chat example: get rid of Wire intermediary format chat example: Working user list on right, chat input textarea focuses and submits on enter chat example: refactor in files and allow submit with Enter chat example: make event available to listeners and refocus textarea after submit chat example: Make a cleaner wire format Add readme for chat client example Working chat client Clarify contribution guidelines Remove 'static bound from closures and remove allow( dead_code ) We are receiving a message from the chat server ...
- Loading branch information
Showing
19 changed files
with
1,563 additions
and
130 deletions.
There are no files selected for viewing
This file contains 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,9 @@ | ||
# Changelog | ||
|
||
## 0.2 - 2019-08-02 | ||
|
||
- **BREAKING CHANGE**: Fix: Correctly wake up tasks waiting for a next message if the connection gets closed externally. | ||
This prevents these tasks from hanging indefinitely. | ||
As a consequence, `WsStream::close` now returns a `Result`, taking into account that if the connection is already | ||
closed, we don't have the `CloseEvent`. Instead a `WsErr` of kind `WsErrKind::ConnectionNotOpen` is returned. | ||
- update to async_runtime 0.3 |
This file contains 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 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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package: | ||
|
||
name : ws_stream_wasm | ||
version : 0.1.0 | ||
version : 0.2.0 | ||
edition : '2018' | ||
authors : [ Naja Melan <[email protected]> ] | ||
description : A convenience library for using websockets in WASM | ||
|
@@ -18,11 +18,10 @@ dependencies: | |
|
||
bitflags : ^1 | ||
pharos : ^0.2 | ||
naja_async_runtime : { version: ^0.2, default-features: false } | ||
naja_async_runtime : { version: ^0.3, default-features: false } | ||
failure : ^0.1 | ||
futures-preview : { version: ^0.3.0-alpha.17, features: [io-compat, compat] } | ||
log : ^0.4 | ||
futures_01 : { version: ^0.1, package: futures } | ||
js-sys : { version: ^0.3 } | ||
wasm-bindgen : { version: ^0.2 } | ||
|
||
|
@@ -55,3 +54,4 @@ dev-dependencies: | |
flexi_logger : ^0.11 | ||
futures_codec : ^0.2 | ||
wasm-bindgen-test : ^0.2 | ||
futures_01 : { version: ^0.1, package: futures } |
This file contains 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 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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
- reconnect? | ||
|
||
## Testing | ||
- verify Cargo.yml + all dependencies | ||
|
||
## Documentation | ||
- chat client example | ||
|
This file contains 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,42 @@ | ||
# Auto-generated from "Cargo.yml" | ||
[dependencies] | ||
console_error_panic_hook = "^0.1" | ||
futures_codec = "^0.2" | ||
js-sys = "^0.3" | ||
log = "^0.4" | ||
regex = "^1" | ||
wasm-bindgen = "^0.2" | ||
wasm-logger = "^0.1" | ||
|
||
[dependencies.chat_format] | ||
git = "https://github.com/najamelan/ws_stream" | ||
|
||
[dependencies.futures-preview] | ||
features = ["io-compat", "compat"] | ||
version = "^0.3.0-alpha.17" | ||
|
||
[dependencies.gloo-events] | ||
git = "https://github.com/rustwasm/gloo" | ||
|
||
[dependencies.naja_async_runtime] | ||
default-features = false | ||
version = "^0.3" | ||
|
||
[dependencies.web-sys] | ||
features = ["console", "CssStyleDeclaration", "Document", "Element", "HtmlDivElement", "HtmlElement", "HtmlFormElement", "HtmlInputElement", "HtmlParagraphElement", "HtmlTextAreaElement", "KeyboardEvent", "Node", "Window"] | ||
version = "^0.3" | ||
|
||
[dependencies.ws_stream_wasm] | ||
path = "../../" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
path = "src/entrypoint.rs" | ||
|
||
[package] | ||
authors = ["Naja Melan <[email protected]>"] | ||
description = "An example for using websockets in rust WASM." | ||
edition = "2018" | ||
name = "ws_stream_wasm_chat_client" | ||
repository = "https::/github.com/najamelan/async_runtime" | ||
version = "0.1.0" |
This file contains 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,52 @@ | ||
package: | ||
|
||
name : ws_stream_wasm_chat_client | ||
version : 0.1.0 | ||
authors : [ Naja Melan <[email protected]> ] | ||
edition : '2018' | ||
description: An example for using websockets in rust WASM. | ||
repository : https::/github.com/najamelan/async_runtime | ||
|
||
|
||
lib: | ||
|
||
crate-type : [ cdylib ] | ||
path : src/entrypoint.rs | ||
|
||
|
||
dependencies: | ||
|
||
console_error_panic_hook: ^0.1 | ||
chat_format : { git: "https://github.com/najamelan/ws_stream" } | ||
naja_async_runtime : { version: ^0.3, default-features: false } | ||
ws_stream_wasm : { path: ../../ } | ||
wasm-bindgen : ^0.2 | ||
futures_codec : ^0.2 | ||
futures-preview : { version: ^0.3.0-alpha.17, features: [io-compat, compat] } | ||
log : ^0.4 | ||
gloo-events : { git: "https://github.com/rustwasm/gloo" } | ||
wasm-logger : ^0.1 | ||
regex : ^1 | ||
js-sys : ^0.3 | ||
|
||
|
||
web-sys: | ||
|
||
version : ^0.3 | ||
|
||
features : | ||
[ | ||
console , | ||
CssStyleDeclaration , | ||
Document , | ||
Element , | ||
HtmlDivElement , | ||
HtmlElement , | ||
HtmlFormElement , | ||
HtmlInputElement , | ||
HtmlParagraphElement, | ||
HtmlTextAreaElement , | ||
KeyboardEvent , | ||
Node , | ||
Window , | ||
] |
This file contains 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,40 @@ | ||
# Ws_stream_wasm chat client example | ||
|
||
Demonstration of `ws_stream_wasm` working in WASM. This example shows a rather realistic (error handling, security, basic features) chat client that communicates with a chat server over websockets. The communication with the server happens with | ||
a custom enum, serialized with a cbor codec (for futures-codec, not tokio), over AsyncRead/AsyncWrite 0.3. | ||
|
||
What ws_stream_wasm adds here is that we just frame the connection with a codec instead of manually serializing our | ||
data structure, creating a websocket message with `web_sys`, and deal with all the potential errors on the connection | ||
by hand. | ||
|
||
## Install | ||
|
||
This requires you to run the chat_server example from [ws_stream](https://github.com/najamelan/ws_stream). You can tweak | ||
the ip:port to something else if you want (for the server you can pass it on the cmd line, for the client it's hard coded). | ||
|
||
You will need wasm-pack: | ||
```bash | ||
cargo install wasm-pack | ||
|
||
# and compile the client | ||
# | ||
wasm-pack build --release --target web | ||
|
||
# in ws_stream repo | ||
# make sure this is running in the same network namespace as your browser | ||
# | ||
cargo run --example chat_server --release | ||
``` | ||
|
||
## Usage | ||
|
||
Now you can open the `index.html` from this crate in several web browser tabs and chat away. | ||
|
||
|
||
## TODO | ||
- disconnect button | ||
- server side disconnect | ||
- reread all code and cleanup | ||
- document as example | ||
- gui | ||
- blog post? |
Oops, something went wrong.