Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

use flake

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/build
**/.DS_Store
.direnv

provider/provider
connectctl/connectctl
Expand Down
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"editor.formatOnSave": false,
"go.testEnvVars": {
"SKIP_SLOW_TESTS": "true"
},
"cSpell.words": [
"webrtc"
]
}
174 changes: 174 additions & 0 deletions connect/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package connect

import (
"context"
"net/url"

// "encoding/json"
// "encoding/base64"
// "bytes"
"fmt"

"github.com/pion/webrtc/v3"
// "io"
// "net"
// "net/http"
Expand Down Expand Up @@ -358,3 +362,173 @@ func (self *BringYourApi) ConnectControl(connectControl *ConnectControlArgs, cal
callback,
)
}

func (self *BringYourApi) PutPeerToPeerOfferSDPSync(ctx context.Context, handshakeID string, sdp webrtc.SessionDescription) (err error) {
var res any
_, err = HttpPutWithStrategy(
ctx,
self.clientStrategy,
fmt.Sprintf("%s/peer-to-peer/handshake/%s/offer/sdp", self.apiUrl, handshakeID),
sdp,
self.byJwt,
res,
NewNoopApiCallback[any](),
)
return err
}

func (self *BringYourApi) PollPeerToPeerOfferSDPSync(ctx context.Context, handshakeID string) (sdp webrtc.SessionDescription, err error) {
for {
_, err = HttpPollWithStrategy(
ctx,
self.clientStrategy,
fmt.Sprintf("%s/peer-to-peer/handshake/%s/offer/sdp", self.apiUrl, handshakeID),
self.byJwt,
&sdp,
NewNoopApiCallback[*webrtc.SessionDescription](),
)

// 204 signals that the server is still waiting for the state
if err == ErrPollTimeout {
continue
}

return sdp, err

}

}

func (self *BringYourApi) PutPeerToPeerAnswerSDPSync(ctx context.Context, handshakeID string, sdp webrtc.SessionDescription) (err error) {
var res any
_, err = HttpPutWithStrategy(
ctx,
self.clientStrategy,
fmt.Sprintf("%s/peer-to-peer/handshake/%s/answer/sdp", self.apiUrl, handshakeID),
sdp,
self.byJwt,
res,
NewNoopApiCallback[any](),
)
return err
}

func (self *BringYourApi) PollPeerToPeerAnswerSDPSync(ctx context.Context, handshakeID string) (sdp webrtc.SessionDescription, err error) {
for {
_, err = HttpPollWithStrategy(
ctx,
self.clientStrategy,
fmt.Sprintf("%s/peer-to-peer/handshake/%s/answer/sdp", self.apiUrl, handshakeID),
self.byJwt,
&sdp,
NewNoopApiCallback[*webrtc.SessionDescription](),
)

// 204 signals that the server is still waiting for the state
if err == ErrPollTimeout {
continue
}

return sdp, err

}

}

func (self *BringYourApi) PostPeerToPeerOfferPeerCandidateSync(ctx context.Context, handshakeID string, peerCandidate webrtc.ICECandidate) (err error) {
var res any
_, err = HttpPostWithStrategy(
ctx,
self.clientStrategy,
fmt.Sprintf("%s/peer-to-peer/handshake/%s/offer/peer_candidates", self.apiUrl, handshakeID),
peerCandidate,
self.byJwt,
res,
NewNoopApiCallback[any](),
)
return err

}

func (self *BringYourApi) PollPeerToPeerOfferCandidatesSync(ctx context.Context, handshakeID string, from int) (candidates []webrtc.ICECandidate, err error) {

u, err := url.Parse(self.apiUrl)

if err != nil {
return nil, fmt.Errorf("failed to parse url: %w", err)
}

u = u.JoinPath("peer-to-peer", "handshake", handshakeID, "offer", "peer_candidates")
q := u.Query()
q.Set("from", fmt.Sprintf("%d", from))
u.RawQuery = q.Encode()

for {
_, err = HttpPollWithStrategy(
ctx,
self.clientStrategy,
u.String(),
self.byJwt,
&candidates,
NewNoopApiCallback[*[]webrtc.ICECandidate](),
)

if err == ErrPollTimeout {
// 204 signals that the server is still waiting for the state
continue
}

return candidates, err

}

}

func (self *BringYourApi) PostPeerToPeerAnswerPeerCandidateSync(ctx context.Context, handshakeID string, peerCandidate webrtc.ICECandidate) (err error) {
var res any
_, err = HttpPostWithStrategy(
ctx,
self.clientStrategy,
fmt.Sprintf("%s/peer-to-peer/handshake/%s/answer/peer_candidates", self.apiUrl, handshakeID),
peerCandidate,
self.byJwt,
res,
NewNoopApiCallback[any](),
)
return err

}

func (self *BringYourApi) PollPeerToPeerAnswerCandidatesSync(ctx context.Context, handshakeID string, from int) (candidates []webrtc.ICECandidate, err error) {

u, err := url.Parse(self.apiUrl)

if err != nil {
return nil, fmt.Errorf("failed to parse url: %w", err)
}

u = u.JoinPath("peer-to-peer", "handshake", handshakeID, "answer", "peer_candidates")
q := u.Query()
q.Set("from", fmt.Sprintf("%d", from))
u.RawQuery = q.Encode()

for {
_, err = HttpPollWithStrategy(
ctx,
self.clientStrategy,
u.String(),
self.byJwt,
&candidates,
NewNoopApiCallback[*[]webrtc.ICECandidate](),
)

if err == ErrPollTimeout {
// 204 signals that the server is still waiting for the state
continue
}

return candidates, err

}

}
38 changes: 31 additions & 7 deletions connect/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,56 @@ go 1.22.0

require (
bringyour.com/protocol v0.0.0
github.com/bringyour/webrtc-conn v0.0.3
github.com/go-playground/assert/v2 v2.2.0
github.com/golang-jwt/jwt/v5 v5.2.0
github.com/google/gopacket v1.1.19
github.com/gorilla/websocket v1.5.0
github.com/oklog/ulid/v2 v2.1.0
golang.org/x/crypto v0.23.0
github.com/pion/webrtc/v3 v3.3.0
github.com/quic-go/quic-go v0.46.0
golang.org/x/crypto v0.26.0
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/net v0.25.0
golang.org/x/net v0.27.0
google.golang.org/protobuf v1.33.0
src.agwa.name/tlshacks v0.0.0-20231008131857-90d701ba3225
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/quic-go/quic-go v0.46.0 // indirect
github.com/pion/datachannel v1.5.8 // indirect
github.com/pion/dtls/v2 v2.2.12 // indirect
github.com/pion/ice/v2 v2.3.34 // indirect
github.com/pion/interceptor v0.1.30 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.12 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.14 // indirect
github.com/pion/rtp v1.8.9 // indirect
github.com/pion/sctp v1.8.21 // indirect
github.com/pion/sdp/v3 v3.0.9 // indirect
github.com/pion/srtp/v2 v2.0.20 // indirect
github.com/pion/stun v0.6.1 // indirect
github.com/pion/transport/v2 v2.2.10 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/wlynxg/anet v0.0.3 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/tools v0.21.0 // indirect
src.agwa.name/tlshacks v0.0.0-20231008131857-90d701ba3225 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/golang/glog v1.2.1
golang.org/x/text v0.15.0 // indirect
golang.org/x/text v0.17.0 // indirect
)

replace bringyour.com/protocol v0.0.0 => ../protocol/build/bringyour.com/protocol
Loading