-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maxPlaybackDrift
and positionUpdateInterval
scaling by audience s…
…ize (#796)
- Loading branch information
Showing
7 changed files
with
273 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/live-share-media/src/internals/PriorityTimeInterval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { TimeInterval } from "@microsoft/live-share"; | ||
|
||
function getScaledPriorityTimeMs( | ||
minMilliseconds: number, | ||
hasPriority: boolean, | ||
shouldPrioritize: boolean, | ||
scaleBy: number | ||
): number { | ||
if (!shouldPrioritize) return minMilliseconds; | ||
if (hasPriority) return minMilliseconds; | ||
return minMilliseconds * scaleBy; | ||
} | ||
|
||
/** | ||
* @hidden | ||
* Time interval that can scale based on a scaling function. | ||
*/ | ||
export class PriorityTimeInterval extends TimeInterval { | ||
/** | ||
* If true, local user has priority and will have the lowest possible millesecond value. | ||
*/ | ||
public hasPriority: boolean; | ||
/** | ||
* If true, milliseconds will be scaled when {@link hasPriority} is false. | ||
*/ | ||
public shouldPrioritize: boolean; | ||
/** | ||
* Function to get the scale ratio. | ||
*/ | ||
private getScaleBy: () => number; | ||
/** | ||
* Time interval that can scale based on a scaling function. | ||
* | ||
* @param defaultMilliseconds the default minimum milliseconds | ||
* @param getScaleByFn a function to scale the milliseconds by when {@link hasPriority} is false and {@link shouldPrioritize} is true. | ||
* @param defaultHasPriority the default {@link hasPriority} value | ||
* @param defaultShouldPrioritize the default {@link shouldPrioritize} value | ||
*/ | ||
constructor( | ||
defaultMilliseconds: number, | ||
getScaleByFn: () => number, | ||
defaultHasPriority: boolean = false, | ||
defaultShouldPrioritize: boolean = true | ||
) { | ||
super(defaultMilliseconds); | ||
this.hasPriority = defaultHasPriority; | ||
this.shouldPrioritize = defaultShouldPrioritize; | ||
this.getScaleBy = getScaleByFn; | ||
} | ||
|
||
public get milliseconds(): number { | ||
return getScaledPriorityTimeMs( | ||
this._milliseconds, | ||
this.hasPriority, | ||
this.shouldPrioritize, | ||
this.getScaleBy() | ||
); | ||
} | ||
|
||
public set milliseconds(value: number) { | ||
this._milliseconds = value; | ||
} | ||
|
||
public get minMilliseconds(): number { | ||
return this._milliseconds; | ||
} | ||
|
||
public get maxMilliseconds(): number { | ||
return getScaledPriorityTimeMs( | ||
this._milliseconds, | ||
false, | ||
this.shouldPrioritize, | ||
this.getScaleBy() | ||
); | ||
} | ||
} |
Oops, something went wrong.