@carbon/ibmdotcom-services 2.43.0 → 2.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,371 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+ var _windowOrGlobal = _interopRequireDefault(require("window-or-global"));
14
+ var _ref, _process$env$REACT_AP, _process, _process2, _ref2, _process$env$REACT_AP2, _process3, _process4, _ref3, _process$env$REACT_AP3, _process5, _process6, _ref4, _process$env$REACT_AP4, _process7, _process8, _ref5, _process$env$REACT_AP5, _process9, _process0;
15
+ /**
16
+ * Copyright IBM Corp. 2020, 2024
17
+ *
18
+ * This source code is licensed under the Apache-2.0 license found in the
19
+ * LICENSE file in the root directory of this source tree.
20
+ */
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ /**
24
+ * Sets the Kaltura Partner ID
25
+ *
26
+ * @type {number}
27
+ * @private
28
+ */
29
+ var _partnerId = (_ref = (_process$env$REACT_AP = (_process = process) === null || _process === void 0 || (_process = _process.env) === null || _process === void 0 ? void 0 : _process.REACT_APP_KALTURA_PARTNER_ID) !== null && _process$env$REACT_AP !== void 0 ? _process$env$REACT_AP : (_process2 = process) === null || _process2 === void 0 || (_process2 = _process2.env) === null || _process2 === void 0 ? void 0 : _process2.KALTURA_PARTNER_ID) !== null && _ref !== void 0 ? _ref :
30
+ // 1773841;
31
+ 1773841;
32
+
33
+ /**
34
+ * Sets the Kaltura UIConf IDs
35
+ *
36
+ * @type {enum}
37
+ * @private
38
+ */
39
+ var _uiConfIds = {
40
+ VIDEO: (_ref2 = (_process$env$REACT_AP2 = (_process3 = process) === null || _process3 === void 0 || (_process3 = _process3.env) === null || _process3 === void 0 ? void 0 : _process3.REACT_APP_KALTURA_UICONF_ID_VIDEO) !== null && _process$env$REACT_AP2 !== void 0 ? _process$env$REACT_AP2 : (_process4 = process) === null || _process4 === void 0 || (_process4 = _process4.env) === null || _process4 === void 0 ? void 0 : _process4.KALTURA_UICONF_ID_VIDEO) !== null && _ref2 !== void 0 ? _ref2 : 57792212,
41
+ AUDIO: (_ref3 = (_process$env$REACT_AP3 = (_process5 = process) === null || _process5 === void 0 || (_process5 = _process5.env) === null || _process5 === void 0 ? void 0 : _process5.REACT_APP_KALTURA_UICONF_ID_AUDIO) !== null && _process$env$REACT_AP3 !== void 0 ? _process$env$REACT_AP3 : (_process6 = process) === null || _process6 === void 0 || (_process6 = _process6.env) === null || _process6 === void 0 ? void 0 : _process6.KALTURA_UICONF_ID_AUDIO) !== null && _ref3 !== void 0 ? _ref3 : 57792222,
42
+ PLAYLIST: (_ref4 = (_process$env$REACT_AP4 = (_process7 = process) === null || _process7 === void 0 || (_process7 = _process7.env) === null || _process7 === void 0 ? void 0 : _process7.REACT_APP_KALTURA_UICONF_ID_PLAYLIST) !== null && _process$env$REACT_AP4 !== void 0 ? _process$env$REACT_AP4 : (_process8 = process) === null || _process8 === void 0 || (_process8 = _process8.env) === null || _process8 === void 0 ? void 0 : _process8.KALTURA_UICONF_ID_PLAYLIST) !== null && _ref4 !== void 0 ? _ref4 : 57792212,
43
+ REELS: (_ref5 = (_process$env$REACT_AP5 = (_process9 = process) === null || _process9 === void 0 || (_process9 = _process9.env) === null || _process9 === void 0 ? void 0 : _process9.REACT_APP_KALTURA_UICONF_ID_REELS) !== null && _process$env$REACT_AP5 !== void 0 ? _process$env$REACT_AP5 : (_process0 = process) === null || _process0 === void 0 || (_process0 = _process0.env) === null || _process0 === void 0 ? void 0 : _process0.KALTURA_UICONF_ID_REELS) !== null && _ref5 !== void 0 ? _ref5 : 57792212
44
+ };
45
+
46
+ /**
47
+ * The IBM Mediacenter Loader and Player Environment
48
+ * to be called
49
+ *
50
+ * @type {string}
51
+ * @private
52
+ */
53
+ var _ibmEnvironment = process && (process.env.REACT_APP_KALTURA_ENVIRONMENT || process.env.KALTURA_ENVIRONMENT) || 'LATEST';
54
+
55
+ /**
56
+ * All the available enviornments for the Streaming Services Kaltura Player Script
57
+ *
58
+ * @type {enum}
59
+ * @private
60
+ */
61
+ var _ibmEnvironments = {
62
+ DEVELOPMENT: 'development',
63
+ LATEST: 'latest',
64
+ NEXT: 'next'
65
+ };
66
+
67
+ /**
68
+ * Streaming Services Kaltura Player Script URL
69
+ *
70
+ * @private
71
+ */
72
+ var _ibmScriptUrl = function _ibmScriptUrl() {
73
+ var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _ibmEnvironment;
74
+ return "https://1.www.s81c.com/common/mediacenter/player/loader/".concat(_ibmEnvironments[environment], "/loader.js");
75
+ };
76
+
77
+ /**
78
+ * Returns boolean if the _scriptLoading and _scriptLoaded flag is false
79
+ *
80
+ * @private
81
+ */
82
+ function _loadScript() {
83
+ var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _ibmEnvironment;
84
+ _scriptLoading = true;
85
+ var script = document.createElement('script');
86
+ script.src = _ibmScriptUrl(environment);
87
+ script.async = true;
88
+ document.body.appendChild(script);
89
+ }
90
+
91
+ /**
92
+ * Number of times to retry the script ready loop before failing
93
+ *
94
+ * @type {number}
95
+ * @private
96
+ */
97
+ var _timeoutRetries = 50;
98
+
99
+ /**
100
+ * Tracks the number of attempts for the script ready loop
101
+ *
102
+ * @type {number}
103
+ * @private
104
+ */
105
+ var _attempt = 0;
106
+
107
+ /**
108
+ * Tracks the script status
109
+ *
110
+ * @type {boolean} _scriptLoading to track the script loading or not
111
+ * @private
112
+ */
113
+ var _scriptLoading = false;
114
+
115
+ /**
116
+ * Timeout loop to check script state is the _scriptLoaded state or _scriptLoading state
117
+ *
118
+ * @param {Function} resolve Resolve function
119
+ * @param {Function} reject Reject function
120
+ * @private
121
+ */
122
+ function _scriptReady(resolve, reject) {
123
+ var _root$IBM;
124
+ var environment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _ibmEnvironment;
125
+ /**
126
+ * @param {object} root?.IBM.Mediacenter.player if exists then resolve
127
+ */
128
+ if (_windowOrGlobal.default !== null && _windowOrGlobal.default !== void 0 && (_root$IBM = _windowOrGlobal.default.IBM) !== null && _root$IBM !== void 0 && (_root$IBM = _root$IBM.Mediacenter) !== null && _root$IBM !== void 0 && _root$IBM.player) {
129
+ _scriptLoading = false;
130
+ resolve();
131
+ } else if (_scriptLoading) {
132
+ _attempt++;
133
+ if (_attempt < _timeoutRetries) {
134
+ setTimeout(function () {
135
+ _scriptReady(resolve, reject, environment);
136
+ }, 100);
137
+ } else {
138
+ reject();
139
+ }
140
+ } else {
141
+ _loadScript(environment);
142
+ _scriptReady(resolve, reject, environment);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * KalturaPlayerAPI class with methods of checking script state and
148
+ * embed media meta data and api data
149
+ *
150
+ * In order to set the Partner ID/UIConf ID, set the following environment
151
+ * variables:
152
+ *
153
+ * - KALTURA_PARTNER_ID
154
+ * - KALTURA_UICONF_ID
155
+ */
156
+ var KalturaPlayerAPIV7 = /*#__PURE__*/function () {
157
+ function KalturaPlayerAPIV7() {
158
+ (0, _classCallCheck2.default)(this, KalturaPlayerAPIV7);
159
+ }
160
+ return (0, _createClass2.default)(KalturaPlayerAPIV7, null, [{
161
+ key: "checkScript",
162
+ value:
163
+ /**
164
+ *
165
+ * Gets the full _scriptReady state
166
+ *
167
+ * @returns {Promise<*>} Promise kaltura media player file
168
+ */
169
+ function checkScript() {
170
+ var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _ibmEnvironment;
171
+ return new Promise(function (resolve, reject) {
172
+ _scriptReady(resolve, reject, environment);
173
+ });
174
+ }
175
+
176
+ /**
177
+ * Creates thumbnail image url with customizable params
178
+ *
179
+ * @param {object} params param object
180
+ * @param {string} params.mediaId specify the kaltura media id
181
+ * @param {string} params.height specify height in pixels
182
+ * @param {string} params.width specify width in pixels
183
+ * @param {string} params.partnerId specify mediacenter's partner id
184
+ * @returns {string} url of thumbnail image
185
+ * @example
186
+ * import { KalturaPlayerAPI } from '@carbon/ibmdotcom-services';
187
+ *
188
+ * function thumbnail() {
189
+ * const thumbnailData = {
190
+ * mediaId: '1_9h94wo6b',
191
+ * height: '240',
192
+ * width: '320'
193
+ * }
194
+ * const thumbnailUrl = KalturaPlayerAPI.getThumbnailUrl(thumbnailData);
195
+ * }
196
+ */
197
+ }, {
198
+ key: "getThumbnailUrl",
199
+ value: function getThumbnailUrl(_ref6) {
200
+ var _root$IBM2;
201
+ var _ref6$mediaId = _ref6.mediaId,
202
+ mediaId = _ref6$mediaId === void 0 ? '' : _ref6$mediaId,
203
+ _ref6$height = _ref6.height,
204
+ height = _ref6$height === void 0 ? 0 : _ref6$height,
205
+ _ref6$width = _ref6.width,
206
+ width = _ref6$width === void 0 ? 0 : _ref6$width,
207
+ _ref6$partnerId = _ref6.partnerId,
208
+ partnerId = _ref6$partnerId === void 0 ? _partnerId : _ref6$partnerId;
209
+ return (_windowOrGlobal.default === null || _windowOrGlobal.default === void 0 || (_root$IBM2 = _windowOrGlobal.default.IBM) === null || _root$IBM2 === void 0 || (_root$IBM2 = _root$IBM2.Mediacenter) === null || _root$IBM2 === void 0 || (_root$IBM2 = _root$IBM2.player) === null || _root$IBM2 === void 0 || (_root$IBM2 = _root$IBM2.api) === null || _root$IBM2 === void 0 ? void 0 : _root$IBM2.getThumbnail(partnerId, mediaId, width, height)) || '';
210
+ }
211
+
212
+ /**
213
+ * Gets the api data
214
+ * The player api will only call kaltura once and cache the data
215
+ * return the cached information in all subsequential calls
216
+ *
217
+ * @param {string} mediaId The mediaId we're embedding the placeholder for.
218
+ * @param {string} partnerId The mediacenter partner id.
219
+ * @returns {object} object
220
+ * @example
221
+ * import { KalturaPlayerAPI } from '@carbon/ibmdotcom-services';
222
+ *
223
+ * async function getMyVideoInfo(id) {
224
+ * const data = await KalturaPlayerAPI.api(id);
225
+ * console.log(data);
226
+ * }
227
+ */
228
+ }, {
229
+ key: "api",
230
+ value: (function () {
231
+ var _api = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(mediaId) {
232
+ var partnerId,
233
+ _args = arguments;
234
+ return _regenerator.default.wrap(function (_context) {
235
+ while (1) switch (_context.prev = _context.next) {
236
+ case 0:
237
+ partnerId = _args.length > 1 && _args[1] !== undefined ? _args[1] : _partnerId;
238
+ _context.next = 1;
239
+ return this.checkScript().then(function () {
240
+ var _root$IBM3;
241
+ return (_windowOrGlobal.default === null || _windowOrGlobal.default === void 0 || (_root$IBM3 = _windowOrGlobal.default.IBM) === null || _root$IBM3 === void 0 || (_root$IBM3 = _root$IBM3.Mediacenter) === null || _root$IBM3 === void 0 || (_root$IBM3 = _root$IBM3.player) === null || _root$IBM3 === void 0 || (_root$IBM3 = _root$IBM3.api) === null || _root$IBM3 === void 0 ? void 0 : _root$IBM3.getMediaProperties(partnerId, mediaId)) || {};
242
+ });
243
+ case 1:
244
+ return _context.abrupt("return", _context.sent);
245
+ case 2:
246
+ case "end":
247
+ return _context.stop();
248
+ }
249
+ }, _callee, this);
250
+ }));
251
+ function api(_x) {
252
+ return _api.apply(this, arguments);
253
+ }
254
+ return api;
255
+ }()
256
+ /**
257
+ * Gets the embed meta data
258
+ *
259
+ * @param {string} mediaId The mediaId we're embedding the placeholder for.
260
+ * @param {string} targetId The targetId the ID where we're putting the placeholder.
261
+ * @param {object} configuration Determine any extra param or plugin for the player.
262
+ * @param {Function} customReadyCallback Determine any extra functions that should be executed
263
+ * @param {string} partnerId specify mediacenter's partner id
264
+ * on player readyCallback.
265
+ * @returns {object} object
266
+ * @example
267
+ * import { KalturaPlayerAPI } from '@carbon/ibmdotcom-services';
268
+ *
269
+ * function embedMyVideo() {
270
+ * const elem = document.getElementById('foo');
271
+ * const videoid = '12345';
272
+ * KalturaPlayerAPI.embedMedia(videoid, elem);
273
+ * }
274
+ */
275
+ )
276
+ }, {
277
+ key: "embedMedia",
278
+ value: (function () {
279
+ var _embedMedia = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3(mediaId, targetId) {
280
+ var configuration,
281
+ customReadyCallback,
282
+ partnerId,
283
+ _args3 = arguments;
284
+ return _regenerator.default.wrap(function (_context3) {
285
+ while (1) switch (_context3.prev = _context3.next) {
286
+ case 0:
287
+ configuration = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
288
+ customReadyCallback = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : function () {};
289
+ partnerId = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : _partnerId;
290
+ _context3.next = 1;
291
+ return this.checkScript().then(function () {
292
+ var legacyPromiseKWidget = /*#__PURE__*/function () {
293
+ var _ref7 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2() {
294
+ var _configuration$player, _ibmEnvironments$conf, _configuration$player2, _root$IBM4;
295
+ var playerType, playerEnvironment, playerUiConfId, playerConfiguration, isCustomCreated, newVideoDiv, kalturaPlayer, previousVideoDiv;
296
+ return _regenerator.default.wrap(function (_context2) {
297
+ while (1) switch (_context2.prev = _context2.next) {
298
+ case 0:
299
+ playerType = (_configuration$player = configuration === null || configuration === void 0 ? void 0 : configuration.playerType) !== null && _configuration$player !== void 0 ? _configuration$player : 'VIDEO';
300
+ playerEnvironment = (_ibmEnvironments$conf = _ibmEnvironments[configuration.playerEnvironment]) !== null && _ibmEnvironments$conf !== void 0 ? _ibmEnvironments$conf : _ibmEnvironments[_ibmEnvironment];
301
+ playerUiConfId = (_configuration$player2 = configuration.playerUiConfId) !== null && _configuration$player2 !== void 0 ? _configuration$player2 : _uiConfIds[playerType];
302
+ playerConfiguration = _objectSpread({
303
+ playerType: playerType,
304
+ autoPlay: true,
305
+ muted: true,
306
+ loop: false,
307
+ playerMode: 'default',
308
+ environment: playerEnvironment,
309
+ partnerId: partnerId,
310
+ uiConfId: playerUiConfId,
311
+ targetId: targetId
312
+ }, configuration);
313
+ if (playerType === 'VIDEO' || playerType === 'AUDIO') {
314
+ playerConfiguration.entryId = mediaId;
315
+ } else if (playerType === 'PLAYLIST' || playerType === 'REELS') {
316
+ // Implement when both players are ready in Mediacenter
317
+ }
318
+
319
+ /**
320
+ * Process the elements around the player
321
+ */
322
+
323
+ if (!document.getElementById(targetId) && document.querySelector('cds-tabs-extended-media')) {
324
+ newVideoDiv = document.createElement('div');
325
+ newVideoDiv.classList.add("bx--video-player__video");
326
+ newVideoDiv.setAttribute('id', targetId);
327
+ document.body.append(newVideoDiv);
328
+ isCustomCreated = true;
329
+ }
330
+
331
+ /**
332
+ * Embed the player and execute custom callback
333
+ */
334
+ _context2.next = 1;
335
+ return _windowOrGlobal.default === null || _windowOrGlobal.default === void 0 || (_root$IBM4 = _windowOrGlobal.default.IBM) === null || _root$IBM4 === void 0 || (_root$IBM4 = _root$IBM4.Mediacenter) === null || _root$IBM4 === void 0 || (_root$IBM4 = _root$IBM4.player) === null || _root$IBM4 === void 0 ? void 0 : _root$IBM4.embed(playerConfiguration);
336
+ case 1:
337
+ kalturaPlayer = _context2.sent;
338
+ customReadyCallback(kalturaPlayer);
339
+ if (isCustomCreated) {
340
+ previousVideoDiv = document.querySelector('cds-tabs-extended-media').shadowRoot.querySelector(".bx--accordion__item--active cds-video-player").lastChild;
341
+ previousVideoDiv.parentElement.appendChild(document.getElementById(targetId));
342
+ }
343
+ return _context2.abrupt("return", kalturaPlayer);
344
+ case 2:
345
+ case "end":
346
+ return _context2.stop();
347
+ }
348
+ }, _callee2);
349
+ }));
350
+ return function legacyPromiseKWidget() {
351
+ return _ref7.apply(this, arguments);
352
+ };
353
+ }();
354
+ return legacyPromiseKWidget();
355
+ });
356
+ case 1:
357
+ return _context3.abrupt("return", _context3.sent);
358
+ case 2:
359
+ case "end":
360
+ return _context3.stop();
361
+ }
362
+ }, _callee3, this);
363
+ }));
364
+ function embedMedia(_x2, _x3) {
365
+ return _embedMedia.apply(this, arguments);
366
+ }
367
+ return embedMedia;
368
+ }())
369
+ }]);
370
+ }();
371
+ var _default = exports.default = KalturaPlayerAPIV7;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "KalturaPlayerAPI", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _KalturaPlayer.default;
11
+ }
12
+ });
13
+ var _KalturaPlayer = _interopRequireDefault(require("./KalturaPlayer"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/ibmdotcom-services",
3
3
  "description": "Carbon for IBM.com Services",
4
- "version": "2.43.0",
4
+ "version": "2.45.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@babel/runtime": "^7.16.3",
50
- "@carbon/ibmdotcom-utilities": "2.43.0",
50
+ "@carbon/ibmdotcom-utilities": "2.45.0",
51
51
  "@ibm/telemetry-js": "^1.5.0",
52
52
  "axios": "^1.6.8",
53
53
  "marked": "^4.0.10",
@@ -89,5 +89,5 @@
89
89
  "rollup-plugin-sizes": "^1.0.4",
90
90
  "whatwg-fetch": "^2.0.3"
91
91
  },
92
- "gitHead": "31ab76ce3aba1d4b066fe955bd3188e94bc835b0"
92
+ "gitHead": "49545853dccb0f60acfe69733d9f98c8cc45dfdb"
93
93
  }