【转载请注明出处: http://blog.csdn.net/leytton/article/details/76836265】

 PS:如果本文对您有帮助,请点个赞让我知道哦~

《WebRTC实时通信系列教程》翻译自《Real time communication with WebRTC》

示例代码下载http://download.csdn.net/detail/leytton/9923708

WebRTC实时通信系列教程1 介绍

WebRTC实时通信系列教程2 概述

WebRTC实时通信系列教程3 获取示例代码

WebRTC实时通信系列教程4 从摄像头获取视频流

WebRTC实时通信系列教程5 RTCPeerConnection传输视频

WebRTC实时通信系列教程6 使用RTCDataChannel传输数据

WebRTC实时通信系列教程7 使用Socket.IO搭建信令服务器交换信息

WebRTC实时通信系列教程8 打通P2P连接和信令通信

WebRTC实时通信系列教程9 数据通道图片传输

WebRTC实时通信系列教程10 恭喜完成本系列课程

一、译文

1、你将学到

  • 使用Socket.IO在Node.js上运行一个WebRTC服务
  • 使用信令服务在WebRTC客户端之间交换元数据.

完整示例代码在 step-05 目录下.

2、HTML和JavaScript代码

index.html 文件:

<!DOCTYPE html>
<html><head><title>Realtime communication with WebRTC</title><link rel="stylesheet" href="/css/main.css" /></head><body><h1>Realtime communication with WebRTC</h1><div id="videos"><video id="localVideo" autoplay muted></video><video id="remoteVideo" autoplay></video></div><script src="/socket.io/socket.io.js"></script><script src="js/lib/adapter.js"></script><script src="js/main.js"></script></body></html>

将 main.js 文件内容替换成 step-05/js/main.js 里的内容.

3、运行Node服务器

在 work 目录下使用以下命令行运行Node服务器:

node index.js

(确保你使用的的 index.js 文件中是上一节中实现了Socket.IO的代码.)

浏览器打开 localhost:8080.

在新标签中再次打开 localhost:8080 .一个video标签将会用于展示 getUserMedia() 获取到的视频流另一个video标签将会用于展示 RTCPeerconnection 获取到的远程视频流.

注意:每次关闭一个客户端标签或窗口后你需要重启Node服务器.

在浏览器JavaScript控制台查看日志输出.

4、拓展

  1. 这个应用仅支持一对一视频聊天. 你如何设计一个房间内的多人视频聊天?
  2. 示例代码中房间名foo是写死的. 如何更好地支持其他房间名?
  3. 用户之间如何分享房间名? 尝试设计分享房间名的方案.
  4. 你能够如何改变扩展这个应用呢

5、你学到的

  • 使用Socket.IO在Node.js上运行一个WebRTC服务
  • 使用信令服务在WebRTC客户端之间交换元数据.

完整示例代码在 step-05 目录下.

6、建议

  • 你可以在 chrome://webrtc-internals 链接中查看WebRTC统计调试数据.
  • 可以用 test.webrtc.org 网页来检测你的PC或者手机浏览器是否支持WebRTC本地环境和调用摄像头.
  • 如果因为缓存问题导致错误,可以尝试:
  • 刷新网页
  • 重启浏览器
  • 执行 npm cache clean 命令.

7、下一节

拍照并获取图片数据,传输到远程客户端.

二、原文

摘自https://codelabs.developers.google.com/codelabs/webrtc-web/#7

8. Combine peer connection and signaling

What you'll learn

In this step you'll find out how to:

  • Run a WebRTC signaling service using Socket.IO running on Node.js
  • Use that service to exchange WebRTC metadata between peers.

A complete version of this step is in the step-05 folder.

Replace HTML and JavaScript

Replace the contents of index.html with the following:

<!DOCTYPE html>
<html><head><title>Realtime communication with WebRTC</title><link rel="stylesheet" href="/css/main.css" /></head><body><h1>Realtime communication with WebRTC</h1><div id="videos"><video id="localVideo" autoplay muted></video><video id="remoteVideo" autoplay></video></div><script src="/socket.io/socket.io.js"></script><script src="js/lib/adapter.js"></script><script src="js/main.js"></script></body></html>

Replace js/main.js with the contents of step-05/js/main.js.

Run the Node server

If your Node server is not running, start it by calling the following command in the work directory

node index.js

