@100mslive/hms-video-store
Advanced tools
Comparing version 0.12.20-alpha.2 to 0.12.20-alpha.3
@@ -203,2 +203,3 @@ import { HMSLocalPeer } from './models/peer'; | ||
private stopPlaylist; | ||
private applySettings; | ||
} |
@@ -21,3 +21,3 @@ import { TransportFailureCategory as TFC } from './models/TransportFailureCategory'; | ||
originalState: TransportState; | ||
maxFailedRetries?: number; | ||
maxRetryTime?: number; | ||
changeState?: boolean; | ||
@@ -32,7 +32,6 @@ } | ||
constructor(onStateChange: (state: TransportState, error?: HMSException) => Promise<void>, sendEvent: (error: HMSException, category: TFC) => void); | ||
schedule({ category, error, task, originalState, maxFailedRetries, changeState, }: ScheduleTaskParams): Promise<void>; | ||
schedule({ category, error, task, originalState, maxRetryTime, changeState, }: ScheduleTaskParams): Promise<void>; | ||
reset(): void; | ||
isTaskInProgress(category: TFC): boolean; | ||
private scheduleTask; | ||
private getBaseDelayForTask; | ||
private getDelayForRetryCount; | ||
@@ -39,0 +38,0 @@ private setTimeoutPromise; |
@@ -5,3 +5,3 @@ export declare const RENEGOTIATION_CALLBACK_ID = "renegotiation-callback-id"; | ||
/** | ||
* Maximum number of retries that transport-layer will try | ||
* Maximum time that transport-layer will try | ||
* before giving up on the connection and returning a failure | ||
@@ -11,4 +11,3 @@ * | ||
*/ | ||
export declare const MAX_TRANSPORT_RETRIES = 5; | ||
export declare const MAX_TRANSPORT_RETRY_DELAY = 60; | ||
export declare const MAX_TRANSPORT_RETRY_TIME = 60000; | ||
export declare const DEFAULT_SIGNAL_PING_TIMEOUT = 12000; | ||
@@ -15,0 +14,0 @@ export declare const DEFAULT_SIGNAL_PING_INTERVAL = 3000; |
@@ -0,1 +1,2 @@ | ||
import { Store } from '../sdk/store'; | ||
/** | ||
@@ -14,1 +15,2 @@ * Check only for presence(not truthy) of a value. | ||
export declare const validateMediaDevicesExistence: () => void; | ||
export declare const validatePublishParams: (store: Store) => void; |
{ | ||
"version": "0.12.20-alpha.2", | ||
"version": "0.12.20-alpha.3", | ||
"license": "MIT", | ||
@@ -76,3 +76,3 @@ "repository": { | ||
], | ||
"gitHead": "af10282af58c6f480c9727a88a434aabfcb7f3c6" | ||
"gitHead": "7432edcc726ca36bf1ffeab7e0ab8ab16f461ac3" | ||
} |
@@ -27,2 +27,3 @@ import HMSRoom from './models/HMSRoom'; | ||
import { | ||
HMSAudioCodec, | ||
HMSChangeMultiTrackStateParams, | ||
@@ -41,2 +42,3 @@ HMSConfig, | ||
HMSScreenShareConfig, | ||
HMSVideoCodec, | ||
TokenRequest, | ||
@@ -56,2 +58,3 @@ TokenRequestOptions, | ||
import { PlaylistManager, TranscriptionConfig } from '../internal'; | ||
import { HMSAudioTrackSettingsBuilder, HMSVideoTrackSettingsBuilder } from '../media/settings'; | ||
import { HMSLocalStream } from '../media/streams/HMSLocalStream'; | ||
@@ -101,3 +104,3 @@ import { | ||
import { workerSleep } from '../utils/timer-utils'; | ||
import { validateMediaDevicesExistence, validateRTCPeerConnection } from '../utils/validations'; | ||
import { validateMediaDevicesExistence, validatePublishParams, validateRTCPeerConnection } from '../utils/validations'; | ||
@@ -961,3 +964,4 @@ const INITIAL_STATE = { | ||
const hmsTrack = new TrackKlass(stream, track, source, this.eventBus); | ||
this.setPlaylistSettings({ | ||
await this.applySettings(hmsTrack); | ||
await this.setPlaylistSettings({ | ||
track, | ||
@@ -1611,2 +1615,40 @@ hmsTrack, | ||
} | ||
// eslint-disable-next-line complexity | ||
private async applySettings(track: HMSLocalTrack) { | ||
validatePublishParams(this.store); | ||
const publishParams = this.store.getPublishParams(); | ||
// this is not needed but added for avoiding ? later | ||
if (!publishParams) { | ||
return; | ||
} | ||
if (track instanceof HMSLocalVideoTrack) { | ||
const publishKey = track.source === 'regular' ? 'video' : track.source === 'screen' ? 'screen' : ''; | ||
if (!publishKey || !publishParams.allowed.includes(publishKey)) { | ||
return; | ||
} | ||
const video = publishParams[publishKey]; | ||
if (!video) { | ||
return; | ||
} | ||
const settings = new HMSVideoTrackSettingsBuilder() | ||
.codec(video.codec as HMSVideoCodec) | ||
.maxBitrate(video.bitRate) | ||
.maxFramerate(video.frameRate) | ||
.setWidth(video.width) | ||
.setHeight(video.height) | ||
.build(); | ||
await track.setSettings(settings); | ||
} else if (track instanceof HMSLocalAudioTrack) { | ||
if (!publishParams.allowed.includes('audio')) { | ||
return; | ||
} | ||
const settings = new HMSAudioTrackSettingsBuilder() | ||
.codec(publishParams.audio.codec as HMSAudioCodec) | ||
.maxBitrate(publishParams.audio.bitRate) | ||
.build(); | ||
await track.setSettings(settings); | ||
} | ||
} | ||
} |
@@ -39,3 +39,2 @@ import { JoinParameters } from './models/JoinParameters'; | ||
ICE_DISCONNECTION_TIMEOUT, | ||
MAX_TRANSPORT_RETRIES, | ||
PROTOCOL_SPEC, | ||
@@ -356,3 +355,2 @@ PROTOCOL_VERSION, | ||
originalState: this.state, | ||
maxFailedRetries: MAX_TRANSPORT_RETRIES, | ||
changeState: false, | ||
@@ -928,3 +926,2 @@ }); | ||
originalState: TransportState.Joined, | ||
maxFailedRetries: 3, | ||
changeState: false, | ||
@@ -1093,3 +1090,2 @@ }); | ||
originalState: TransportState.Joined, | ||
maxFailedRetries: 1, | ||
}); | ||
@@ -1096,0 +1092,0 @@ } |
import { Dependencies as TFCDependencies, TransportFailureCategory as TFC } from './models/TransportFailureCategory'; | ||
import { TransportState } from './models/TransportState'; | ||
import { HMSException } from '../error/HMSException'; | ||
import { MAX_TRANSPORT_RETRIES, MAX_TRANSPORT_RETRY_DELAY } from '../utils/constants'; | ||
import { MAX_TRANSPORT_RETRY_TIME } from '../utils/constants'; | ||
import HMSLogger from '../utils/logger'; | ||
@@ -26,3 +26,3 @@ import { PromiseWithCallbacks } from '../utils/promise'; | ||
originalState: TransportState; | ||
maxFailedRetries?: number; | ||
maxRetryTime?: number; | ||
changeState?: boolean; | ||
@@ -46,6 +46,6 @@ } | ||
originalState, | ||
maxFailedRetries = MAX_TRANSPORT_RETRIES, | ||
maxRetryTime = MAX_TRANSPORT_RETRY_TIME, | ||
changeState = true, | ||
}: ScheduleTaskParams) { | ||
await this.scheduleTask({ category, error, changeState, task, originalState, maxFailedRetries }); | ||
await this.scheduleTask({ category, error, changeState, task, originalState, maxRetryTime, failedAt: Date.now() }); | ||
} | ||
@@ -70,5 +70,6 @@ | ||
originalState, | ||
maxFailedRetries = MAX_TRANSPORT_RETRIES, | ||
failedAt, | ||
maxRetryTime = MAX_TRANSPORT_RETRY_TIME, | ||
failedRetryCount = 0, | ||
}: ScheduleTaskParams & { failedRetryCount?: number }): Promise<void> { | ||
}: ScheduleTaskParams & { failedAt: number; failedRetryCount?: number }): Promise<void> { | ||
HMSLogger.d(this.TAG, 'schedule: ', { category: TFC[category], error }); | ||
@@ -119,4 +120,5 @@ | ||
if (failedRetryCount >= maxFailedRetries || hasFailedDependency) { | ||
error.description += `. [${TFC[category]}] Could not recover after ${failedRetryCount} tries`; | ||
const timeElapsedSinceError = Date.now() - failedAt; | ||
if (timeElapsedSinceError >= maxRetryTime || hasFailedDependency) { | ||
error.description += `. [${TFC[category]}] Could not recover after ${timeElapsedSinceError} milliseconds`; | ||
@@ -151,3 +153,3 @@ if (hasFailedDependency) { | ||
const delay = this.getDelayForRetryCount(category, failedRetryCount); | ||
const delay = this.getDelayForRetryCount(category); | ||
@@ -179,3 +181,6 @@ HMSLogger.d( | ||
} | ||
HMSLogger.d(this.TAG, `schedule: [${TFC[category]}] [failedRetryCount=${failedRetryCount}] Recovered ♻️`); | ||
HMSLogger.d( | ||
this.TAG, | ||
`schedule: [${TFC[category]}] [failedRetryCount=${failedRetryCount}] Recovered ♻️ after ${timeElapsedSinceError}ms`, | ||
); | ||
} else { | ||
@@ -188,3 +193,4 @@ await this.scheduleTask({ | ||
originalState, | ||
maxFailedRetries, | ||
maxRetryTime, | ||
failedAt, | ||
failedRetryCount: failedRetryCount + 1, | ||
@@ -195,17 +201,14 @@ }); | ||
private getBaseDelayForTask(category: TFC, n: number) { | ||
private getDelayForRetryCount(category: TFC) { | ||
const jitter = category === TFC.JoinWSMessageFailed ? Math.random() * 2 : Math.random(); | ||
let delaySeconds = 0; | ||
if (category === TFC.JoinWSMessageFailed) { | ||
// linear backoff(2 + jitter for every retry) | ||
return 2; | ||
delaySeconds = 2 + jitter; | ||
} else if (category === TFC.SignalDisconnect) { | ||
delaySeconds = 1; | ||
} | ||
// exponential backoff | ||
return Math.pow(2, n); | ||
return delaySeconds * 1000; | ||
} | ||
private getDelayForRetryCount(category: TFC, n: number) { | ||
const delay = this.getBaseDelayForTask(category, n); | ||
const jitter = category === TFC.JoinWSMessageFailed ? Math.random() * 2 : Math.random(); | ||
return Math.round(Math.min(delay + jitter, MAX_TRANSPORT_RETRY_DELAY) * 1000); | ||
} | ||
private async setTimeoutPromise<T>(task: () => Promise<T>, delay: number): Promise<T> { | ||
@@ -212,0 +215,0 @@ return new Promise((resolve, reject) => { |
@@ -6,3 +6,3 @@ export const RENEGOTIATION_CALLBACK_ID = 'renegotiation-callback-id'; | ||
/** | ||
* Maximum number of retries that transport-layer will try | ||
* Maximum time that transport-layer will try | ||
* before giving up on the connection and returning a failure | ||
@@ -12,4 +12,3 @@ * | ||
*/ | ||
export const MAX_TRANSPORT_RETRIES = 5; | ||
export const MAX_TRANSPORT_RETRY_DELAY = 60; | ||
export const MAX_TRANSPORT_RETRY_TIME = 60_000; | ||
@@ -16,0 +15,0 @@ export const DEFAULT_SIGNAL_PING_TIMEOUT = 12_000; |
import HMSLogger from './logger'; | ||
import { ErrorFactory } from '../error/ErrorFactory'; | ||
import { HMSAction } from '../error/HMSAction'; | ||
import { Store } from '../sdk/store'; | ||
@@ -35,1 +37,11 @@ const TAG = `[VALIDATIONS]`; | ||
}; | ||
export const validatePublishParams = (store: Store) => { | ||
const publishParams = store.getPublishParams(); | ||
if (!publishParams) { | ||
throw ErrorFactory.GenericErrors.NotConnected( | ||
HMSAction.VALIDATION, | ||
'call addTrack after preview or join is successful', | ||
); | ||
} | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4799886
40808