Skip to content

Commit

Permalink
fix transport
Browse files Browse the repository at this point in the history
Former-commit-id: bc62a2a432f41e1b9abf209c459b00321db6dcaa [formerly 74c4656ef2bff7a00c302bd7f1196d979882f76e] [formerly 1d18b50a060e7e3b0d12a3d95e224f4be71dd4e2 [formerly f739679]]
Former-commit-id: b21ca08bd848fc9389f79fd447aa30a417b05c99 [formerly 1d1fe9f43c0551bce1815c3212dc68fbbb751c7d]
Former-commit-id: db7821d5774fa1ca427f64c657114d02f6c42059
  • Loading branch information
notedit committed Jan 3, 2019
1 parent 0fa97ed commit b9bdea3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 deletions.
33 changes: 6 additions & 27 deletions endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewEndpointWithPort(ip string, port int) *Endpoint {

// CreateTransport create a new transport object and register it with the remote ICE username and password
// disableSTUNKeepAlive - Disable ICE/STUN keep alives, required for server to server transports, set this to false if you do not how to use it
func (e *Endpoint) CreateTransport(remoteSdp *sdp.SDPInfo, localSdp *sdp.SDPInfo, disableSTUNKeepAlive bool) *Transport {
func (e *Endpoint) CreateTransport(remoteSdp *sdp.SDPInfo, localSdp *sdp.SDPInfo, options ...bool) *Transport {

var localIce *sdp.ICEInfo
var localDtls *sdp.DTLSInfo
Expand All @@ -67,35 +67,14 @@ func (e *Endpoint) CreateTransport(remoteSdp *sdp.SDPInfo, localSdp *sdp.SDPInfo
localIce.SetLite(true)
localIce.SetEndOfCandidate(true)

transport := NewTransport(e.bundle, remoteIce, remoteDtls, remoteCandidates,
localIce, localDtls, localCandidates, disableSTUNKeepAlive)

e.transports[transport.username.ToString()] = transport

transport.Once("stopped", func() {
delete(e.transports, transport.username.ToString())
})
disableSTUNKeepAlive := false

return transport
}

// CreateTransportWithRemote create a new transport object and register it with the remote ICE username and password
// This is used when you do not have local sdp info yet.
func (e *Endpoint) CreateTransportWithRemote(sdpInfo *sdp.SDPInfo, disableSTUNKeepAlive bool) *Transport {

localIce := sdp.ICEInfoGenerate(true)
localDtls := sdp.NewDTLSInfo(sdpInfo.GetDTLS().GetSetup().Reverse(), "sha-256", e.fingerprint)
localCandidates := []*sdp.CandidateInfo{e.candidate.Clone()}

remoteCandidatesClone := []*sdp.CandidateInfo{}
for _, candidate := range sdpInfo.GetCandidates() {
remoteCandidatesClone = append(remoteCandidatesClone, candidate.Clone())
if len(options) > 0 {
disableSTUNKeepAlive = options[0]
}

remoteIceClone := sdpInfo.GetICE().Clone()
remoteDtlsClone := sdpInfo.GetDTLS().Clone()

transport := NewTransport(e.bundle, remoteIceClone, remoteDtlsClone, remoteCandidatesClone, localIce, localDtls, localCandidates, disableSTUNKeepAlive)
transport := NewTransport(e.bundle, remoteIce, remoteDtls, remoteCandidates,
localIce, localDtls, localCandidates, disableSTUNKeepAlive)

e.transports[transport.username.ToString()] = transport

Expand Down
2 changes: 1 addition & 1 deletion manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ With that information, you can create an ICE+DTLS transport on the `Endpoint`.
offer, err := sdp.Parse(offerStr)

//Create an DTLS ICE transport in that enpoint
transport = endpoint.CreateTransportWithRemote(offer, false)
transport = endpoint.CreateTransport(offer, nil)

```

Expand Down
9 changes: 5 additions & 4 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_TransportCreate(t *testing.T) {
sdpInfo := sdp.NewSDPInfo()
sdpInfo.SetICE(iceInfo)
sdpInfo.SetDTLS(dtlsInfo)
transport := endpoint.CreateTransportWithRemote(sdpInfo, false)
transport := endpoint.CreateTransport(sdpInfo, nil)

if transport == nil {
t.Error("can not create transport")
Expand All @@ -33,7 +33,7 @@ func Test_CreateIncomingTrack(t *testing.T) {
sdpInfo.SetICE(iceInfo)
sdpInfo.SetDTLS(dtlsInfo)

transport := endpoint.CreateTransportWithRemote(sdpInfo, false)
transport := endpoint.CreateTransport(sdpInfo, nil)

incomingTrack := transport.CreateIncomingStreamTrack("audio", "audiotrack", map[string]uint{})

Expand All @@ -52,7 +52,7 @@ func Test_CreateOutgoingTrack(t *testing.T) {
sdpInfo.SetICE(iceInfo)
sdpInfo.SetDTLS(dtlsInfo)

transport := endpoint.CreateTransportWithRemote(sdpInfo, false)
transport := endpoint.CreateTransport(sdpInfo, nil)
outgoingTrack := transport.CreateOutgoingStreamTrack("video", "videotrack", map[string]uint{})

if outgoingTrack.GetID() != "videotrack" {
Expand All @@ -71,7 +71,8 @@ func Test_TransportStop(t *testing.T) {
sdpInfo.SetICE(iceInfo)
sdpInfo.SetDTLS(dtlsInfo)

transport := endpoint.CreateTransportWithRemote(sdpInfo, false)
transport := endpoint.CreateTransport(sdpInfo, nil)

transport.Once("stopped", func() {
t.Log("transport stopped")
})
Expand Down

0 comments on commit b9bdea3

Please sign in to comment.