@@ -82,6 +82,7 @@ export class PlayerSdk {
8282 private playerOrigin : string | null = null ;
8383 private postMessageCallbacks : { [ callbackId : string ] : ( arg : any ) => void } = { } ;
8484 private iframeUrl : string ;
85+ private options : SdkOptions ;
8586
8687 static nextSdkPlayerId : number = 1 ;
8788
@@ -116,6 +117,7 @@ export class PlayerSdk {
116117 this . sdkInSync = false ;
117118 this . currentVideoReady = false ;
118119 this . playerOrigin = new URL ( this . iframeUrl ) . origin ;
120+ this . options = options ;
119121
120122 window . addEventListener ( "message" , ( message ) => {
121123 if ( message . origin === this . playerOrigin && parseInt ( message . data ?. sdkPlayerId , 10 ) === this . sdkPlayerId ) {
@@ -134,46 +136,64 @@ export class PlayerSdk {
134136
135137 loadConfig ( options : SdkOptions ) {
136138 this . currentVideoReady = false ;
139+ this . options = {
140+ ...this . options ,
141+ ...options ,
142+ } ;
137143 this . postMessage ( {
138144 message : 'loadConfig' ,
139- url : this . buildPlayerUrl ( options )
145+ url : this . buildPlayerUrl ( this . options )
140146 } ) ;
141147 }
142148
143149 play ( ) {
144150 this . postMessage ( { message : 'play' } ) ;
145151 }
146152 hideControls ( controls ?: ControlName [ ] ) {
153+ if ( ! controls ) {
154+ this . options . hideControls = true ;
155+ }
147156 this . postMessage ( { message : 'hideControls' , controls } , undefined , true ) ;
148157 }
149158 showControls ( controls ?: ControlName [ ] ) {
159+ if ( ! controls ) {
160+ this . options . hideControls = false ;
161+ }
150162 this . postMessage ( { message : 'showControls' , controls } , undefined , true ) ;
151163 }
152164 hideSubtitles ( ) {
165+ this . options . showSubtitles = false ;
153166 this . postMessage ( { message : 'hideSubtitles' } ) ;
154167 }
155168 showSubtitles ( ) {
169+ this . options . showSubtitles = true ;
156170 this . postMessage ( { message : 'showSubtitles' } ) ;
157171 }
158172 hideTitle ( ) {
173+ this . options . hideTitle = true ;
159174 this . postMessage ( { message : 'hideTitle' } ) ;
160175 }
161176 showTitle ( ) {
177+ this . options . hideTitle = false ;
162178 this . postMessage ( { message : 'showTitle' } ) ;
163179 }
164180 hidePoster ( ) {
181+ this . options . hidePoster = true ;
165182 this . postMessage ( { message : 'hidePoster' } ) ;
166183 }
167184 showPoster ( ) {
185+ this . options . hidePoster = false ;
168186 this . postMessage ( { message : 'showPoster' } ) ;
169187 }
170188 pause ( ) {
171189 this . postMessage ( { message : 'pause' } ) ;
172190 }
173191 mute ( ) {
192+ this . options . muted = true ;
174193 this . postMessage ( { message : 'mute' } ) ;
175194 }
176195 unmute ( ) {
196+ this . options . muted = false ;
177197 this . postMessage ( { message : 'unmute' } ) ;
178198 }
179199 seek ( time : number ) {
@@ -186,15 +206,19 @@ export class PlayerSdk {
186206 this . postMessage ( { message : 'setVolume' , volume } ) ;
187207 }
188208 setAutoplay ( autoplay : boolean ) {
209+ this . options . autoplay = autoplay ;
189210 this . postMessage ( { message : 'setAutoplay' , autoplay } ) ;
190211 }
191212 setLoop ( loop : boolean ) {
213+ this . options . loop = loop ;
192214 this . postMessage ( { message : 'setLoop' , loop } ) ;
193215 }
194216 setChromeless ( chromeless : boolean ) {
217+ this . options . chromeless = chromeless ;
195218 this . postMessage ( { message : 'setChromeless' , chromeless } ) ;
196219 }
197220 setPlaybackRate ( rate : number ) {
221+ this . options . playbackRate = rate ;
198222 this . postMessage ( { message : 'setPlaybackRate' , rate } , undefined , true ) ;
199223 }
200224 exitFullscreen ( ) {
0 commit comments