提交 5e7d81ff authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Fix `videoroom` example backend to use the same router for all participants of…

Fix `videoroom` example backend to use the same router for all participants of the room, implement frontend
上级 244ef887
module.exports = {
env : {
browser : true,
es6 : true
},
parserOptions : {
project : 'tsconfig.json',
sourceType : 'module'
}
};
<!doctype html>
<style>
body {
margin: 0;
}
#container {
display: flex;
}
figure {
margin: 0;
width: 30vw;
}
video {
max-width: 100%;
}
</style>
<div id="container">
<figure>
<video id="preview-send" muted controls></video>
<figcaption>You</figcaption>
</figure>
</div>
<script src="dist/bundle.js">
</script>
{
"version": "0.0.0",
"private": true,
"engines": {
"node": ">=14.8"
},
"scripts": {
"start": "webpack serve"
},
"author": "Nazar Mokrynskyi <nazar@mokrynskyi.com>",
"dependencies": {
"mediasoup-client": "^3.6.36"
},
"devDependencies": {
"ts-loader": "^9.2.4",
"typescript": "^4.3.5",
"webpack": "^5.46.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
}
}
差异被折叠。
{
"compilerOptions": {
"module": "es6",
"target": "es2018",
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": false,
"sourceRoot": "src",
"baseUrl": "src",
"outDir": "dist",
"strict": true,
"noUnusedParameters": true,
"noUnusedLocals": true,
"lib": [
"es5",
"es2015",
"es2019",
"dom"
]
},
"include": [
"src",
".eslintrc.js",
"webpack.config.js"
]
}
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
module.exports = {
mode : 'development',
entry : './src/index.ts',
module : {
rules : [
{
test : /\.ts$/,
use : 'ts-loader',
exclude : /node_modules/
}
]
},
resolve : {
extensions : [ '.ts', '.js' ]
},
output : {
filename : 'dist/bundle.js',
path : path.resolve(__dirname, 'dist')
},
devServer : {
liveReload : false,
port : 3001
}
};
...@@ -237,11 +237,11 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for EchoConnection { ...@@ -237,11 +237,11 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for EchoConnection {
ctx.address().do_send(message); ctx.address().do_send(message);
} }
Err(error) => { Err(error) => {
eprint!("Failed to parse client message: {}\n{}", error, text); eprintln!("Failed to parse client message: {}\n{}", error, text);
} }
}, },
Ok(ws::Message::Binary(bin)) => { Ok(ws::Message::Binary(bin)) => {
eprint!("Unexpected binary message: {:?}", bin); eprintln!("Unexpected binary message: {:?}", bin);
} }
Ok(ws::Message::Close(reason)) => { Ok(ws::Message::Close(reason)) => {
ctx.close(reason); ctx.close(reason);
...@@ -278,7 +278,7 @@ impl Handler<ClientMessage> for EchoConnection { ...@@ -278,7 +278,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("Producer transport connected"); println!("Producer transport connected");
} }
Err(error) => { Err(error) => {
eprint!("Failed to connect producer transport: {}", error); eprintln!("Failed to connect producer transport: {}", error);
address.do_send(InternalMessage::Stop); address.do_send(InternalMessage::Stop);
} }
} }
...@@ -306,7 +306,7 @@ impl Handler<ClientMessage> for EchoConnection { ...@@ -306,7 +306,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("{:?} producer created: {}", kind, id); println!("{:?} producer created: {}", kind, id);
} }
Err(error) => { Err(error) => {
eprint!("Failed to create {:?} producer: {}", kind, error); eprintln!("Failed to create {:?} producer: {}", kind, error);
address.do_send(InternalMessage::Stop); address.do_send(InternalMessage::Stop);
} }
} }
...@@ -326,7 +326,7 @@ impl Handler<ClientMessage> for EchoConnection { ...@@ -326,7 +326,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("Consumer transport connected"); println!("Consumer transport connected");
} }
Err(error) => { Err(error) => {
eprint!("Failed to connect consumer transport: {}", error); eprintln!("Failed to connect consumer transport: {}", error);
address.do_send(InternalMessage::Stop); address.do_send(InternalMessage::Stop);
} }
} }
...@@ -365,7 +365,7 @@ impl Handler<ClientMessage> for EchoConnection { ...@@ -365,7 +365,7 @@ impl Handler<ClientMessage> for EchoConnection {
println!("{:?} consumer created: {}", kind, id); println!("{:?} consumer created: {}", kind, id);
} }
Err(error) => { Err(error) => {
eprint!("Failed to create consumer: {}", error); eprintln!("Failed to create consumer: {}", error);
address.do_send(InternalMessage::Stop); address.do_send(InternalMessage::Stop);
} }
} }
......
...@@ -10,4 +10,13 @@ In order to run server-side part of examples (this directory) use `cargo run --e ...@@ -10,4 +10,13 @@ In order to run server-side part of examples (this directory) use `cargo run --e
Simple echo example that receives audio+video from the client and sends audio+video back to the client via different Simple echo example that receives audio+video from the client and sends audio+video back to the client via different
transport. Frontend part of this example is in `examples-frontend/echo` directory. transport. Frontend part of this example is in `examples-frontend/echo` directory.
Check WebSocket messages in browser DevTools for better understanding of what is happening under the hood. Check WebSocket messages in browser DevTools for better understanding of what is happening under the hood, also source
code has a bunch of comments about what is happening and where changes would be needed for production use.
# Video room
A bit more advanced example that allow multiple participants to join the same virtual room and receive audio+video from
other participants, resulting in a simple video conferencing setup. Frontend part of this example is in
`examples-frontend/videoroom` directory.
Check WebSocket messages in browser DevTools for better understanding of what is happening under the hood, also source
code has a bunch of comments about what is happening and where changes would be needed for production use.
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论