Skip to content

Commit aaf54a3

Browse files
Merge pull request #43 from apivideo/dont-reset-config-when-loadconfig
When loadConfig() is called, apply the last config settings
2 parents 347bd08 + 8a333cb commit aaf54a3

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All changes to this project will be documented in this file.
33

4+
## [1.2.19] - 2022-05-19
5+
- When loadConfig() is called, apply the last config settings
6+
47
## [1.2.18] - 2022-05-12
58
- Fix showControls & hideControls methods when called before the player is ready.
69

dist/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export declare class PlayerSdk {
7373
private playerOrigin;
7474
private postMessageCallbacks;
7575
private iframeUrl;
76+
private options;
7677
static nextSdkPlayerId: number;
7778
constructor(targetSelector: string | Element, userOptions?: SdkOptions);
7879
loadConfig(options: SdkOptions): void;

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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() {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@api.video/player-sdk",
3-
"version": "1.2.18",
3+
"version": "1.2.19",
44
"description": "api.video player SDK",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)