Skip to content

Commit

Permalink
fix: use math.pow for max_safe_integer
Browse files Browse the repository at this point in the history
  • Loading branch information
eswarclynn committed Feb 27, 2024
1 parent 02b4dd1 commit e065090
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from './interfaces';
import { HMSTrackStats } from '../../interfaces';
import { HMSWebrtcStats } from '../../rtc-stats';
import { JAVA_INTEGER_MAX_VALUE, SUBSCRIBE_STATS_SAMPLE_WINDOW } from '../../utils/constants';
import { MAX_SAFE_INTEGER, SUBSCRIBE_STATS_SAMPLE_WINDOW } from '../../utils/constants';
import AnalyticsEventFactory from '../AnalyticsEventFactory';

export class SubscribeStatsAnalytics extends BaseStatsAnalytics {
Expand Down Expand Up @@ -93,11 +93,11 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics {
const videoTrack = peer?.videoTrack;
const areBothTracksEnabled = audioTrack && videoTrack && audioTrack.enabled && videoTrack.enabled;
if (!areBothTracksEnabled) {
return JAVA_INTEGER_MAX_VALUE;
return MAX_SAFE_INTEGER;
}
const audioStats = hmsStats.getRemoteTrackStats(audioTrack.trackId);
if (!audioStats) {
return JAVA_INTEGER_MAX_VALUE;
return MAX_SAFE_INTEGER;
}
return audioStats.timestamp - trackStats.timestamp;
}
Expand Down Expand Up @@ -179,10 +179,10 @@ class RunningRemoteTrackAnalytics extends RunningTrackAnalytics {
private calculateAvgAvSyncForSample() {
const avSyncValues = this.tempStats.map(stat => stat.avSync);
const validAvSyncValues: number[] = avSyncValues.filter(
(value): value is number => value !== undefined && value !== JAVA_INTEGER_MAX_VALUE,
(value): value is number => value !== undefined && value !== MAX_SAFE_INTEGER,
);
if (validAvSyncValues.length === 0) {
return JAVA_INTEGER_MAX_VALUE;
return MAX_SAFE_INTEGER;
}
return validAvSyncValues.reduce((a, b) => a + b, 0) / validAvSyncValues.length;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hms-video-store/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const PUBLISH_STATS_PUSH_INTERVAL = 300;
export const SUBSCRIBE_STATS_SAMPLE_WINDOW = 10;
export const SUBSCRIBE_STATS_PUSH_INTERVAL = 60;

export const JAVA_INTEGER_MAX_VALUE = 2147483647;
export const MAX_SAFE_INTEGER = Math.pow(2, 31) - 1;

export const HMSEvents = {
DEVICE_CHANGE: 'device-change',
Expand Down

0 comments on commit e065090

Please sign in to comment.