File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed
packages/av-cliper/src/clips Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @webav/av-cliper ' : minor
3+ ---
4+
5+ feat: ImgClip supports the tickInterceptor method
Original file line number Diff line number Diff line change 1- import { expect , test } from 'vitest' ;
1+ import { expect , test , vi } from 'vitest' ;
22import { ImgClip } from '..' ;
33
44const animated_gif = `//${ location . host } /img/animated.gif` ;
@@ -32,3 +32,17 @@ test('clone ImgClip', async () => {
3232 const { state } = await cloneClip . tick ( 10e6 ) ;
3333 expect ( state ) . toBe ( 'success' ) ;
3434} ) ;
35+
36+ test ( 'ImgClip tickInterceptor' , async ( ) => {
37+ const clip = new ImgClip ( ( await fetch ( static_jpg ) ) . body ! ) ;
38+ clip . tickInterceptor = vi . fn ( ) ;
39+ await clip . ready ;
40+ await clip . tick ( 10e6 ) ;
41+ expect ( clip . tickInterceptor ) . toBeCalledWith (
42+ 10e6 ,
43+ expect . objectContaining ( {
44+ state : 'success' ,
45+ video : expect . any ( ImageBitmap ) ,
46+ } ) ,
47+ ) ;
48+ } ) ;
Original file line number Diff line number Diff line change @@ -119,25 +119,30 @@ export class ImgClip implements IClip {
119119 Log . info ( 'ImgClip ready:' , this . #meta) ;
120120 }
121121
122+ tickInterceptor : < T extends Awaited < ReturnType < ImgClip [ 'tick' ] > > > (
123+ time : number ,
124+ tickRet : T ,
125+ ) => Promise < T > = async ( _ , tickRet ) => tickRet ;
126+
122127 async tick ( time : number ) : Promise < {
123128 video : ImageBitmap | VideoFrame ;
124129 state : 'success' ;
125130 } > {
126131 if ( this . #img != null ) {
127- return {
132+ return await this . tickInterceptor ( time , {
128133 video : await createImageBitmap ( this . #img) ,
129134 state : 'success' ,
130- } ;
135+ } ) ;
131136 }
132137 const tt = time % this . #meta. duration ;
133- return {
138+ return await this . tickInterceptor ( time , {
134139 video : (
135140 this . #frames. find (
136141 ( f ) => tt >= f . timestamp && tt <= f . timestamp + ( f . duration ?? 0 ) ,
137142 ) ?? this . #frames[ 0 ]
138143 ) . clone ( ) ,
139144 state : 'success' ,
140- } ;
145+ } ) ;
141146 }
142147
143148 async split ( time : number ) {
You can’t perform that action at this time.
0 commit comments