Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
* 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
najamelan committed Aug 2, 2019
2 parents 87dca8d + 613532d commit 297b7dd
Show file tree
Hide file tree
Showing 19 changed files with 1,563 additions and 130 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ pharos = "^0.2"
features = ["io-compat", "compat"]
version = "^0.3.0-alpha.17"

[dependencies.futures_01]
package = "futures"
version = "^0.1"

[dependencies.js-sys]
version = "^0.3"

[dependencies.naja_async_runtime]
default-features = false
version = "^0.2"
version = "^0.3"

[dependencies.wasm-bindgen]
version = "^0.2"
Expand All @@ -40,6 +36,10 @@ serde_cbor = "0.9.0"
tokio-serde-cbor = "0.3.1"
wasm-bindgen-test = "^0.2"

[dev-dependencies.futures_01]
package = "futures"
version = "^0.1"

[dev-dependencies.serde]
features = ["derive"]
version = "1.0.87"
Expand All @@ -61,4 +61,4 @@ license = "Unlicense"
name = "ws_stream_wasm"
readme = "README.md"
repository = "https://github.com/najamelan/ws_stream_wasm"
version = "0.1.0"
version = "0.2.0"
6 changes: 3 additions & 3 deletions Cargo.yml
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
Expand All @@ -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 }

Expand Down Expand Up @@ -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 }
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ WebSockets, check out [ws_stream](https://crates.io/crates/ws_stream).
## Table of Contents

- [Install](#install)
- [Upgrade](#upgrade)
- [Dependencies](#dependencies)
- [Usage](#usage)
- [API](#api)
- [API](#api)
- [References](#references)
- [Contributing](#contributing)
- [Code of Conduct](#code-of-conduct)
Expand All @@ -54,6 +55,10 @@ With raw Cargo.toml
ws_stream_wasm = "^0.1"
```

### Upgrade

Please check out the [changelog](https://github.com/najamelan/ws_wasm_stream/blob/master/CHANGELOG.md) when upgrading.

### Dependencies

This crate has few dependiencies. Cargo will automatically handle it's dependencies for you.
Expand Down Expand Up @@ -117,6 +122,7 @@ This repository accepts contributions. Ideas, questions, feature requests and bu

Pull Requests are welcome on github. By commiting pull requests, you accept that your code might be modified and reformatted to fit the project coding style or to improve the implementation. Please discuss what you want to see modified before filing a pull request if you don't want to be doing work that might be rejected.

Please file PR's against the `dev` branch, don't forget to update the changelog and the documentation.

### Testing

Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
- reconnect?

## Testing
- verify Cargo.yml + all dependencies

## Documentation
- chat client example
Expand Down
42 changes: 42 additions & 0 deletions examples/chat_client/Cargo.toml
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"
52 changes: 52 additions & 0 deletions examples/chat_client/Cargo.yml
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 ,
]
40 changes: 40 additions & 0 deletions examples/chat_client/README.md
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?
Loading

0 comments on commit 297b7dd

Please sign in to comment.