RTCSessionDescription
RTCSessionDescription 介面描述了連線(或潛在連線)的一端及其配置方式。每個 RTCSessionDescription 包含一個描述 type(指示其在 offer/answer 協商過程中的作用)以及會話的 SDP 描述符。
兩個對等方之間協商連線的過程涉及來回交換 RTCSessionDescription 物件,每個描述都建議傳送者支援的一種連線配置選項組合。一旦兩個對等方就連線配置達成一致,協商即完成。
建構函式
RTCSessionDescription()已棄用-
透過指定
type和sdp來建立一個新的RTCSessionDescription。所有接受RTCSessionDescription物件的函式也都接受具有相同屬性的物件,因此您可以使用一個普通物件代替建立RTCSessionDescription例項。
例項屬性
RTCSessionDescription 介面不繼承任何屬性。
RTCSessionDescription.type只讀-
一個列舉,描述會話描述的型別。
RTCSessionDescription.sdp只讀-
一個包含描述會話的 SDP 的字串。
例項方法
RTCSessionDescription 不繼承任何方法。
RTCSessionDescription.toJSON()-
返回物件的 JSON 描述。生成的 JSON 中包含
type和sdp這兩個屬性的值。
示例
js
signalingChannel.onmessage = (evt) => {
if (!pc) start(false);
const message = JSON.parse(evt.data);
if (message.type && message.sdp) {
pc.setRemoteDescription(
new RTCSessionDescription(message),
() => {
// if we received an offer, we need to answer
if (pc.remoteDescription.type === "offer") {
pc.createAnswer(localDescCreated, logError);
}
},
logError,
);
} else {
pc.addIceCandidate(
new RTCIceCandidate(message.candidate),
() => {},
logError,
);
}
};
規範
| 規範 |
|---|
| WebRTC:瀏覽器中的即時通訊 # rtcsessiondescription-class |
瀏覽器相容性
載入中…