@@ -3,21 +3,19 @@ import { Events } from "./types";
33import type {
44 Asset ,
55 AudioTrack ,
6- HlsPlayerEventMap ,
76 Interstitial ,
87 Playhead ,
98 Quality ,
109 SubtitleTrack ,
1110} from "./types" ;
12- import type { EventEmitter } from "tseep" ;
1311
1412interface MediaShim {
1513 currentTime : number ;
1614 duration : number ;
1715}
1816
1917interface StateParams {
20- emitter : EventEmitter < HlsPlayerEventMap > ;
18+ onEvent ( event : Events ) : void ;
2119 getTiming ( ) : {
2220 primary ?: MediaShim | null ;
2321 asset ?: MediaShim | null ;
@@ -69,7 +67,7 @@ export class State implements StateProperties {
6967 }
7068 this . ready = true ;
7169 this . requestTimingSync ( ) ;
72- this . emit_ ( Events . READY ) ;
70+ this . params_ . onEvent ( Events . READY ) ;
7371 }
7472
7573 setPlayhead ( playhead : Playhead ) {
@@ -83,20 +81,20 @@ export class State implements StateProperties {
8381 this . requestTimingSync ( ) ;
8482 }
8583
86- this . emit_ ( Events . PLAYHEAD_CHANGE ) ;
84+ this . params_ . onEvent ( Events . PLAYHEAD_CHANGE ) ;
8785 }
8886
8987 setStarted ( ) {
9088 if ( this . started ) {
9189 return ;
9290 }
9391 this . started = true ;
94- this . emit_ ( Events . STARTED ) ;
92+ this . params_ . onEvent ( Events . STARTED ) ;
9593 }
9694
9795 setInterstitial ( interstitial : Interstitial | null ) {
9896 this . interstitial = interstitial ;
99- this . emit_ ( Events . INTERSTITIAL_CHANGE ) ;
97+ this . params_ . onEvent ( Events . INTERSTITIAL_CHANGE ) ;
10098 }
10199
102100 setAsset ( asset : Omit < Asset , "time" | "duration" > | null ) {
@@ -121,12 +119,12 @@ export class State implements StateProperties {
121119
122120 if ( diff ( this . qualities ) !== diff ( qualities ) ) {
123121 this . qualities = qualities ;
124- this . emit_ ( Events . QUALITIES_CHANGE ) ;
122+ this . params_ . onEvent ( Events . QUALITIES_CHANGE ) ;
125123 }
126124
127125 if ( autoQuality !== this . autoQuality ) {
128126 this . autoQuality = autoQuality ;
129- this . emit_ ( Events . AUTO_QUALITY_CHANGE ) ;
127+ this . params_ . onEvent ( Events . AUTO_QUALITY_CHANGE ) ;
130128 }
131129 }
132130
@@ -135,7 +133,7 @@ export class State implements StateProperties {
135133
136134 if ( diff ( this . audioTracks ) !== diff ( audioTracks ) ) {
137135 this . audioTracks = audioTracks ;
138- this . emit_ ( Events . AUDIO_TRACKS_CHANGE ) ;
136+ this . params_ . onEvent ( Events . AUDIO_TRACKS_CHANGE ) ;
139137 }
140138 }
141139
@@ -148,7 +146,7 @@ export class State implements StateProperties {
148146 diff ( this . subtitleTracks ) !== diff ( subtitleTracks )
149147 ) {
150148 this . subtitleTracks = subtitleTracks ;
151- this . emit_ ( Events . SUBTITLE_TRACKS_CHANGE ) ;
149+ this . params_ . onEvent ( Events . SUBTITLE_TRACKS_CHANGE ) ;
152150 }
153151 }
154152
@@ -157,20 +155,20 @@ export class State implements StateProperties {
157155 return ;
158156 }
159157 this . volume = volume ;
160- this . emit_ ( Events . VOLUME_CHANGE ) ;
158+ this . params_ . onEvent ( Events . VOLUME_CHANGE ) ;
161159 }
162160
163161 setSeeking ( seeking : boolean ) {
164162 if ( seeking === this . seeking ) {
165163 return ;
166164 }
167165 this . seeking = seeking ;
168- this . emit_ ( Events . SEEKING_CHANGE ) ;
166+ this . params_ . onEvent ( Events . SEEKING_CHANGE ) ;
169167 }
170168
171169 setCuePoints ( cuePoints : number [ ] ) {
172170 this . cuePoints = cuePoints ;
173- this . emit_ ( Events . CUEPOINTS_CHANGE ) ;
171+ this . params_ . onEvent ( Events . CUEPOINTS_CHANGE ) ;
174172 }
175173
176174 requestTimingSync ( ) {
@@ -195,7 +193,7 @@ export class State implements StateProperties {
195193 }
196194
197195 if ( shouldEmit ) {
198- this . emit_ ( Events . TIME_CHANGE ) ;
196+ this . params_ . onEvent ( Events . TIME_CHANGE ) ;
199197 }
200198 }
201199
@@ -227,11 +225,6 @@ export class State implements StateProperties {
227225 return oldTime !== target . time || oldDuration !== target . duration ;
228226 }
229227
230- private emit_ ( event : Events ) {
231- this . params_ . emitter . emit ( event ) ;
232- this . params_ . emitter . emit ( "*" , event ) ;
233- }
234-
235228 ready = noState . ready ;
236229 playhead = noState . playhead ;
237230 started = noState . started ;
0 commit comments