mirror of
https://github.com/jech/galene.git
synced 2024-11-09 18:25:58 +01:00
Complete parsing of WHIP candidates.
This commit is contained in:
parent
be2d3ab4ca
commit
dc34350d8f
2 changed files with 24 additions and 15 deletions
|
@ -193,17 +193,7 @@ func (c *WhipClient) gotOffer(ctx context.Context, offer []byte) ([]byte, error)
|
|||
return []byte(conn.pc.CurrentLocalDescription().SDP), nil
|
||||
}
|
||||
|
||||
func (c *WhipClient) GotICECandidate(candidate, ufrag []byte) error {
|
||||
zero := uint16(0)
|
||||
init := webrtc.ICECandidateInit{
|
||||
Candidate: string(candidate),
|
||||
SDPMLineIndex: &zero,
|
||||
}
|
||||
if ufrag != nil {
|
||||
u := string(ufrag)
|
||||
init.UsernameFragment = &u
|
||||
}
|
||||
|
||||
func (c *WhipClient) GotICECandidate(init webrtc.ICECandidateInit) error {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
if c.connection == nil {
|
||||
|
|
|
@ -316,18 +316,37 @@ func whipResourceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// RFC 8840
|
||||
lines := bytes.Split(body, []byte{'\n'})
|
||||
var ufrag []byte
|
||||
mLineIndex := -1
|
||||
var mid, ufrag []byte
|
||||
for _, l := range lines {
|
||||
l = bytes.TrimRight(l, " \r")
|
||||
if bytes.HasPrefix(l, []byte("a=ice-ufrag:")) {
|
||||
ufrag = l[len("a=ice-ufrag:"):]
|
||||
} else if bytes.HasPrefix(l, []byte("m=")) {
|
||||
mLineIndex++
|
||||
mid = nil
|
||||
} else if bytes.HasPrefix(l, []byte("a=mid:")) {
|
||||
mid = l[len("a=mid:"):]
|
||||
} else if bytes.HasPrefix(l, []byte("a=candidate:")) {
|
||||
err := c.GotICECandidate(l[2:], ufrag)
|
||||
init := webrtc.ICECandidateInit{
|
||||
Candidate: string(l[2:]),
|
||||
}
|
||||
if len(mid) > 0 {
|
||||
s := string(mid)
|
||||
init.SDPMid = &s
|
||||
}
|
||||
if mLineIndex >= 0 {
|
||||
i := uint16(mLineIndex)
|
||||
init.SDPMLineIndex = &i
|
||||
}
|
||||
if len(ufrag) > 0 {
|
||||
s := string(ufrag)
|
||||
init.UsernameFragment = &s
|
||||
}
|
||||
err := c.GotICECandidate(init)
|
||||
if err != nil {
|
||||
log.Printf("WHIP candidate: %v", err)
|
||||
}
|
||||
} else if bytes.Equal(l, []byte("a=end-of-candidates")) {
|
||||
c.GotICECandidate(nil, ufrag)
|
||||
}
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
|
Loading…
Reference in a new issue