| 97 | } |
| 98 | |
| 99 | func createPeerConnection() (*webrtc.PeerConnection, error) { |
| 100 | // Create a MediaEngine object to configure the supported codec |
| 101 | m := webrtc.MediaEngine{} |
| 102 | |
| 103 | // This sets up H.264, OPUS, etc. |
| 104 | m.RegisterDefaultCodecs() |
| 105 | |
| 106 | // Create the API object with the MediaEngine |
| 107 | api := webrtc.NewAPI(webrtc.WithMediaEngine(&m)) |
| 108 | |
| 109 | // Prepare the configuration |
| 110 | // UE is using unified plan on the backend so we should too |
| 111 | config := webrtc.Configuration{SDPSemantics: webrtc.SDPSemanticsUnifiedPlan} |
| 112 | |
| 113 | // Create a new RTCPeerConnection |
| 114 | peerConnection, err := api.NewPeerConnection(config) |
| 115 | |
| 116 | if err != nil { |
| 117 | log.Println("Error making new peer connection: ", err) |
| 118 | return nil, err |
| 119 | } |
| 120 | |
| 121 | // Allow us to receive 1 audio track, and 1 video track in the "recvonly" mode |
| 122 | if _, err = peerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeAudio, webrtc.RtpTransceiverInit{ |
| 123 | Direction: webrtc.RTPTransceiverDirectionRecvonly, |
| 124 | }); err != nil { |
| 125 | log.Println("Error adding RTP audio transceiver: ", err) |
| 126 | return nil, err |
| 127 | } else if _, err = peerConnection.AddTransceiverFromKind(webrtc.RTPCodecTypeVideo, webrtc.RtpTransceiverInit{ |
| 128 | Direction: webrtc.RTPTransceiverDirectionRecvonly, |
| 129 | }); err != nil { |
| 130 | log.Println("Error adding RTP video transceiver: ", err) |
| 131 | return nil, err |
| 132 | } |
| 133 | |
| 134 | return peerConnection, err |
| 135 | } |
| 136 | |
| 137 | // Pion has recieved an "answer" from the remote Unreal Engine Pixel Streaming (through Cirrus) |
| 138 | // Pion will now set its remote session description that it got from the answer. |