()
| 386 | } |
| 387 | |
| 388 | func main() { |
| 389 | flag.Parse() |
| 390 | |
| 391 | // Setup a websocket connection between this application and the Cirrus webserver. |
| 392 | serverURL := url.URL{Scheme: "ws", Host: fmt.Sprintf("%s:%d", *CirrusAddress, *CirrusPort), Path: "/"} |
| 393 | wsConn, _, err := websocket.DefaultDialer.Dial(serverURL.String(), nil) |
| 394 | if err != nil { |
| 395 | log.Fatal("Websocket dialing error: ", err) |
| 396 | return |
| 397 | } |
| 398 | |
| 399 | defer wsConn.Close() |
| 400 | |
| 401 | peerConnection, err := createPeerConnection() |
| 402 | if err != nil { |
| 403 | panic(err) |
| 404 | } |
| 405 | |
| 406 | // Store our local ice candidates that we will transmit to UE |
| 407 | pendingCandidates := make([]*webrtc.ICECandidate, 0) |
| 408 | |
| 409 | // Setup a callback to capture our local ice candidates when they are ready |
| 410 | // Note: can happen at random times so might be before or after we have sent offer. |
| 411 | peerConnection.OnICECandidate(func(localIceCandidate *webrtc.ICECandidate) { |
| 412 | if localIceCandidate == nil { |
| 413 | return |
| 414 | } |
| 415 | |
| 416 | desc := peerConnection.RemoteDescription() |
| 417 | if desc == nil { |
| 418 | pendingCandidates = append(pendingCandidates, localIceCandidate) |
| 419 | fmt.Println("Added local ICE candidate that we will send off later...") |
| 420 | } else { |
| 421 | sendLocalIceCandidate(wsConn, localIceCandidate) |
| 422 | } |
| 423 | }) |
| 424 | |
| 425 | // Set the handler for ICE connection state |
| 426 | // This will notify you when the peer has connected/disconnected |
| 427 | peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) { |
| 428 | |
| 429 | colorPurple := "\033[35m" |
| 430 | colorReset := "\033[0m" |
| 431 | |
| 432 | fmt.Printf("Connection State has changed %s \n", connectionState.String()) |
| 433 | |
| 434 | if connectionState == webrtc.ICEConnectionStateConnected { |
| 435 | fmt.Println(string(colorPurple), "Connected to UE Pixel Streaming!", string(colorReset)) |
| 436 | } else if connectionState == webrtc.ICEConnectionStateFailed || connectionState == webrtc.ICEConnectionStateDisconnected { |
| 437 | fmt.Println(string(colorPurple), "Disconnected from UE Pixel Streaming.", string(colorReset)) |
| 438 | } |
| 439 | }) |
| 440 | |
| 441 | videoUDP, audioUDP := setupMediaForwarding(peerConnection) |
| 442 | defer videoUDP.conn.Close() |
| 443 | defer audioUDP.conn.Close() |
| 444 | |
| 445 | sendOffer(wsConn, peerConnection) |
nothing calls this directly
no test coverage detected