- 浏览: 1442522 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (691)
- linux (207)
- shell (33)
- java (42)
- 其他 (22)
- javascript (33)
- cloud (16)
- python (33)
- c (48)
- sql (12)
- 工具 (6)
- 缓存 (16)
- ubuntu (7)
- perl (3)
- lua (2)
- 超级有用 (2)
- 服务器 (2)
- mac (22)
- nginx (34)
- php (2)
- 内核 (2)
- gdb (13)
- ICTCLAS (2)
- mac android (0)
- unix (1)
- android (1)
- vim (1)
- epoll (1)
- ios (21)
- mysql (3)
- systemtap (1)
- 算法 (2)
- 汇编 (2)
- arm (3)
- 我的数据结构 (8)
- websocket (12)
- hadoop (5)
- thrift (2)
- hbase (1)
- graphviz (1)
- redis (1)
- raspberry (2)
- qemu (31)
- opencv (4)
- socket (1)
- opengl (1)
- ibeacons (1)
- emacs (6)
- openstack (24)
- docker (1)
- webrtc (11)
- angularjs (2)
- neutron (23)
- jslinux (18)
- 网络 (13)
- tap (9)
- tensorflow (8)
- nlu (4)
- asm.js (5)
- sip (3)
- xl2tp (5)
- conda (1)
- emscripten (6)
- ffmpeg (10)
- srt (1)
- wasm (5)
- bert (3)
- kaldi (4)
- 知识图谱 (1)
最新评论
-
wahahachuang8:
我喜欢代码简洁易读,服务稳定的推送服务,前段时间研究了一下go ...
websocket的helloworld -
q114687576:
http://www.blue-zero.com/WebSoc ...
websocket的helloworld -
zhaoyanzimm:
感谢您的分享,给我提供了很大的帮助,在使用过程中发现了一个问题 ...
nginx的helloworld模块的helloworld -
haoningabc:
leebyte 写道太NB了,期待早日用上Killinux!么 ...
qemu+emacs+gdb调试内核 -
leebyte:
太NB了,期待早日用上Killinux!
qemu+emacs+gdb调试内核
2020年5月9日更新,5年前的例子运行不了了,更新下html
主要是chrome的URL的api变了
在mac的chrome上
把 document.getElementById('remoteVideo').src = window.URL.createObjectURL(event.stream);
改成
document.getElementById('remoteVideo').srcObject = event.stream;
参考:https://stackoverflow.com/questions/27120757/failed-to-execute-createobjecturl-on-url
视频和datachannel一起使用的两个页面的例子
网上的datachannel只能在一个页面,
根据视频的改了下两个页面可以传数据了
疑问:ondatachannel似乎没用上
先打开192.168.137.27:8081/js/webrtc2.html
另一台电脑打开
192.168.137.27:8081/js/webrtc2.html#true
视频正确两个都显示了才正确,
websocket三个页面有问题,没优化
server.js
webrtc2.html
主要是chrome的URL的api变了
在mac的chrome上
把 document.getElementById('remoteVideo').src = window.URL.createObjectURL(event.stream);
改成
document.getElementById('remoteVideo').srcObject = event.stream;
参考:https://stackoverflow.com/questions/27120757/failed-to-execute-createobjecturl-on-url
视频和datachannel一起使用的两个页面的例子
网上的datachannel只能在一个页面,
根据视频的改了下两个页面可以传数据了
疑问:ondatachannel似乎没用上
先打开192.168.137.27:8081/js/webrtc2.html
另一台电脑打开
192.168.137.27:8081/js/webrtc2.html#true
视频正确两个都显示了才正确,
websocket三个页面有问题,没优化
server.js
//http://www.blogjava.net/linli/archive/2014/10/21/418910.html var express = require('express'), app = express(), server = require('http').createServer(app); server.listen(3000); app.get('/', function(req, res) { res.sendfile(__dirname + '/webrtc.html'); }); var WebSocketServer = require('ws').Server, wss = new WebSocketServer({server: server}); function writeObj(obj){ var description = ""; for(var i in obj){ var property=obj[i]; description+=i+" = "+property+"\n"; } console.log(description); } // 存储socket的数组,这里只能有2个socket,每次测试需要重启,否则会出错 var wsc = [], index = 1; // 有socket连入 wss.on('connection', function(ws) { console.log('connection:'); //writeObj(ws); // 将socket存入数组 wsc.push(ws); // 记下对方socket在数组中的下标,因为这个测试程序只允许2个socket // 所以第一个连入的socket存入0,第二个连入的就是存入1 // otherIndex就反着来,第一个socket的otherIndex下标为1,第二个socket的otherIndex下标为0 var otherIndex = index--, desc = null; if (otherIndex == 1) { desc = 'first socket'; } else { desc = 'second socket'; } // 转发收到的消息 ws.on('message', function(message) { var json = JSON.parse(message); //console.log('received (' + desc + '): ', json); console.log('otherIndex ---('+desc+')(' + otherIndex + '): '+json.event); wsc[otherIndex].send(message, function (error) { if (error) { console.log('Send message error (' + desc + '): ', error); } }); }); });
webrtc2.html
<html> <body> <button id="sendButton" onclick="sendData()">Send</button> <textarea id="dataChannelSend" >abc</textarea> <textarea id="dataChannelReceive" ></textarea> Local: <br> <video id="localVideo" autoplay></video><br> Remote: <br> <video id="remoteVideo" autoplay></video> <script> function writeObj(obj){ var description = ""; for(var i in obj){ var property=obj[i]; description+=i+" = "+property+"\n"; } console.log(description); } var isCaller = window.location.href.split('#')[1]; var socket = new WebSocket("ws://192.168.137.27:3000"); socket.onmessage = function(event){ var json = JSON.parse(event.data); //console.log('onmessage: ', json); //如果是一个ICE的候选,则将其加入到PeerConnection中,否则设定对方的session描述为传递过来的描述 if( json.event === "_ice_candidate" ){ // console.log("_ice_candidate:---->"); // writeObj(json.data.candidate); pc.addIceCandidate(new RTCIceCandidate(json.data.candidate)); } else { // console.log("not _ice_candidate:---->"); // writeObj(json.data.sdp); pc.setRemoteDescription(new RTCSessionDescription(json.data.sdp)); console.log("---------------->pc.setRemote"); // 如果是一个offer,那么需要回复一个answer if(json.event === "_offer") { console.log("------->createAnswer"); pc.createAnswer(function(desc){ pc.setLocalDescription(desc); console.log("---------------->pc.setLocal"); socket.send(JSON.stringify({ "event": "_answer", "data": { "sdp": desc } })); }, function (error) { console.log('Failure callback: ' + error); }); }else{ console.log("------->receive Answer---('"+json.event+"')"); } } }; var iceServer = null; var pc = new webkitRTCPeerConnection(iceServer,{optional: [{RtpDataChannels: true}]}); try { sendChannel = pc.createDataChannel('sendDataChannel',{reliable: true}); } catch (e) { alert('createDataChannel() failed with exception: ' + e.message); } sendChannel.onopen = console.log('--Send channel open state is : ' +sendChannel.readyState); sendChannel.onclose = console.log('--Send channel close state is: ' +sendChannel.readyState); // 发送ICE候选到其他客户端 pc.onicecandidate = function(event){ console.log("onicecandidate----------->"); if (event.candidate !== null) { console.log("event.candidate != null"); socket.send(JSON.stringify({ "event": "_ice_candidate", "data": { "candidate": event.candidate } })); }else{ console.log("event.candidate == null"); } }; sendChannel.onmessage = function(event) { console.log("-sendChannel--★★★★★---ondatachannel"); document.getElementById('dataChannelReceive').value = event.data; }; /*pc.ondatachannel = function(event) { console.log("-receiveChannel--★★★★★---ondatachannel"); receiveChannel = event.channel; receiveChannel.onmessage = function(event) { document.getElementById('dataChannelReceive').value = event.data; }; receiveChannel.onopen = console.log('--Receive channel open state is: ' + receiveChannel.readyState);; receiveChannel.onclose = console.log('--Receive channel close state is: ' + receiveChannel.readyState);; };*/ // 如果检测到媒体流连接到本地,将其绑定到一个video标签上输出 pc.onaddstream = function(event){ //document.getElementById('remoteVideo').src = URL.createObjectURL(event.stream); document.getElementById('remoteVideo').srcObject = event.stream; }; function sendData() { var data = document.getElementById('dataChannelSend').value; console.log("---->>>>sendData():"+data); sendChannel.send(data); } navigator.webkitGetUserMedia({ "audio": true, "video": true }, function(stream){ // document.getElementById('localVideo').src = URL.createObjectURL(stream); document.getElementById('localVideo').srcObject = stream; pc.addStream(stream); if(isCaller){ console.log("------->createOffer"); pc.createOffer(function(desc){ // console.log(desc); pc.setLocalDescription(desc); console.log("---------------->pc.setLocal"); socket.send(JSON.stringify({ "event": "_offer", "data": { "sdp": desc } })); }, function (error) { console.log('Failure callback: ' + error); }); } }, function(error){ console.log('getUserMedia error: ' + error); }); </script> </body> </html>
发表评论
-
srt学习笔记一:srt的helloworld
2020-03-27 19:13 5601。无服务的方式:udp, 2。srs作为服务端:rtmp推收 ... -
ios的safari使用自制ca证书测试webrtc
2018-08-20 13:31 2333这个需要注意 https://stackoverflow.c ... -
webrtc学习笔记九 (datachannel在jslinux的应用,java版本)
2015-10-15 17:45 2460目标:使用java的websocket作为datachannl ... -
webrtc学习笔记八(datachannnel同步textarea)
2015-10-09 16:47 11122020年5月12日更新 出现错误 websocket Fai ... -
webrtc学习笔记七(datachannel在jslinux的应用,nodejs版本)
2015-10-09 15:34 799目标: 两个浏览器的jslinux可以进行数据交互 fa ... -
webrtc学习笔记六(datachannel+websocket)
2015-10-03 00:12 14902020年5月12日更新 5年前的例子又不好使了, 出现错误 ... -
webrtc学习笔记四(获取真实的ip)
2015-09-28 14:47 3953<script> function getI ... -
webrtc学习笔记三(截屏快照)
2015-09-25 14:46 2191需要注意的问题: sizeCanvas这个方法帮助解决的 ch ... -
webrtc学习笔记二(datachannel)
2015-09-24 17:57 2396https://www.webrtc-experiment.c ... -
webrtc学习笔记一 (视频流)
2015-09-24 17:39 4407google官方的 socket.io的源码 https:// ...
相关推荐
NULL 博文链接:https://haoningabc.iteye.com/blog/2245893
WebRTC学习笔记_Demo收集 WebRTC是比较流行的开源web视频通讯技术
注意不要使用https,否则需要SSL 证书
WebRTC学习笔记01-最简单实现一对一视频通讯代码
Webrtc的学习笔记 有很多目录内容还没有补全,后续版本会逐渐完善
本demo采用web网页作为客户端,webrtc作为服务端,实现多路rtsp视频流在网页端同时实时预览。 其中包含两个文件夹:webrtc-qmy为客户端;webrtc-streamer-v0.7.0-dirty-Windows-AMD64-Release问服务端。具体使用流程...
使用详情查看我的博客《kurento-media-server和cotrun打洞的服务器的安装及部署,实现RTSP转WebRTC视频流播放》,链接:https://blog.csdn.net/weixin_40717107/article/details/122422896
webrtc-streamer 是一个使用简单机制通过 WebRTC 流式传输视频捕获设备和 RTSP 源的项目,它内置了一个小型的 HTTP server 来对 WebRTC需要的相关接口提供支持。相对于ffmpeg+flv.js的方案,延迟降低到了0.4秒左右,...
webrtc 视频数据流流程图,整理了视频数据流发送及接受流程.
webrtc实现h5播放rtsp流
webrtc基于webrtc-streamer推流实现直播,前端基于vue3实现,下载可用
WebRTC C ++示例在C ++上使用WebRTC(DataChannel)的示例程序(README.en.md是此文件的英文翻译。) 使用C ++中的WebRTC DataChannel的示例代码。要求Mac OS X 的Ubuntu编译$ cd $ git clone --depth 1 ...
h5实现播放RTSP视频流WebRTC.docx
这是基于asp.net开发的SuperWebSocket和WebRtc结合的Web网页版视频聊天实例,分享出来供大家学习。
通过WebRTC实时通讯技术,配合后端java websocket实现多人视频。局域网内视频没问题,公网需要自行穿透NAT,项目整体为SpringBoot 外置Tomcat 启动
Webrtc源码开发笔记1 —Webrtc视频编码打包流程模块图解 梳理webrtc从transceiver到transport流程,从而宏观上了解webrtc视频采集,编码,打包发送等相关流程与相关模块的对应关系,为开发和快速定位问题提供参考。
webRTC一对一视频通讯测试完整demo,包括webRTC基本api测试demo(音视频录制,屏幕共享,截图),后台采用socket.io作为信令服务器,开发语言为node,前台框架使用vue
基于webrtc开发的多人视频会议,信令服务器使用 java websocket, springboot架构。访问地址 https://IP/mcu.html
RTCMultiConnection 流媒体后台服务器 采用Node.js。可以支持1对1,1对多的音视频聊天服务。可以作为研发参考。
srs webrtc前端拉流播放(附带测试地址)