- 浏览: 1448252 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (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月12日更新
5年前的例子又不好使了,
出现错误
websocket Failed to execute 'send' on 'WebSocket': Still in CONNECTING state
参考:https://blog.csdn.net/bossxu_/article/details/102977802
原因是
pc.createOffer 的时候websocket还没建立完,socket.send出现问题,
把这段代码加到websocket.onopen事件里就好了:
只有datachannel的例子,websocket作为转发用,
建立连接后websocket就可以关了
server.js
webrtc_datachannle.html
5年前的例子又不好使了,
出现错误
websocket Failed to execute 'send' on 'WebSocket': Still in CONNECTING state
参考:https://blog.csdn.net/bossxu_/article/details/102977802
原因是
pc.createOffer 的时候websocket还没建立完,socket.send出现问题,
把这段代码加到websocket.onopen事件里就好了:
只有datachannel的例子,websocket作为转发用,
建立连接后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); } }); }); });
webrtc_datachannle.html
<html> <body> <button id="sendButton" onclick="sendData()">Send</button> <textarea id="dataChannelSend" >abc</textarea> <textarea id="dataChannelReceive" ></textarea> <script> var isCaller = window.location.href.split('#')[1]; var socket = new WebSocket("ws://127.0.0.1:3000"); socket.onopen=function(){ //这部分放到onopen事件里了 2020.05.12 console.log("socket on open --->"); 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); }); } } socket.onmessage = function(event){ var json = JSON.parse(event.data); //console.log('onmessage: ', json); //如果是一个ICE的候选,则将其加入到PeerConnection中,否则设定对方的session描述为传递过来的描述 if( json.event === "_ice_candidate" ){ pc.addIceCandidate(new RTCIceCandidate(json.data.candidate)); } else { 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; }; function sendData() { var data = document.getElementById('dataChannelSend').value; console.log("---->>>>sendData():"+data); sendChannel.send(data); } // if(isCaller){ //这部分放到onopen事件里了 2020.05.12 // 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); // }); // } </script> </body> </html>
发表评论
-
srt学习笔记一:srt的helloworld
2020-03-27 19:13 5761。无服务的方式:udp, 2。srs作为服务端:rtmp推收 ... -
ios的safari使用自制ca证书测试webrtc
2018-08-20 13:31 2342这个需要注意 https://stackoverflow.c ... -
webrtc学习笔记九 (datachannel在jslinux的应用,java版本)
2015-10-15 17:45 2466目标:使用java的websocket作为datachannl ... -
webrtc学习笔记八(datachannnel同步textarea)
2015-10-09 16:47 11182020年5月12日更新 出现错误 websocket Fai ... -
webrtc学习笔记七(datachannel在jslinux的应用,nodejs版本)
2015-10-09 15:34 803目标: 两个浏览器的jslinux可以进行数据交互 fa ... -
webrtc学习笔记五(视频流和datachannel一起使用的例子)
2015-09-30 23:57 36452020年5月9日更新,5年前 ... -
webrtc学习笔记四(获取真实的ip)
2015-09-28 14:47 3968<script> function getI ... -
webrtc学习笔记三(截屏快照)
2015-09-25 14:46 2196需要注意的问题: sizeCanvas这个方法帮助解决的 ch ... -
webrtc学习笔记二(datachannel)
2015-09-24 17:57 2403https://www.webrtc-experiment.c ... -
webrtc学习笔记一 (视频流)
2015-09-24 17:39 4416google官方的 socket.io的源码 https:// ...
相关推荐
WebRTC开发的视频通话,修改了之前的一个小例子,可以正常运行,后台java的websocket,用于学习交流
相关技术:Websocket,Springboot,WebRtc 使用Websocket 作为交互,作为信令服务器,负责信令交换。 视频、麦克风、屏幕共享相关操作,下载即可运行。 包含使用手册及相关说明。
需要使用端口,域名访问时,必须对tomcat做自签名证书,如果只是在本地使用localhost访问,就不需要做自签名证书了。 项目地址:https://shiping.lipingoomoney.cn:8443/rtcdemo/
基于Java WebSocket 做信令服务器,使用webrtc浏览器和服务器只需要完成一次握手,两者之间就直接可以创建持久性的连接,并进行双向数据传输。从而实现音视频通话。下载启动 输入http://localhost 就可使用
WebRTC直播间演示链接WebRTC介绍原理简单解释:浏览器提供获取屏幕、音频等媒体数据的接口,双方的媒体流数据通过Turn服务器传输。项目构造(非常简单)前端:就一个html文件,js和css直接放里面了,纯手写...
基于SpringBoot+Websocket+WebRtc 实现多人在线视频通话 功能如下所示: 1. 开关摄像头 2.开关麦克风 3.屏幕共享
基于SpringBoot+WebSocket+WebRTC实现视频通话,代码中的一些逻辑关系没有进行详细处理,只是实现了视频通话的功能哈!
使用WebRtc+node.js+express+PeerJS构建的多人即时视频通话项目源代码
WEBRTC到SIP客户端和服务器 如何设置Kamailio + RTPEngine + TURN服务器以启用WebRTC客户端和旧版SIP客户端之间的呼叫。 默认情况下,此配置启用了IPv6。 此设置将桥接SRTP-> RTP和ICE-> nonICE,以使WebRTC客户端...
GO语言基于WebRTC的视频会议系统源码+数据库.zip基于WebRTC的视频会议系统源码+数据库.zip基于WebRTC的视频会议系统源码+数据库.zip基于WebRTC的视频会议系统源码+数据库.zip基于WebRTC的视频会议系统源码+数据库....
webrtc+java+webscoket+js 实现视频聊天、在线聊天室、桌面共享 本项目只能在局域网内使用,要是放在公网需要配置https才行,运行前需要把相关ip修改成本地服务器ip,chat 是前端代码文件夹,建议用nginx部署,index....
基于Springboot实现的多人视频在线会议服务器前端(webrtc项目)源码+使用说明.7z 【多人视频在线会议-后端源码】https://download.csdn.net/download/DeepLearning_/87317683 视频会议的前端 使用webrtc实现图像传输...
实现webrtc的视频通信 采用websocket技术连接 服务器端使用java 客户端基于chrome浏览器
基于WebRtc+node.js+express+PeerJS构建的多人即时视频通话项目源码+项目说明.zip 该项目是个人毕设项目,答辩评审分达到95分,代码都经过调试测试,确保可以运行!欢迎下载使用,可用于小白学习、进阶。 该资源主要...
SpringBoot整合WebSocket+nacos注册中心实现多服务通信
WebRTC学习笔记_Demo收集 WebRTC是比较流行的开源web视频通讯技术
基于webrtc的视频会议(源码+项目说明).zip已经通过的高分项目。 基于webrtc的视频会议(源码+项目说明).zip已经通过的高分项目。基于webrtc的视频会议(源码+项目说明).zip已经通过的高分项目。基于webrtc的...
WEBRTC windows DEMO 添加 arm-nb 8k 4.75k
WEBRTC多人视频通话,可以支持多人视频通话,目前是三人的,因为视频通话的信令用到的是websocket,所以代码里面也放入了单独websocket通信的demo,解释也比较详细了,原来有一个列子是两人的,后面改成三人的,多人...
WebRTC学习笔记01-最简单实现一对一视频通讯代码