Skip to content

Commit

Permalink
fix(grpc): attach handlers before join (#355)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Jan 2, 2021
1 parent ff430d3 commit 3dbe475
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
40 changes: 20 additions & 20 deletions cmd/signal/grpc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,6 @@ func (s *SFUServer) Signal(stream pb.SFU_SignalServer) error {
}
}

answer, err := peer.Join(payload.Join.Sid, offer)
if err != nil {
switch err {
case sfu.ErrTransportExists:
fallthrough
case sfu.ErrOfferIgnored:
err = stream.Send(&pb.SignalReply{
Payload: &pb.SignalReply_Error{
Error: fmt.Errorf("join error: %w", err).Error(),
},
})
if err != nil {
log.Errorf("grpc send error %v ", err)
return status.Errorf(codes.Internal, err.Error())
}
default:
return status.Errorf(codes.Unknown, err.Error())
}
}

// Notify user of new ice candidate
peer.OnIceCandidate = func(candidate *webrtc.ICECandidateInit, target int) {
bytes, err := json.Marshal(candidate)
Expand Down Expand Up @@ -156,6 +136,26 @@ func (s *SFUServer) Signal(stream pb.SFU_SignalServer) error {
}
}

answer, err := peer.Join(payload.Join.Sid, offer)
if err != nil {
switch err {
case sfu.ErrTransportExists:
fallthrough
case sfu.ErrOfferIgnored:
err = stream.Send(&pb.SignalReply{
Payload: &pb.SignalReply_Error{
Error: fmt.Errorf("join error: %w", err).Error(),
},
})
if err != nil {
log.Errorf("grpc send error %v ", err)
return status.Errorf(codes.Internal, err.Error())
}
default:
return status.Errorf(codes.Unknown, err.Error())
}
}

marshalled, err := json.Marshal(answer)
if err != nil {
return status.Errorf(codes.Internal, fmt.Sprintf("sdp marshal error: %v", err))
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down

0 comments on commit 3dbe475

Please sign in to comment.