fixed panic when client connected abruptly

This commit is contained in:
David Zhao
2021-01-26 17:38:47 -08:00
parent b96028b4d6
commit a065a01592
10 changed files with 54 additions and 10 deletions
+5
View File
@@ -69,6 +69,7 @@ type RedisSink struct {
rc *redis.Client
nodeId string
participantId string
isClosed bool
once sync.Once
onClose func()
}
@@ -83,12 +84,16 @@ func NewRedisSink(rc *redis.Client, nodeId, participantId string) *RedisSink {
}
func (s *RedisSink) WriteMessage(msg proto.Message) error {
if s.isClosed {
return ErrChannelClosed
}
return publishRouterMessage(s.rc, s.nodeId, s.participantId, msg)
}
func (s *RedisSink) Close() {
s.once.Do(func() {
publishRouterMessage(s.rc, s.nodeId, s.participantId, &livekit.EndSession{})
s.isClosed = true
if s.onClose != nil {
s.onClose()
}