Skip to content
Open
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
23 changes: 17 additions & 6 deletions ayame/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ func (c *Connection) createPeerConnection() error {
return
}
c.trace("read RTP error %v", readErr)
c.Disconnect()
c.onDisconnectHandler("READ-RTP-ERROR", err)
c.Disconnect()
return
}
c.onTrackPacketHandler(track, rtp)
Expand All @@ -358,6 +358,17 @@ func (c *Connection) createPeerConnection() error {
}
}()
})
pc.OnICECandidate(func(candidate *webrtc.ICECandidate) {
if candidate != nil {
json := candidate.ToJSON()
c.trace("ICE candidate: %v", json)
msg := candidateMessage{
Type: "candidate",
ICECandidate: &json,
}
c.sendMsg(msg)
}
})
// Set the Handler for ICE connection state
// This will notify you when the peer has connected/disconnected
pc.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
Expand All @@ -371,8 +382,8 @@ func (c *Connection) createPeerConnection() error {
case webrtc.ICEConnectionStateDisconnected:
fallthrough
case webrtc.ICEConnectionStateFailed:
c.Disconnect()
c.onDisconnectHandler("ICE-CONNECTION-STATE-FAILED", nil)
c.Disconnect()
}
}
})
Expand Down Expand Up @@ -419,8 +430,8 @@ func (c *Connection) createAnswer() error {

answer, err := c.pc.CreateAnswer(nil)
if err != nil {
c.Disconnect()
c.onDisconnectHandler("CREATE-ANSWER-ERROR", err)
c.Disconnect()
return err
}
c.trace("create answer sdp=%s", answer.SDP)
Expand Down Expand Up @@ -449,8 +460,8 @@ func (c *Connection) setOffer(sessionDescription webrtc.SessionDescription) erro
}
err := c.pc.SetRemoteDescription(sessionDescription)
if err != nil {
c.Disconnect()
c.onDisconnectHandler("CREATE-OFFER-ERROR", err)
c.Disconnect()
return err
}
c.trace("set offer sdp=%s", sessionDescription.SDP)
Expand Down Expand Up @@ -605,8 +616,8 @@ loop:
c.trace("CLOSE-MESSAGE-CHANNEL")
<-ctx.Done()
c.trace("EXITED-MAIN")
c.Disconnect()
c.onDisconnectHandler("EXIT-RECV", nil)
c.Disconnect()
c.trace("EXIT-RECV")
}

Expand Down Expand Up @@ -664,8 +675,8 @@ func (c *Connection) handleMessage(rawMessage []byte) error {
if rejectReason == "" {
rejectReason = "REJECTED"
}
c.Disconnect()
c.onDisconnectHandler(rejectReason, nil)
c.Disconnect()
case "offer":
offerMsg := webrtc.SessionDescription{}
if err := unmarshalMessage(c, rawMessage, &offerMsg); err != nil {
Expand Down