(Make sure you're using the version of index.js from the previous step that implements Socket.IO.)

From your browser, open localhost:8080.

Open localhost:8080 again, in a new tab or window. One video element will display the local stream fromgetUserMedia()and the other will show the 'remote' video streamed via RTCPeerconnection.

You'll need to restart your Node server each time you close a client tab or window.

View logging in the browser console.

Bonus points

  1. This application supports only one-to-one video chat. How might you change the design to enable more than one person to share the same video chat room?
  2. The example has the room name foo hard coded. What would be the best way to enable other room names?
  3. How would users share the room name? Try to build an alternative to sharing room names.
  4. How could you change the app

What you learned

In this step you learned how to:

  • Run a WebRTC signaling service using Socket.IO running on Node.js
  • Use that service to exchange WebRTC metadata between peers.

A complete version of this step is in the step-05 folder.

Tips

  • WebRTC stats and debug data are available from chrome://webrtc-internals.
  • test.webrtc.org can be used to check your local environment and test your camera and microphone.
  • If you have odd troubles with caching, try the following:
  • Do a hard refresh by holding down ctrl and clicking the Reload button
  • Restart the browser
  • Run npm cache clean from the command line.

Next up

Find out how to take a photo, get the image data, and share that between remote peers.

WebRTC实时通信系列教程8 打通P2P连接和信令通信相关推荐

  1. WebRTC实时通信系列教程9 数据通道图片传输

    [转载请注明出处: http://blog.csdn.net/leytton/article/details/76838194]  PS:如果本文对您有帮助,请点个赞让我知道哦~ <WebRTC ...

  2. ClickHouse 系列教程五:多种连接方法

    文章目录 clickhouse-client HTTP 接口 JDBC Python接口 ClickHouse系列教程: ClickHouse系列教程 clickhouse-client 你可以通过c ...

  3. 西门子smartclient怎么用_基于Snap7使用C#编程访问西门子PLC系列教程(3)-Snap7Client(建立连接)...

    本文是Snap7软件包系列教程的第3篇. 在上一篇文章中,我们介绍了S7通信协议中有三种角色:客户端/服务器/伙伴:有两种通信模式:客户端/服务器(Client/Server)模式和伙伴/伙伴(Par ...

  4. Android Webrtc使用Wifi Direct无法建立P2P连接

    问题描述: 两个安卓设备之间已经完成WiFi直连,但是依旧无法使用webrtc建立peer connection连接,也就无法实时传输媒体数据. 原因: 根据log调查后发现,主要的失败的原因在于此处 ...

  5. WebRTC:P2P 连接过程完全解析

    宏观流程: 设置 local sdp: 创建一个 transport 对象(启用了 bundle): 收集 local candidates: 设置 remote sdp,添加 remote cand ...

  6. ClickHouse系列教程

    ClickHouse系列教程一:Debian/Ubuntu 下ClickHouse的安装和使用 ClickHouse系列教程二:使用航班飞行数据 ClickHouse系列教程三:MergeTree引擎 ...

  7. Android WebRTC 入门教程(二) -- 模拟p2p本地视频传输

    Android WebRTC 入门教程(一) – 使用相机 Android WebRTC 入门教程(二) – 模拟p2p本地视频传输 源码工程: https://github.com/LillteZh ...

  8. 乐鑫代理启明云端分享|ESP32系列教程之三: VS Code远程连接Linux

    提示:本文档为ESP32教程系列,旨在为客户进行ESP32系列芯片开发提供环境搭建.工程示例演示等方面的参考文档及视频演示,降低ESP32系列芯片.模组开发的入门难度. ESP32教程系列文档主要参考 ...

  9. (二)树莓派系列教程:树莓派4B手动连接wifi,远程控制。命令行界面、桌面界面

    一.通过连接同一局域网的wifi来远程操作树莓派 在树莓派系列教程(一)中我们在烧录系统的时候已经配置了树莓派在开机时候按优先级来裂解wifi.但是如果我们没有配置wifi的文件,我们可以手动连接wi ...

最新文章

  1. 1024 程序员节专题论坛来袭,权威解读 MindSpore、CANN 5.0 特性和 HCIA MDC 开发者认证...
  2. vsFTPd 服务器初学者指南
  3. Thread class vs Runnnable interface(转)
  4. mysql能否在手机端运行_在手机上安装linux并部署mysql,jupyter用于数据探索
  5. IOS+Android马甲包封装上架!
  6. c并非所有的代码路径都返回值_两行C语言代码播放音乐,就这么so easy!你学到了吗?...
  7. linux startx无法启动
  8. 深入理解磁盘文件系统之inode
  9. 中国酒精拭子市场趋势报告、技术动态创新及市场预测
  10. 三招快速搞定 Linux 文件批量重命名!
  11. java 线程释放_如何手动释放一个java线程占用的资源
  12. IDA的新手入门指南
  13. 2.16 自定义快速访问工具栏以提升工作效率 [原创Excel教程]
  14. qt.qpa.plugin: Could not load the Qt platform plugin “xcb“ in
  15. 8款实用的Jquery瀑布流插件
  16. 如何用puttygen由pem生成ppk
  17. Redis单线程和多线程
  18. Spreadsheet电子表格控件安装及用法总结
  19. Spring Web Flow 2中的流管理持久性
  20. cocos creator 做一个涂鸦跳跃

热门文章

  1. LibreCAD for windows 编译
  2. Vdbench存储测试教程
  3. 完美定制你的QQ,把QQ里不要的文件通通删除!
  4. 什么样的企业需要舆情优化系统?什么样的企业需要手工监测?
  5. 基于BP神经网络飞机颠簸预测
  6. Python实现的一个简洁轻快的后台管理框架.支持拥有多用户组的RBAC管理后台,不用配置各种运行环境
  7. 关于executeUpdate方法返回的值问题
  8. 回测好,为什么实盘不靠谱?
  9. 简述created和mounted的区别
  10. JSP设置Excel表格换行_Excel表格技巧—如何调整工作表打印页面设置