-
-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Playhead position change bug. (#324)
* Fix issue with not loading requested by engine segment. * Fix types error.
- Loading branch information
1 parent
39ec83d
commit f9382a6
Showing
12 changed files
with
118 additions
and
104 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
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
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
49 changes: 49 additions & 0 deletions
49
packages/p2p-media-loader-core/src/requests/engine-request.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,49 @@ | ||
import { Segment, SegmentResponse } from "../types"; | ||
|
||
export type EngineCallbacks = { | ||
onSuccess: (response: SegmentResponse) => void; | ||
onError: (reason: CoreRequestError) => void; | ||
}; | ||
|
||
export class EngineRequest { | ||
private _status: "pending" | "succeed" | "failed" | "aborted" = "pending"; | ||
|
||
constructor( | ||
readonly segment: Segment, | ||
readonly engineCallbacks: EngineCallbacks | ||
) {} | ||
|
||
get status() { | ||
return this._status; | ||
} | ||
|
||
resolve(data: ArrayBuffer, bandwidth: number) { | ||
this.throwErrorIfNotPending(); | ||
this._status = "succeed"; | ||
this.engineCallbacks.onSuccess({ data, bandwidth }); | ||
} | ||
|
||
reject() { | ||
this.throwErrorIfNotPending(); | ||
this._status = "failed"; | ||
this.engineCallbacks.onError(new CoreRequestError("failed")); | ||
} | ||
|
||
abort() { | ||
this.throwErrorIfNotPending(); | ||
this._status = "aborted"; | ||
this.engineCallbacks.onError(new CoreRequestError("aborted")); | ||
} | ||
|
||
private throwErrorIfNotPending() { | ||
if (this._status !== "pending") { | ||
throw new Error("Engine request has been already settled."); | ||
} | ||
} | ||
} | ||
|
||
export class CoreRequestError extends Error { | ||
constructor(readonly type: "failed" | "aborted") { | ||
super(); | ||
} | ||
} |
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
Oops, something went wrong.