docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct RTCSessionDescription

    The RTCSessionDescription interface represents the setup of one side of a connection or a proposed connection. It contains a description type that identifies the negotiation stage it pertains to, along with the session's SDP (Session Description Protocol) details.

    Namespace: Unity.WebRTC
    Assembly: Unity.WebRTC.dll
    Syntax
    public struct RTCSessionDescription
    Remarks

    Establishing a connection between two parties involves swapping RTCSessionDescription objects, with each one proposing a set of connection setup options that the sender can accommodate. The connection setup is finalized when both parties agree on a particular configuration.

    Examples
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using UnityEngine;
    using Unity.WebRTC;
    
    class MediaStreamer : MonoBehaviour
    {
        private RTCPeerConnection _pc1;
        private List<RTCRtpSender> pc1Senders;
        private MediaStream videoStream;
        private MediaStreamTrack track;
        private DelegateOnNegotiationNeeded pc1OnNegotiationNeeded;
        private bool videoUpdateStarted;
    
        private void Start()
        {
            pc1Senders = new List<RTCRtpSender>();
            pc1OnNegotiationNeeded = () => { StartCoroutine(PcOnNegotiationNeeded(_pc1)); };
            Call();
        }
    
        IEnumerator PcOnNegotiationNeeded(RTCPeerConnection pc)
        {
            var op = pc.CreateOffer();
            yield return op;
            if (!op.IsError)
            {
                yield return StartCoroutine(OnCreateOfferSuccess(pc, op.Desc));
            }
        }
    
        private void Call()
        {
            RTCConfiguration configuration = default;
            configuration.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } };
            _pc1 = new RTCPeerConnection(ref configuration);
            _pc1.OnNegotiationNeeded = pc1OnNegotiationNeeded;
    
            videoStream = Camera.main.CaptureStream(1280, 720);
            track = videoStream.GetTracks().First();
    
            pc1Senders.Add(_pc1.AddTrack(track));
            if (!videoUpdateStarted)
            {
                StartCoroutine(WebRTC.Update());
                videoUpdateStarted = true;
            }
        }
    
        private IEnumerator OnCreateOfferSuccess(RTCPeerConnection pc, RTCSessionDescription desc)
        {
            Debug.Log($"Offer created. SDP is: \n{desc.sdp}");
            var op = pc.SetLocalDescription(ref desc);
            yield return op;
        }
    }

    Fields

    sdp

    A string that holds the session's SDP information.

    Declaration
    public string sdp
    Field Value
    Type Description
    string
    See Also
    RTCPeerConnection
    RTCRtpSender

    type

    An enum that specifies the type of the session description. Refer to RTCSdpType.

    Declaration
    public RTCSdpType type
    Field Value
    Type Description
    RTCSdpType
    See Also
    RTCPeerConnection
    RTCRtpSender

    See Also

    RTCPeerConnection
    RTCRtpSender
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)