PeerConnection
Example(摘)
/*When two peers decide they are going to set up a connection to each other, they both go through these steps. The STUN/TURN server configuration describes a server they can use to get things like their public IP address or to set up NAT traversal. They also have to send data for the signaling channel to each other using the same out-of-band mechanism they used to establish that they were going to communicate in the first place.*/
//假设信令通道存在
var signalingChannel = createSignalingChannel();
var pc;
var configuration = ; //run start(true) to initial a call
function start(isCaller){
pc = new RTCPeerConnection(configuration); //send any ice candidates to the other peer
//ICE 交互式连接建立 NAT
pc.onicecandidate = function(evt){
signalingChannel.send(JSON.stringify({"candidate":evt.candidate}));
} //get the local stream,show it in the local video element and send it
navigator.getUserMedia({"audio":true,"video":true},function(stream){
selfView.src = URL.createObjectURL(stream);
pc.addStream(stream); if(isCaller)
pc.createOffer(gotDescription);
else
pc.createAnswer(pc.remoteDescription,gotDescription);
function gotDescription(desc){
pc.setLocalDescription(desc);
//trace("Offer from pc1 \n"+desc.sdp);
//sdp : Session Description Protocol
signalingChannel.send(JSON.stringify({"sdp":desc}));
}
});
}
signalingChannel.onmessage = function(evt){
if(!pc)
start(false); var signal = JSON.parse(evt.data);
if(signal.sdp)
pc.setRemoteDescription(new RTCSessionDescription(signal.sdp));
else
pc.addIceCandidate(new RTCIceCandidate(signal.candidate));
}
PeerConnection的更多相关文章
- WebRTC PeerConnection
PeerConnection 是WebRtc native interface 最外层的模块, 通常来说, 用户使用Peerconection就可以构建最简单的p2p 应用. 下面的UML里 ...
- 几个比较”有意思“的JS脚本
1.获取内网和公网真实IP地址(引用地址) <!DOCTYPE html> <html> <head> <meta http-equiv="Cont ...
- 使用WebRTC搭建前端视频聊天室——数据通道篇
本文翻译自WebRTC data channels 在两个浏览器中,为聊天.游戏.或是文件传输等需求发送信息是十分复杂的.通常情况下,我们需要建立一台服务器来转发数据,当然规模比较大的情况下,会扩展成 ...
- 使用WebRTC搭建前端视频聊天室——信令篇
博客原文地址 建议看这篇之前先看一下使用WebRTC搭建前端视频聊天室——入门篇 如果需要搭建实例的话可以参照SkyRTC-demo:github地址 其中使用了两个库:SkyRTC(github地址 ...
- 使用WebRTC搭建前端视频聊天室——入门篇
http://segmentfault.com/a/1190000000436544 什么是WebRTC? 众所周知,浏览器本身不支持相互之间直接建立信道进行通信,都是通过服务器进行中转.比如现在有两 ...
- WebRTC通信流程
WebRTC是HTML5支持的重要特性之一,有了它,不再需要借助音视频相关的客户端,直接通过浏览器的Web页面就可以实现音视频对聊功能.而且WebRTC项目是开源的,我们可以借助WebRTC源码快速构 ...
- WebRTC手记之初探
转载请注明出处:http://www.cnblogs.com/fangkm/p/4364553.html WebRTC是HTML5支持的重要特性之一,有了它,不再需要借助音视频相关的客户端,直接通过浏 ...
- webrtc初识
最近由于项目的需求,开始接触了webrtc这个东西.没想到这东西的门槛还是蛮高的,接下来分享一下我所踩过的坑,希望对以后初次接触这个东西的人有所帮助. webrtc官网 第一步当然是看官方主页了(ww ...
- android中webrtc的几个关键的状态
在android层使用webrtc的时候,都是通过native层回调的形式来触发ui的改变,比如在什么时候绘出对方的视频窗口,什么时候表示双方连接已经建立等等... 我现在把我知道的列出来用于备忘. ...
随机推荐
- 自定义View(三)实现简单的可拖动、可缩放的ImageView
实现技术主要用到1.多点触摸 2.matrix的矩阵,平移.缩放 根据手指的数量判断是进行的拖动.还是缩放动作 package com.bi.xintest; import android.cont ...
- hdu 2586 How far away ?(离线求最近公共祖先)
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #i ...
- MySQL的简单查询语句
查询: 一:查询所有数据 select * from Info 查所有数据 select Code,Name from Info 查特定列 二:根据条件查 select * from Info whe ...
- OOP之C#设计及其UML(反向工程)
现在总结一下C#类关键字(virtual.abstract.override.new.sealed)的使用(以C#代码体现),并再次熟悉一下OOP思想,使用UML工具EA(Enterprise Arc ...
- [LeetCode][Java]Candy@LeetCode
Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- EAA脚本语言0.2
对上一版的改进.IL生成问题大部分解决了. 运行效果 脚本源码 #using "System"; #using "System.Drawing"; #using ...
- CentOS下MySQL数据库安装
前辈们总是说,要边学边记录,要总结.所以,开始把每天学到的内容一点一点记录. 复杂的理论不懂,只会目前安装,安好后就开始玩咯! 1.在官网下载相应的rpm安装包 下载地址:http://dev.mys ...
- SparkContext的初始化(季篇)——测量系统、ContextCleaner及环境更新
<深入理解Spark:核心思想与源码分析>一书前言的内容请看链接<深入理解SPARK:核心思想与源码分析>一书正式出版上市 <深入理解Spark:核心思想与源码分析> ...
- Base64正反编码
public class Base64 { private static char[] base64EncodeChars = new char[] { 'A', 'B', 'C', 'D', 'E' ...
- 19. UIAlertController 提示框获取文本内容,打印控制台上
1.首先定义一个全局字符串变量,方便接收获取的文本内容 2. -(void)viewDidAppear:(BOOL)animated{ UIAlertController * alert = [UIA ...