WebRTC基于node的实例

本博客通过一个实例展示了如何使用WebRTC在Node环境下建立实时通信。客户端包括index.html和client.js,部署在web服务器上。服务端是index.js,通过8888端口提供WebSocket服务。用户可以在两个浏览器窗口之间进行视频通话,实现一对一的远程连接。源码可在CSDN下载。
摘要由CSDN通过智能技术生成

客户端:

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <title>Learning WebRTC - Chapter 5: Connecting ClientsTogether</title> 
  <style>
body {
background-color: #3D6DF2;
margin-top: 15px;
font-family: sans-serif;
color: white;
}
video {
background: black;
border: 1px solid gray;
}
.page {
position: relative;
display: block;
margin: 0 auto;
width: 500px;
height: 500px;
}
#yours {
width: 150px;
height: 150px;
position: absolute;
top: 15px;
right: 15px;
}
#theirs {
width: 500px;
height: 500px;}
</style> 
 </head> 
 <body> 
  <div id="login-page" class="page"> 
   <h2>Login As</h2> 
   <input type="text" id="username" /> 
   <button id="login">Login</button> 
  </div> 
  <div id="call-page" class="page"> 
   <video id="yours" autoplay=""></video> 
   <video id="theirs" autoplay=""></video> 
   <input type="text" id="their-username" /> 
   <button id="call">Call</button> 
   <button id="hang-up">Hang Up</button> 
  </div> 
  <script src="client.js"></script>   
 </body>
</html>

client.js

var connection = new WebSocket('ws://192.168.2.119:8888'),
name = "";
var loginPage = document.querySelector('#login-page'),
usernameInput = document.querySelector('#username'),
loginButton = document.querySelector('#login'),
callPage = document.querySelector('#call-page'),
theirUsernameInput = document.querySelector('#their-username'),
callButton = document.querySelector('#call'),
hangUpButton = document.querySelector('#hang-up');
callPage.style.display = "none";
// Login wh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值