Skip to content

Commit

Permalink
fix: video not recovered after degradation
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Sep 19, 2024
1 parent 8c79ee4 commit a473d52
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions packages/hms-video-store/src/media/tracks/HMSRemoteVideoTrack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack {
* @returns {boolean} isDegraded - returns true if degraded
* */
setLayerFromServer(layerUpdate: VideoTrackLayerUpdate) {
this._degraded =
this.enabled &&
(layerUpdate.publisher_degraded || layerUpdate.subscriber_degraded) &&
layerUpdate.current_layer === HMSSimulcastLayer.NONE;
this._degraded = this.getDegradationValue(layerUpdate);
this._degradedAt = this._degraded ? new Date() : this._degradedAt;
const currentLayer = layerUpdate.current_layer;
HMSLogger.d(
Expand All @@ -165,12 +162,30 @@ export class HMSRemoteVideoTrack extends HMSVideoTrack {
pub_degraded=${layerUpdate.publisher_degraded}
isDegraded=${this._degraded}`,
);
const stream = this.stream as HMSRemoteStream;
// There are cases where none is requested just after this
if (
stream.getVideoLayer() === HMSSimulcastLayer.NONE &&
this.hasSinks() &&
currentLayer !== HMSSimulcastLayer.NONE
) {
this.updateLayer('setLayerFromServer');
}
// No need to send preferLayer update, as server has done it already
(this.stream as HMSRemoteStream).setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer');
stream.setVideoLayerLocally(currentLayer, this.logIdentifier, 'setLayerFromServer');

this.pushInHistory(`sfuLayerUpdate-${currentLayer}`);
return this._degraded;
}

private getDegradationValue(layerUpdate: VideoTrackLayerUpdate) {
return (
this.enabled &&
(layerUpdate.publisher_degraded || layerUpdate.subscriber_degraded) &&
layerUpdate.current_layer === HMSSimulcastLayer.NONE
);
}

private async updateLayer(source: string) {
const newLayer =
(this.degraded || !this.enabled || !this.hasSinks()) && !this.disableNoneLayerRequest
Expand Down

0 comments on commit a473d52

Please sign in to comment.