P2P学习(三)网络传输基本知识---ICE中提及过SDP

(一)SDP了解及基本格式

WebRTC学习(七)SDP规范

SDP案例: 下面这个例子中,就是一个标准的SDP案例

WebRTC学习(七)SDP规范

首先是版本信息v,一般都是0;

那第二个是o,表示为owner,这个SDP归谁所有,比如案例中主机名字jdoe,有多个系列号,最后包含一个IP地址。但是这IP地址并不一定是最终要进行传输的IP的地址,在我们WEBRTC里并不是用这个IP,而是使用candidate中的ip。

c表示connection表示连接这个网络的IPV4,OK,这些都不太重要。

那么这里呢,有一个媒体信息m,就是说在我这次交换媒体信息里,媒体就是一个audio也就是音频,它使用的是RTP的协议,

对于这个音频它有一个参数a=rtpmap,就是我使用的这个音频的编码方式是PCMU采样率是8000,这里大家了解一下就好。

最重要的是最后两行,它检测到有两种Candidate就是候选的路:

第一条是UDP的,IP 是 10.0.1.1端口是 8998,类型是host;

第二种也是UDP的,IP是192.0.2.3端口是45664,类型是穿越NAT的映射地址,

这里没有中继地址,就是最终不可能通过中继传输数据,那要么就是说我们在同一局域网内可以互通,要么就是穿越NAT走P2P,这就是SDP。

(二)显示通讯双方的SDP内容

WebRTC学习(六)端对端传输中获取!!!

/*
 *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree.
 */

button {
  margin: 0 20px 25px 0;
  vertical-align: top;
  width: 134px;
}

textarea {
  color: #444;
  font-size: 0.9em;
  font-weight: 300;
  height: 20.0em;
  padding: 5px;
  width: calc(100% - 10px);
}

div#getUserMedia {
  padding: 0 0 8px 0;
}

div.input {
  display: inline-block;
  margin: 0 4px 0 0;
  vertical-align: top;
  width: 310px;
}

div.input > div {
  margin: 0 0 20px 0;
  vertical-align: top;
}

div.output {
  background-color: #eee;
  display: inline-block;
  font-family: 'Inconsolata', 'Courier New', monospace;
  font-size: 0.9em;
  padding: 10px 10px 10px 25px;
  position: relative;
  top: 10px;
  white-space: pre;
  width: 270px;
}

div#preview {
  border-bottom: 1px solid #eee;
  margin: 0 0 1em 0;
  padding: 0 0 0.5em 0;
}

div#preview > div {
  display: inline-block;
  vertical-align: top;
  width: calc(50% - 12px);
}

section#statistics div {
  display: inline-block;
  font-family: 'Inconsolata', 'Courier New', monospace;
  vertical-align: top;
  width: 308px;
}

section#statistics div#senderStats {
  margin: 0 20px 0 0;
}

section#constraints > div {
  margin: 0 0 20px 0;
}

h2 {
  margin: 0 0 1em 0;
}


section#constraints label {
  display: inline-block;
  width: 156px;
}

section {
  margin: 0 0 20px 0;
  padding: 0 0 15px 0;
}

video {
  background: #222;
  margin: 0 0 0 0;
  --width: 100%;
  width: var(--width);
  height: 225px;
}

@media screen and (max-width: 720px) {
  button {
    font-weight: 500;
    height: 56px;
    line-height: 1.3em;
    width: 90px;
  }

  div#getUserMedia {
    padding: 0 0 40px 0;
  }

  section#statistics div {
    width: calc(50% - 14px);
  }

}
main.css

相关文章: