client sends offer after getting room info
This commit is contained in:
+42
-40
@@ -23,17 +23,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RTCClient struct {
|
type RTCClient struct {
|
||||||
conn *websocket.Conn
|
conn *websocket.Conn
|
||||||
PeerConn *webrtc.PeerConnection
|
PeerConn *webrtc.PeerConnection
|
||||||
localTracks []*webrtc.Track
|
localTracks []*webrtc.Track
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
connected bool
|
connected bool
|
||||||
iceConnected bool
|
iceConnected bool
|
||||||
paused bool
|
paused bool
|
||||||
me *rtc.MediaEngine // optional, populated only when receiving tracks
|
me *rtc.MediaEngine // optional, populated only when receiving tracks
|
||||||
receivers []*rtc.Receiver
|
receivers []*rtc.Receiver
|
||||||
|
localParticipant *livekit.ParticipantInfo
|
||||||
|
|
||||||
// pending actions to start after connected to peer
|
// pending actions to start after connected to peer
|
||||||
pendingCandidates []*webrtc.ICECandidate
|
pendingCandidates []*webrtc.ICECandidate
|
||||||
@@ -174,35 +175,6 @@ func (c *RTCClient) Run() error {
|
|||||||
c.AppendLog("data channel open")
|
c.AppendLog("data channel open")
|
||||||
})
|
})
|
||||||
|
|
||||||
c.AppendLog("creating offer")
|
|
||||||
|
|
||||||
// Create an offer to send to the other process
|
|
||||||
offer, err := c.PeerConn.CreateOffer(nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.AppendLog("created offer", "offer", offer.SDP)
|
|
||||||
|
|
||||||
// Sets the LocalDescription, and starts our UDP listeners
|
|
||||||
// Note: this will start the gathering of ICE candidates
|
|
||||||
if err = c.PeerConn.SetLocalDescription(offer); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// send the offer to remote
|
|
||||||
req := &livekit.SignalRequest{
|
|
||||||
Message: &livekit.SignalRequest_Offer{
|
|
||||||
Offer: service.ToProtoSessionDescription(offer),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
c.AppendLog("connecting to remote...")
|
|
||||||
if err = c.SendRequest(req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer c.PeerConn.Close()
|
|
||||||
|
|
||||||
// run the session
|
// run the session
|
||||||
for {
|
for {
|
||||||
res, err := c.ReadResponse()
|
res, err := c.ReadResponse()
|
||||||
@@ -210,6 +182,36 @@ func (c *RTCClient) Run() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch msg := res.Message.(type) {
|
switch msg := res.Message.(type) {
|
||||||
|
case *livekit.SignalResponse_Join:
|
||||||
|
c.AppendLog("join accepted, sending offer..")
|
||||||
|
c.localParticipant = msg.Join.Participant
|
||||||
|
|
||||||
|
// Create an offer to send to the other process
|
||||||
|
offer, err := c.PeerConn.CreateOffer(nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.AppendLog("created offer", "offer", offer.SDP)
|
||||||
|
|
||||||
|
// Sets the LocalDescription, and starts our UDP listeners
|
||||||
|
// Note: this will start the gathering of ICE candidates
|
||||||
|
if err = c.PeerConn.SetLocalDescription(offer); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// send the offer to remote
|
||||||
|
req := &livekit.SignalRequest{
|
||||||
|
Message: &livekit.SignalRequest_Offer{
|
||||||
|
Offer: service.ToProtoSessionDescription(offer),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
c.AppendLog("connecting to remote...")
|
||||||
|
if err = c.SendRequest(req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer c.PeerConn.Close()
|
||||||
case *livekit.SignalResponse_Answer:
|
case *livekit.SignalResponse_Answer:
|
||||||
c.AppendLog("connected to remote, setting desc")
|
c.AppendLog("connected to remote, setting desc")
|
||||||
// remote answered the offer, establish connection
|
// remote answered the offer, establish connection
|
||||||
|
|||||||
Reference in New Issue
Block a user