File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,18 @@ export type SampleGroupEntryKind = InstanceOf<
89
89
Extends < BoxRegistry [ 'sampleGroupEntry' ] , typeof SampleGroupEntry >
90
90
> ;
91
91
92
+ export type AllRegisteredBoxes = {
93
+ [ K in AllIdentifiers ] : K extends keyof BoxRegistry [ 'box' ]
94
+ ? InstanceOf < BoxRegistry [ 'box' ] [ K ] >
95
+ : K extends keyof BoxRegistry [ 'sampleEntry' ]
96
+ ? InstanceOf < BoxRegistry [ 'sampleEntry' ] [ K ] >
97
+ : K extends keyof BoxRegistry [ 'sampleGroupEntry' ]
98
+ ? InstanceOf < BoxRegistry [ 'sampleGroupEntry' ] [ K ] >
99
+ : K extends keyof BoxRegistry [ 'uuid' ]
100
+ ? InstanceOf < BoxRegistry [ 'uuid' ] [ K ] >
101
+ : never ;
102
+ } ;
103
+
92
104
export interface FragmentedTrack < TUser > {
93
105
id : number ;
94
106
user : TUser ;
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ import { BoxRegistry } from '#/registry';
84
84
import { MP4BoxStream } from '#/stream' ;
85
85
import type {
86
86
AllIdentifiers ,
87
+ AllRegisteredBoxes ,
87
88
BoxKind ,
88
89
Description ,
89
90
EntityGroup ,
@@ -921,17 +922,17 @@ export class ISOFile<TSegmentUser = unknown, TSampleUser = unknown> {
921
922
}
922
923
923
924
/* Find and return specific boxes using recursion and early return */
924
- getBox ( type : AllIdentifiers ) {
925
+ getBox < T extends AllIdentifiers > ( type : T ) : AllRegisteredBoxes [ T ] {
925
926
const result = this . getBoxes ( type , true ) ;
926
927
return result . length ? result [ 0 ] : undefined ;
927
928
}
928
929
929
- getBoxes ( type : AllIdentifiers , returnEarly : boolean ) {
930
- const result : Array < Box > = [ ] ;
930
+ getBoxes < T extends AllIdentifiers > ( type : T , returnEarly : boolean ) {
931
+ const result : Array < AllRegisteredBoxes [ T ] > = [ ] ;
931
932
932
933
const sweep = ( root : Box | ISOFile ) => {
933
934
if ( root instanceof Box && root . type && root . type === type ) {
934
- result . push ( root ) ;
935
+ result . push ( root as unknown as AllRegisteredBoxes [ T ] ) ;
935
936
}
936
937
937
938
const inner : Array < Box > = [ ] ;
You can’t perform that action at this time.
0 commit comments