Issue updated tokens to clients. (#365)

This ensures client reconnect attempts would be successful for long running rooms. It also fixes inaccurate permissions that were set incorrectly when full reconnections take place.
This commit is contained in:
David Zhao
2022-01-23 23:15:49 -08:00
committed by GitHub
parent 6a46958870
commit 52fc53d325
13 changed files with 356 additions and 15 deletions
+11
View File
@@ -60,6 +60,7 @@ type RTCClient struct {
pendingTrackWriters []*TrackWriter
OnConnected func()
OnDataReceived func(data []byte, sid string)
refreshToken string
// map of livekit.ParticipantID and last packet
lastPackets map[livekit.ParticipantID]*rtp.Packet
@@ -324,6 +325,10 @@ func (c *RTCClient) Run() error {
c.lock.Lock()
c.pendingPublishedTracks[msg.TrackPublished.Cid] = msg.TrackPublished.Track
c.lock.Unlock()
case *livekit.SignalResponse_RefreshToken:
c.lock.Lock()
c.refreshToken = msg.RefreshToken
c.lock.Unlock()
}
}
}
@@ -412,6 +417,12 @@ func (c *RTCClient) Stop() {
c.cancel()
}
func (c *RTCClient) RefreshToken() string {
c.lock.Lock()
defer c.lock.Unlock()
return c.refreshToken
}
func (c *RTCClient) SendRequest(msg *livekit.SignalRequest) error {
payload, err := proto.Marshal(msg)
if err != nil {