use full candidateInit, update encoding
This commit is contained in:
@@ -74,15 +74,13 @@ func NewParticipant(conf *WebRTCConfig, sc SignalConnection, name string) (*Part
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
|
||||
ci := c.ToJSON()
|
||||
|
||||
// write candidate
|
||||
err := sc.WriteResponse(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_Trickle{
|
||||
Trickle: &livekit.Trickle{
|
||||
Candidate: ci.Candidate,
|
||||
// TODO: there are other candidateInit fields that we might want
|
||||
},
|
||||
Trickle: ToProtoTrickle(ci),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -76,6 +76,10 @@ func (r *Room) Join(participant *Participant) error {
|
||||
|
||||
// subscribe participant to existing tracks
|
||||
for _, p := range r.participants {
|
||||
if p.id == participant.id {
|
||||
// don't send to itself
|
||||
continue
|
||||
}
|
||||
if err := p.AddSubscriber(participant); err != nil {
|
||||
// TODO: log error? or disconnect?
|
||||
logger.GetLogger().Errorw("could not subscribe to participant",
|
||||
|
||||
+8
-6
@@ -1,6 +1,7 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/pion/webrtc/v3"
|
||||
@@ -57,14 +58,15 @@ func FromProtoSessionDescription(sd *livekit.SessionDescription) webrtc.SessionD
|
||||
}
|
||||
}
|
||||
|
||||
func ToProtoTrickle(candidateInit *webrtc.ICECandidateInit) *livekit.Trickle {
|
||||
func ToProtoTrickle(candidateInit webrtc.ICECandidateInit) *livekit.Trickle {
|
||||
data, _ := json.Marshal(candidateInit)
|
||||
return &livekit.Trickle{
|
||||
Candidate: candidateInit.Candidate,
|
||||
CandidateInit: string(data),
|
||||
}
|
||||
}
|
||||
|
||||
func FromProtoTrickle(trickle *livekit.Trickle) *webrtc.ICECandidateInit {
|
||||
return &webrtc.ICECandidateInit{
|
||||
Candidate: trickle.Candidate,
|
||||
}
|
||||
func FromProtoTrickle(trickle *livekit.Trickle) webrtc.ICECandidateInit {
|
||||
ci := webrtc.ICECandidateInit{}
|
||||
json.Unmarshal([]byte(trickle.CandidateInit), &ci)
|
||||
return ci
|
||||
}
|
||||
|
||||
+11
-10
@@ -43,11 +43,6 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
pName := r.FormValue("name")
|
||||
log := logger.GetLogger()
|
||||
|
||||
log.Infow("new client connected",
|
||||
"roomId", roomId,
|
||||
"participantName", pName,
|
||||
)
|
||||
|
||||
room := s.manager.GetRoom(roomId)
|
||||
if room == nil {
|
||||
writeJSONError(w, http.StatusNotFound, "room not found")
|
||||
@@ -78,6 +73,12 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Infow("new client connected",
|
||||
"roomId", roomId,
|
||||
"name", pName,
|
||||
"participant", participant.ID(),
|
||||
)
|
||||
|
||||
if err := room.Join(participant); err != nil {
|
||||
writeJSONError(w, http.StatusInternalServerError, "could not join room", err.Error())
|
||||
return
|
||||
@@ -155,11 +156,11 @@ func (s *RTCService) handleOffer(participant *rtc.Participant, offer *livekit.Se
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *RTCService) handleNegotiate(sc rtc.SignalConnection, peer *rtc.Participant, neg *livekit.SessionDescription) error {
|
||||
logger.GetLogger().Debugw("handling incoming negotiate")
|
||||
func (s *RTCService) handleNegotiate(sc rtc.SignalConnection, participant *rtc.Participant, neg *livekit.SessionDescription) error {
|
||||
logger.GetLogger().Debugw("handling incoming negotiate", "participant", participant.ID())
|
||||
if neg.Type == webrtc.SDPTypeOffer.String() {
|
||||
offer := rtc.FromProtoSessionDescription(neg)
|
||||
answer, err := peer.Answer(offer)
|
||||
answer, err := participant.Answer(offer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -175,7 +176,7 @@ func (s *RTCService) handleNegotiate(sc rtc.SignalConnection, peer *rtc.Particip
|
||||
}
|
||||
} else if neg.Type == webrtc.SDPTypeAnswer.String() {
|
||||
answer := rtc.FromProtoSessionDescription(neg)
|
||||
err := peer.SetRemoteDescription(answer)
|
||||
err := participant.SetRemoteDescription(answer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -186,7 +187,7 @@ func (s *RTCService) handleNegotiate(sc rtc.SignalConnection, peer *rtc.Particip
|
||||
func (s *RTCService) handleTrickle(peer *rtc.Participant, trickle *livekit.Trickle) error {
|
||||
candidateInit := rtc.FromProtoTrickle(trickle)
|
||||
logger.GetLogger().Debugw("adding peer candidate", "participantId", peer.ID())
|
||||
if err := peer.AddICECandidate(*candidateInit); err != nil {
|
||||
if err := peer.AddICECandidate(candidateInit); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user