github.com/pion/webrtc/v4@v4.0.1/icetransport_js.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  //go:build js && wasm
     5  // +build js,wasm
     6  
     7  package webrtc
     8  
     9  import "syscall/js"
    10  
    11  // ICETransport allows an application access to information about the ICE
    12  // transport over which packets are sent and received.
    13  type ICETransport struct {
    14  	// Pointer to the underlying JavaScript ICETransport object.
    15  	underlying js.Value
    16  }
    17  
    18  // GetSelectedCandidatePair returns the selected candidate pair on which packets are sent
    19  // if there is no selected pair nil is returned
    20  func (t *ICETransport) GetSelectedCandidatePair() (*ICECandidatePair, error) {
    21  	val := t.underlying.Call("getSelectedCandidatePair")
    22  	if val.IsNull() || val.IsUndefined() {
    23  		return nil, nil
    24  	}
    25  
    26  	return NewICECandidatePair(
    27  		valueToICECandidate(val.Get("local")),
    28  		valueToICECandidate(val.Get("remote")),
    29  	), nil
    30  }