Skip to content

Commit

Permalink
feat: onInit, onInitError
Browse files Browse the repository at this point in the history
  • Loading branch information
pushpush committed Sep 27, 2024
1 parent d59d11e commit 7d19dbe
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 99 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ type Theme = {
<td>onJSLoadError</td>
<td>No</td>
</tr>
<tr>
<td>onInit</td>
<td>
playerId: string;
</td>
</tr>
<tr>
<td>onInitError</td>
<td>Error</td>
</tr>
<tr>
<td>onReady</td>
<td>
Expand Down
5 changes: 5 additions & 0 deletions dist/player.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export type BookmarkTypes = {
time: number;
title?: string;
};
export type EventInitTypes = {
playerId: string;
};
export type EventReadyTypes = {
currentTime: number;
duration: number;
Expand Down Expand Up @@ -106,6 +109,8 @@ export type PlayerPropsTypes = {
watermark?: WatermarkTypes;
localStorage?: boolean;
theme?: Theme;
onInit?: (data: EventInitTypes) => void;
onInitError?: (error: Error) => void;
onReady?: (data: EventReadyTypes) => void;
onQualityChanged?: (data: EventQualityChangedTypes) => void;
onCurrentTrackChanged?: (data: EventCurrentTrackChangedTypes) => void;
Expand Down
77 changes: 45 additions & 32 deletions dist/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ var Player = /*#__PURE__*/function (_Component) {

_this.create = function () {
try {
var _this$props4 = _this.props,
onInit = _this$props4.onInit,
onInitError = _this$props4.onInitError;
return Promise.resolve(_this.destroy()).then(function () {
var parentsRef = _this.parentsRef.current;

Expand All @@ -577,7 +580,7 @@ var Player = /*#__PURE__*/function (_Component) {
var playerDiv = document.createElement('div');
playerDiv.setAttribute('id', playerId);
parentsRef.appendChild(playerDiv);
/* fast re create player fix */
/* fast re-create player fix */

return Promise.resolve(new Promise(function (resolve) {
setTimeout(resolve, 0);
Expand All @@ -586,8 +589,18 @@ var Player = /*#__PURE__*/function (_Component) {
return;
}

return Promise.resolve(_this.createPlayer(playerId)).then(function (_this$createPlayer) {
_this.player = _this$createPlayer;
return Promise.resolve(new Promise(function (resolve, reject) {
_this.createPlayer(playerId).then(function (player) {
resolve(player);
onInit && onInit({
playerId: playerId
});
})["catch"](function (e) {
reject(e);
onInitError && onInitError(e);
});
})).then(function (_Promise) {
_this.player = _Promise;

_this.getEventList().forEach(function (event) {
var _this$player;
Expand Down Expand Up @@ -657,31 +670,31 @@ var Player = /*#__PURE__*/function (_Component) {
};

_this.createPlayer = function (playerId) {
var _this$props4 = _this.props,
title = _this$props4.title,
subtitle = _this$props4.subtitle,
poster = _this$props4.poster,
chapters = _this$props4.chapters,
vtt = _this$props4.vtt,
externalId = _this$props4.externalId,
drmAuthToken = _this$props4.drmAuthToken,
width = _this$props4.width,
height = _this$props4.height,
autoPause = _this$props4.autoPause,
autoPlay = _this$props4.autoPlay,
loop = _this$props4.loop,
muted = _this$props4.muted,
playsInline = _this$props4.playsInline,
preload = _this$props4.preload,
language = _this$props4.language,
controls = _this$props4.controls,
mainPlayButton = _this$props4.mainPlayButton,
playbackRateButton = _this$props4.playbackRateButton,
bookmarks = _this$props4.bookmarks,
actions = _this$props4.actions,
watermark = _this$props4.watermark,
localStorage = _this$props4.localStorage,
theme = _this$props4.theme;
var _this$props5 = _this.props,
title = _this$props5.title,
subtitle = _this$props5.subtitle,
poster = _this$props5.poster,
chapters = _this$props5.chapters,
vtt = _this$props5.vtt,
externalId = _this$props5.externalId,
drmAuthToken = _this$props5.drmAuthToken,
width = _this$props5.width,
height = _this$props5.height,
autoPause = _this$props5.autoPause,
autoPlay = _this$props5.autoPlay,
loop = _this$props5.loop,
muted = _this$props5.muted,
playsInline = _this$props5.playsInline,
preload = _this$props5.preload,
language = _this$props5.language,
controls = _this$props5.controls,
mainPlayButton = _this$props5.mainPlayButton,
playbackRateButton = _this$props5.playbackRateButton,
bookmarks = _this$props5.bookmarks,
actions = _this$props5.actions,
watermark = _this$props5.watermark,
localStorage = _this$props5.localStorage,
theme = _this$props5.theme;
var options = {
url: _this.getIFrameUrl(),
size: {
Expand Down Expand Up @@ -1123,10 +1136,10 @@ var Player = /*#__PURE__*/function (_Component) {
};

_proto.render = function render() {
var _this$props5 = this.props,
className = _this$props5.className,
style = _this$props5.style,
onJSLoadError = _this$props5.onJSLoadError;
var _this$props6 = this.props,
className = _this$props6.className,
style = _this$props6.style,
onJSLoadError = _this$props6.onJSLoadError;
return React__default['default'].createElement(Loader, {
onJSLoad: this.handleJSLoad,
onJSLoadError: onJSLoadError
Expand Down
77 changes: 45 additions & 32 deletions dist/player.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ var Player = /*#__PURE__*/function (_Component) {

_this.create = function () {
try {
var _this$props4 = _this.props,
onInit = _this$props4.onInit,
onInitError = _this$props4.onInitError;
return Promise.resolve(_this.destroy()).then(function () {
var parentsRef = _this.parentsRef.current;

Expand All @@ -573,7 +576,7 @@ var Player = /*#__PURE__*/function (_Component) {
var playerDiv = document.createElement('div');
playerDiv.setAttribute('id', playerId);
parentsRef.appendChild(playerDiv);
/* fast re create player fix */
/* fast re-create player fix */

return Promise.resolve(new Promise(function (resolve) {
setTimeout(resolve, 0);
Expand All @@ -582,8 +585,18 @@ var Player = /*#__PURE__*/function (_Component) {
return;
}

return Promise.resolve(_this.createPlayer(playerId)).then(function (_this$createPlayer) {
_this.player = _this$createPlayer;
return Promise.resolve(new Promise(function (resolve, reject) {
_this.createPlayer(playerId).then(function (player) {
resolve(player);
onInit && onInit({
playerId: playerId
});
})["catch"](function (e) {
reject(e);
onInitError && onInitError(e);
});
})).then(function (_Promise) {
_this.player = _Promise;

_this.getEventList().forEach(function (event) {
var _this$player;
Expand Down Expand Up @@ -653,31 +666,31 @@ var Player = /*#__PURE__*/function (_Component) {
};

_this.createPlayer = function (playerId) {
var _this$props4 = _this.props,
title = _this$props4.title,
subtitle = _this$props4.subtitle,
poster = _this$props4.poster,
chapters = _this$props4.chapters,
vtt = _this$props4.vtt,
externalId = _this$props4.externalId,
drmAuthToken = _this$props4.drmAuthToken,
width = _this$props4.width,
height = _this$props4.height,
autoPause = _this$props4.autoPause,
autoPlay = _this$props4.autoPlay,
loop = _this$props4.loop,
muted = _this$props4.muted,
playsInline = _this$props4.playsInline,
preload = _this$props4.preload,
language = _this$props4.language,
controls = _this$props4.controls,
mainPlayButton = _this$props4.mainPlayButton,
playbackRateButton = _this$props4.playbackRateButton,
bookmarks = _this$props4.bookmarks,
actions = _this$props4.actions,
watermark = _this$props4.watermark,
localStorage = _this$props4.localStorage,
theme = _this$props4.theme;
var _this$props5 = _this.props,
title = _this$props5.title,
subtitle = _this$props5.subtitle,
poster = _this$props5.poster,
chapters = _this$props5.chapters,
vtt = _this$props5.vtt,
externalId = _this$props5.externalId,
drmAuthToken = _this$props5.drmAuthToken,
width = _this$props5.width,
height = _this$props5.height,
autoPause = _this$props5.autoPause,
autoPlay = _this$props5.autoPlay,
loop = _this$props5.loop,
muted = _this$props5.muted,
playsInline = _this$props5.playsInline,
preload = _this$props5.preload,
language = _this$props5.language,
controls = _this$props5.controls,
mainPlayButton = _this$props5.mainPlayButton,
playbackRateButton = _this$props5.playbackRateButton,
bookmarks = _this$props5.bookmarks,
actions = _this$props5.actions,
watermark = _this$props5.watermark,
localStorage = _this$props5.localStorage,
theme = _this$props5.theme;
var options = {
url: _this.getIFrameUrl(),
size: {
Expand Down Expand Up @@ -1119,10 +1132,10 @@ var Player = /*#__PURE__*/function (_Component) {
};

_proto.render = function render() {
var _this$props5 = this.props,
className = _this$props5.className,
style = _this$props5.style,
onJSLoadError = _this$props5.onJSLoadError;
var _this$props6 = this.props,
className = _this$props6.className,
style = _this$props6.style,
onJSLoadError = _this$props6.onJSLoadError;
return React.createElement(Loader, {
onJSLoad: this.handleJSLoad,
onJSLoadError: onJSLoadError
Expand Down
77 changes: 45 additions & 32 deletions dist/player.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@

_this.create = function () {
try {
var _this$props4 = _this.props,
onInit = _this$props4.onInit,
onInitError = _this$props4.onInitError;
return Promise.resolve(_this.destroy()).then(function () {
var parentsRef = _this.parentsRef.current;

Expand All @@ -580,7 +583,7 @@
var playerDiv = document.createElement('div');
playerDiv.setAttribute('id', playerId);
parentsRef.appendChild(playerDiv);
/* fast re create player fix */
/* fast re-create player fix */

return Promise.resolve(new Promise(function (resolve) {
setTimeout(resolve, 0);
Expand All @@ -589,8 +592,18 @@
return;
}

return Promise.resolve(_this.createPlayer(playerId)).then(function (_this$createPlayer) {
_this.player = _this$createPlayer;
return Promise.resolve(new Promise(function (resolve, reject) {
_this.createPlayer(playerId).then(function (player) {
resolve(player);
onInit && onInit({
playerId: playerId
});
})["catch"](function (e) {
reject(e);
onInitError && onInitError(e);
});
})).then(function (_Promise) {
_this.player = _Promise;

_this.getEventList().forEach(function (event) {
var _this$player;
Expand Down Expand Up @@ -660,31 +673,31 @@
};

_this.createPlayer = function (playerId) {
var _this$props4 = _this.props,
title = _this$props4.title,
subtitle = _this$props4.subtitle,
poster = _this$props4.poster,
chapters = _this$props4.chapters,
vtt = _this$props4.vtt,
externalId = _this$props4.externalId,
drmAuthToken = _this$props4.drmAuthToken,
width = _this$props4.width,
height = _this$props4.height,
autoPause = _this$props4.autoPause,
autoPlay = _this$props4.autoPlay,
loop = _this$props4.loop,
muted = _this$props4.muted,
playsInline = _this$props4.playsInline,
preload = _this$props4.preload,
language = _this$props4.language,
controls = _this$props4.controls,
mainPlayButton = _this$props4.mainPlayButton,
playbackRateButton = _this$props4.playbackRateButton,
bookmarks = _this$props4.bookmarks,
actions = _this$props4.actions,
watermark = _this$props4.watermark,
localStorage = _this$props4.localStorage,
theme = _this$props4.theme;
var _this$props5 = _this.props,
title = _this$props5.title,
subtitle = _this$props5.subtitle,
poster = _this$props5.poster,
chapters = _this$props5.chapters,
vtt = _this$props5.vtt,
externalId = _this$props5.externalId,
drmAuthToken = _this$props5.drmAuthToken,
width = _this$props5.width,
height = _this$props5.height,
autoPause = _this$props5.autoPause,
autoPlay = _this$props5.autoPlay,
loop = _this$props5.loop,
muted = _this$props5.muted,
playsInline = _this$props5.playsInline,
preload = _this$props5.preload,
language = _this$props5.language,
controls = _this$props5.controls,
mainPlayButton = _this$props5.mainPlayButton,
playbackRateButton = _this$props5.playbackRateButton,
bookmarks = _this$props5.bookmarks,
actions = _this$props5.actions,
watermark = _this$props5.watermark,
localStorage = _this$props5.localStorage,
theme = _this$props5.theme;
var options = {
url: _this.getIFrameUrl(),
size: {
Expand Down Expand Up @@ -1126,10 +1139,10 @@
};

_proto.render = function render() {
var _this$props5 = this.props,
className = _this$props5.className,
style = _this$props5.style,
onJSLoadError = _this$props5.onJSLoadError;
var _this$props6 = this.props,
className = _this$props6.className,
style = _this$props6.style,
onJSLoadError = _this$props6.onJSLoadError;
return React__default['default'].createElement(Loader, {
onJSLoad: this.handleJSLoad,
onJSLoadError: onJSLoadError
Expand Down
Loading

0 comments on commit 7d19dbe

Please sign in to comment.