diff --git a/demo/full/scripts/globals.d.ts b/demo/full/scripts/globals.d.ts index c56c2a32bd8..953c8d724e1 100644 --- a/demo/full/scripts/globals.d.ts +++ b/demo/full/scripts/globals.d.ts @@ -1,3 +1,2 @@ import "../../../src/typings/globals.d"; -import "../../../src/typings/next-tick"; import "../../../src/typings/object-assign"; diff --git a/package-lock.json b/package-lock.json index 66245418025..c2e4889fa71 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,9 +8,6 @@ "name": "rx-player", "version": "4.0.0-beta.3", "license": "Apache-2.0", - "dependencies": { - "next-tick": "1.1.0" - }, "devDependencies": { "@babel/core": "7.23.0", "@babel/plugin-transform-runtime": "7.22.15", @@ -11469,11 +11466,6 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, - "node_modules/next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" - }, "node_modules/nise": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", @@ -23027,11 +23019,6 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, - "next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" - }, "nise": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.4.tgz", diff --git a/package.json b/package.json index 69f77b71b7c..1a4e2541279 100644 --- a/package.json +++ b/package.json @@ -167,9 +167,6 @@ "type": "git", "url": "git://github.com/canalplus/rx-player.git" }, - "dependencies": { - "next-tick": "1.1.0" - }, "devDependencies": { "@babel/core": "7.23.0", "@babel/plugin-transform-runtime": "7.22.15", diff --git a/src/compat/patch_webkit_source_buffer.ts b/src/compat/patch_webkit_source_buffer.ts index 32f35569d09..67d6afa3c70 100644 --- a/src/compat/patch_webkit_source_buffer.ts +++ b/src/compat/patch_webkit_source_buffer.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import nextTick from "next-tick"; import EventEmitter from "../utils/event_emitter"; +import queueMicrotask from "../utils/queue_microtask"; import globalScope from "./global_scope"; import isNode from "./is_node"; @@ -57,7 +57,7 @@ export default function patchWebkitSourceBuffer() : void { sourceBufferWebkitProto._emitUpdate = function(eventName : string, val : unknown) { - nextTick(() => { + queueMicrotask(() => { /* eslint-disable no-invalid-this */ this.trigger(eventName, val); this.updating = false; diff --git a/src/core/stream/adaptation/adaptation_stream.ts b/src/core/stream/adaptation/adaptation_stream.ts index 8414e55ff3d..371e8c09aa0 100644 --- a/src/core/stream/adaptation/adaptation_stream.ts +++ b/src/core/stream/adaptation/adaptation_stream.ts @@ -1,4 +1,3 @@ -import nextTick from "next-tick"; import config from "../../../config"; import { formatError } from "../../../errors"; import log from "../../../log"; @@ -7,6 +6,7 @@ import assertUnreachable from "../../../utils/assert_unreachable"; import cancellableSleep from "../../../utils/cancellable_sleep"; import noop from "../../../utils/noop"; import objectAssign from "../../../utils/object_assign"; +import queueMicrotask from "../../../utils/queue_microtask"; import SharedReference, { createMappedReference, IReadOnlySharedReference, @@ -192,7 +192,7 @@ export default function AdaptationStream( // conditions where the inner logic would be called synchronously before // the next observation (which may reflect very different playback conditions) // is actually received. - return nextTick(() => { + return queueMicrotask(() => { playbackObserver.listen(() => { if (fnCancelSignal.isCancelled()) { return; diff --git a/src/core/stream/orchestrator/stream_orchestrator.ts b/src/core/stream/orchestrator/stream_orchestrator.ts index 95a8b425864..3fecf5d6827 100644 --- a/src/core/stream/orchestrator/stream_orchestrator.ts +++ b/src/core/stream/orchestrator/stream_orchestrator.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import nextTick from "next-tick"; import config from "../../../config"; import { MediaError } from "../../../errors"; import log from "../../../log"; @@ -22,6 +21,7 @@ import Manifest, { IDecipherabilityUpdateElement, Period, } from "../../../manifest"; +import queueMicrotask from "../../../utils/queue_microtask"; import { createMappedReference, IReadOnlySharedReference, @@ -351,7 +351,7 @@ export default function StreamOrchestrator( // Schedule micro task before checking the last playback observation // to reduce the risk of race conditions where the next observation // was going to be emitted synchronously. - nextTick(() => { + queueMicrotask(() => { if (orchestratorCancelSignal.isCancelled()) { return ; } @@ -554,7 +554,7 @@ export default function StreamOrchestrator( // conditions where the inner logic would be called synchronously before // the next observation (which may reflect very different playback // conditions) is actually received. - return nextTick(() => { + return queueMicrotask(() => { if (innerCancelSignal.isCancelled()) { return; } diff --git a/src/core/stream/period/period_stream.ts b/src/core/stream/period/period_stream.ts index fb055e45281..ee8fc37fb9a 100644 --- a/src/core/stream/period/period_stream.ts +++ b/src/core/stream/period/period_stream.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import nextTick from "next-tick"; import config from "../../../config"; import { formatError, @@ -26,6 +25,7 @@ import { Period, } from "../../../manifest"; import objectAssign from "../../../utils/object_assign"; +import queueMicrotask from "../../../utils/queue_microtask"; import { getLeftSizeOfBufferedTimeRange } from "../../../utils/ranges"; import SharedReference, { IReadOnlySharedReference, @@ -362,7 +362,7 @@ export default function PeriodStream( // is actually received. // It can happen when `askForMediaSourceReload` is called as a side-effect of // the same event that triggers the playback observation to be emitted. - nextTick(() => { + queueMicrotask(() => { playbackObserver.listen(() => { if (cancelSignal.isCancelled()) { return; diff --git a/src/typings/next-tick.d.ts b/src/typings/next-tick.d.ts deleted file mode 100644 index e8288a9f87f..00000000000 --- a/src/typings/next-tick.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright 2015 CANAL+ Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -declare module "next-tick" { - function nextTick( - fn : () => void - ) : void; - - export default nextTick; -} diff --git a/src/utils/queue_microtask.ts b/src/utils/queue_microtask.ts new file mode 100644 index 00000000000..97e6d1a4e0c --- /dev/null +++ b/src/utils/queue_microtask.ts @@ -0,0 +1,7 @@ +export default typeof queueMicrotask === "function" ? + queueMicrotask : + function queueMicrotaskPonyfill( + cb: () => void + ): void { + Promise.resolve().then(cb, () => cb()); + };