generated from security-union/yew-actix-template
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
VideoCallClient
into its own crate (#142)
* factor out connection, peer management, and packet handling code * clean up warnings about unused variables and results * make CameraEncoder::start() args consistent with the other encoders * Various cleanups and clippy * Pass VideoCallClient to encoders, remove on_packet callbacks * keep copy of aes in outer struct so no borrow() is needed to get it * Explicitly ensure peer before handling packet, rather than on-the-fly callback hell With some code cleanups along the way * Gratuitous cleanup: Better naming * Gratuitous cleanup: error enums & DRY some code * Gratuitous cleanup: factor out HashWithOrderedKeys * move yew-ui-src/model to videocall-client/src * Flesh out videocall-client crate definition, pull out dependencies Conform `use` statements in yew-ui to crate * cargo fmt * add wasm-unknown-unknown target to rust-toolchain.toml * clippy * Add documentation * Doc update: Mention that only Chrome is supported * Add do-not-edit note to README * Rebuild README * fix bad doc cross-references * move yew-ui-src/model to videocall-client/src * Flesh out videocall-client crate definition, pull out dependencies Conform `use` statements in yew-ui to crate * cargo fmt * add wasm-unknown-unknown target to rust-toolchain.toml * clippy * Add documentation * Doc update: Mention that only Chrome is supported * Add do-not-edit note to README * Rebuild README * fix bad doc cross-references
- Loading branch information
Showing
44 changed files
with
732 additions
and
248 deletions.
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 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 |
---|---|---|
|
@@ -5,5 +5,6 @@ members = [ | |
"bot", | ||
"src-tauri", | ||
"types", | ||
"videocall-client", | ||
"yew-ui" | ||
] |
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,92 @@ | ||
[package] | ||
name = "videocall-client" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
aes = "0.8.3" | ||
anyhow = "1" | ||
cbc = { version = "0.1.2", features = ["alloc"] } | ||
gloo = "0.8.0" | ||
gloo-timers = "0.2.6" | ||
gloo-utils = "0.1" | ||
js-sys = "0.3" | ||
log = "0.4.19" | ||
protobuf = "3.2.0" | ||
rand = { version = "0.8.5", features = ["std_rng", "small_rng"] } | ||
rsa = "0.9.2" | ||
types = { path= "../types"} | ||
wasm-bindgen = "0.2.78" | ||
wasm-bindgen-futures = "0.4.30" | ||
yew = { version = "0.20" } | ||
yew-websocket = "1.0.1" | ||
yew-webtransport = "0.3.2" | ||
|
||
[dependencies.web-sys] | ||
version = "0.3.60" | ||
features = [ | ||
"AudioTrack", | ||
"AudioData", | ||
"AudioEncoder", | ||
"AudioEncoderInit", | ||
"AudioEncoderConfig", | ||
"AudioDecoder", | ||
"AudioDecoderInit", | ||
"AudioDecoderConfig", | ||
"AudioContext", | ||
"BaseAudioContext", | ||
"GainOptions", | ||
"GainNode", | ||
"console", | ||
"CodecState", | ||
"CanvasRenderingContext2d", | ||
"EncodedAudioChunk", | ||
"EncodedAudioChunkInit", | ||
"EncodedAudioChunkType", | ||
"EncodedVideoChunk", | ||
"EncodedVideoChunkInit", | ||
"EncodedVideoChunkType", | ||
"MediaStreamAudioDestinationNode", | ||
"AudioDestinationNode", | ||
"AudioContextOptions", | ||
"AudioDataCopyToOptions", | ||
"HtmlCanvasElement", | ||
"HtmlImageElement", | ||
"Navigator", | ||
"MediaDevices", | ||
"MediaStream", | ||
"MediaStreamTrack", | ||
"MediaTrackSettings", | ||
"MediaStreamTrackProcessor", | ||
"MediaStreamTrackProcessorInit", | ||
"MediaStreamTrackGenerator", | ||
"MediaStreamTrackGeneratorInit", | ||
"WritableStream", | ||
"WritableStreamDefaultWriter", | ||
"MediaStreamAudioSourceNode", | ||
"HtmlVideoElement", | ||
"MediaStreamConstraints", | ||
"ReadableStream", | ||
"ReadableStreamGetReaderOptions", | ||
"ReadableStreamDefaultReader", | ||
"VideoEncoder", | ||
"VideoEncoderInit", | ||
"VideoEncoderConfig", | ||
"VideoEncoderEncodeOptions", | ||
"VideoFrame", | ||
"VideoTrack", | ||
"VideoDecoder", | ||
"VideoDecoderConfig", | ||
"VideoDecoderInit", | ||
"LatencyMode", | ||
"HtmlAudioElement", | ||
"AudioDataInit", | ||
"AudioSampleFormat", | ||
"TransformStream", | ||
"MediaDeviceInfo", | ||
"MediaDeviceKind", | ||
"MediaTrackConstraints", | ||
"CanvasRenderingContext2d" | ||
] |
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,93 @@ | ||
<!--- Do not manually edit README.md! The file is created automatically using 'cargo readme'. | ||
Changes should be made in: | ||
* src/lib.rs | ||
* README.tpl | ||
Rebuilding: | ||
$ cd videocall-client | ||
$ cargo readme > README.md | ||
---> | ||
|
||
# videocall-client | ||
|
||
Version: 0.1.0 | ||
|
||
--- | ||
|
||
This crate provides a client-side (browser) interface to the videocall protocol. The purpose is to | ||
take care of the media I/O both for the encoding the current participant and for rendering the | ||
media from the remote peers. It also provides tools for listing available media devices and | ||
granting access. | ||
|
||
This crate intends to make no assumptions about the UI or the HTML of the client app. | ||
The only DOM data it needs is the ID of the `HtmlVideoElement` for the participant's own video | ||
display and the ID's of the `HtmlCanvasElement`s into which remote peer video should be renderered. | ||
|
||
In addition to its use by Rust UI apps (e.g. via yew), it is intended that this crate be | ||
compiled to npm module that could be called from javascript, e.g. in an electron app. | ||
|
||
Currently, only the Chrome browser is supported, due to some of the Web APIs that are used. | ||
|
||
**NOTE:** This initial version is a slightly frankenstein result of piecemeal refactoring bits | ||
from the original app and stitching them together. It could use cleaning up both the API the | ||
internal design. | ||
|
||
## Outline of usage | ||
|
||
For more detailed documentation see the doc for each struct. | ||
|
||
### Client creation and connection: | ||
```rust | ||
let options = VideoCallClientOptions {...}; // set parameters and callbacks for various events | ||
let client = VideoCallClient::new(options); | ||
|
||
client.connect(); | ||
``` | ||
|
||
### Encoder creation: | ||
```rust | ||
let camera = CameraEncoder.new(client, video_element_id); | ||
let microphone = MicrophoneEncoder.new(client); | ||
let screen = ScreenEncoder.new(client); | ||
|
||
camera.select(video_device); | ||
camera.start(); | ||
camera.stop(); | ||
microphone.select(video_device); | ||
microphone.start(); | ||
microphone.stop(); | ||
screen.start(); | ||
screen.stop(); | ||
``` | ||
|
||
### Device access permission: | ||
|
||
```rust | ||
let media_device_access = MediaDeviceAccess::new(); | ||
media_device_access.on_granted = ...; // callback | ||
media_device_access.on_denied = ...; // callback | ||
media_device_access.request(); | ||
``` | ||
|
||
#### Device query and listing: | ||
```rust | ||
let media_device_list = MediaDeviceList::new(); | ||
media_device_list.audio_inputs.on_selected = ...; // callback | ||
media_device_access.video_inputs.on_selected = ...; // callback | ||
|
||
media_device_list.load(); | ||
|
||
let microphones = media_device_list.audio_inputs.devices(); | ||
let cameras = media_device_list.video_inputs.devices(); | ||
media_device_list.audio_inputs.select(µphones[i].device_id); | ||
media_device_list.video_inputs.select(&cameras[i].device_id); | ||
|
||
``` | ||
|
||
--- | ||
|
||
*Readme created using [cargo-readme](https://github.com/webern/cargo-readme) using [README.tpl](./README.tpl)* |
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,25 @@ | ||
<!--- Do not manually edit README.md! The file is created automatically using 'cargo readme'. | ||
Changes should be made in: | ||
* src/lib.rs | ||
* README.tpl | ||
Rebuilding: | ||
$ cd videocall-client | ||
$ cargo readme > README.md | ||
---> | ||
|
||
# {{crate}} | ||
|
||
Version: {{version}} | ||
|
||
--- | ||
|
||
{{readme}} | ||
|
||
--- | ||
|
||
*Readme created using [cargo-readme](https://github.com/webern/cargo-readme) using [README.tpl](./README.tpl)* |
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,3 @@ | ||
[toolchain] | ||
channel = "nightly-2023-01-27" | ||
targets = [ "wasm32-unknown-unknown" ] |
File renamed without changes.
Oops, something went wrong.