@kks-web/player-sdk 1.0.7-beta.1
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.
- package/README.md +118 -0
- package/index.d.ts +41 -0
- package/index.esm.js +366 -0
- package/index.js +1 -0
- package/package.json +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Player SDK
|
|
2
|
+
|
|
3
|
+
The BlendVision Player SDK allows you to create, interact with and control an
|
|
4
|
+
embedded BlendVision Player.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
You can install the BlendVision Player SDK through npm:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @web-kks/player-sdk
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Alternatively, you can reference an up‐to‐date version on our CDN:
|
|
15
|
+
|
|
16
|
+
```html
|
|
17
|
+
<script src="https://unpkg.com/@web-kks/player-sdk"></script>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
You can create the well-crafted BlendVision player for your event with this SDK.
|
|
23
|
+
|
|
24
|
+
### Create with an element id
|
|
25
|
+
|
|
26
|
+
Pass an element's `id` and a [config](#config-options) object to the `Player`
|
|
27
|
+
constructor to create an embedded player inside that element. The config object should
|
|
28
|
+
consist of a `token` which is the `accessToken` of the event powered by BlendVision Moment.
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<!-- the element where you would like to display the player -->
|
|
32
|
+
<div id="my-player"></div>
|
|
33
|
+
|
|
34
|
+
<script src="https://unpkg.com/@web-kks/player-sdk"></script>
|
|
35
|
+
<script>
|
|
36
|
+
const config = {
|
|
37
|
+
token: "your-token", // the accessToken of the event from BlendVision Moment api
|
|
38
|
+
};
|
|
39
|
+
// Will create inside the my-player div:
|
|
40
|
+
// <iframe width="100%" height="100%" src="https://player.live.kkstream.io/?t=your-token&hl=en" title="Player" allow="autoplay; encrypted-media" allowfullscreen=""></iframe>
|
|
41
|
+
new BlendVision.Player("my-player", config);
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
### Using with a module bundler
|
|
45
|
+
If you’re using a module bundler like [webpack](https://webpack.js.org/) or [rollup](http://rollupjs.org/), the exported object will be the Player constructor (unlike the browser where it is attached to `window.BlendVision`):
|
|
46
|
+
```js
|
|
47
|
+
import Player from "@web-kks/player-sdk";
|
|
48
|
+
|
|
49
|
+
new Player("my-player", {
|
|
50
|
+
token: "your-token", // the accessToken of the event from BlendVision Moment api
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Using with React
|
|
55
|
+
If you're building your projects with [React](https://github.com/facebook/react), you could follow the sample code as described below.
|
|
56
|
+
Since we do not provide a React component version of our player for the time being, please instantiate our SDK in React life cycle as below:
|
|
57
|
+
|
|
58
|
+
#### For React 16.8+ with hooks
|
|
59
|
+
```jsx
|
|
60
|
+
import React, { useEffect } from "react";
|
|
61
|
+
import Player from "@web-kks/player-sdk";
|
|
62
|
+
|
|
63
|
+
const App = () => {
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const options = {
|
|
66
|
+
token: "your-token"
|
|
67
|
+
}
|
|
68
|
+
new Player("my-player", options);
|
|
69
|
+
}, [])
|
|
70
|
+
return (
|
|
71
|
+
<div className="App">
|
|
72
|
+
<h1>BlendVision Player SDK</h1>
|
|
73
|
+
<div className="main">
|
|
74
|
+
<div id="my-player"/>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### For React Class components
|
|
82
|
+
```jsx
|
|
83
|
+
import React from 'react';
|
|
84
|
+
import Player from "@web-kks/player-sdk";
|
|
85
|
+
|
|
86
|
+
class App extends React.Component {
|
|
87
|
+
componentDidMount() {
|
|
88
|
+
const options = {
|
|
89
|
+
token: 'your-token'
|
|
90
|
+
}
|
|
91
|
+
new Player('my-player', options);
|
|
92
|
+
}
|
|
93
|
+
render() {
|
|
94
|
+
return (
|
|
95
|
+
<div className="App">
|
|
96
|
+
<h1>BlendVision Player SDK</h1>
|
|
97
|
+
<div className="main">
|
|
98
|
+
<div id="my-player"/>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default App;
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Config Options
|
|
110
|
+
|
|
111
|
+
These config options are available to use as an object passed to the
|
|
112
|
+
`Player` constructor.
|
|
113
|
+
|
|
114
|
+
| option | default | description |
|
|
115
|
+
| --------- | --------------------------------- | ----------------------------------------------------------------------- |
|
|
116
|
+
| token | | **Required.** The accessToken of the event from BlendVision Moment api. |
|
|
117
|
+
| playerUrl | `https://player.live.kkstream.io` | The URL of the Player service. |
|
|
118
|
+
| locale | en | The language of Player. `(en, zh, ja)` |
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface PlayerProps {
|
|
2
|
+
token?: string;
|
|
3
|
+
playerUrl?: string;
|
|
4
|
+
locale?: string;
|
|
5
|
+
did?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
event?: any;
|
|
8
|
+
titleSpacing?: number;
|
|
9
|
+
disableFullscreen?: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare class Player {
|
|
12
|
+
private readonly originalElement;
|
|
13
|
+
readonly targetOrigin: string;
|
|
14
|
+
element: HTMLIFrameElement | null;
|
|
15
|
+
enableWatermark: boolean;
|
|
16
|
+
lastTouchEnd: number;
|
|
17
|
+
onEnded: () => void;
|
|
18
|
+
onMessage: (event: any) => void;
|
|
19
|
+
onTouchStart: (event: any) => void;
|
|
20
|
+
onTouchEnd: (event: any) => void;
|
|
21
|
+
constructor(target: string | HTMLElement | null, config?: PlayerProps);
|
|
22
|
+
/**
|
|
23
|
+
* Workaround
|
|
24
|
+
* BM-3091: receive command from player iframe, when watermark is enabled on iOS device mobile.
|
|
25
|
+
* Implement some functions for mock fullscreen UI and zoom prevention, including fullscreen / exitFullscreen and restrictZoom / unrestrictZoom.
|
|
26
|
+
*/
|
|
27
|
+
fullscreen(): void;
|
|
28
|
+
exitFullscreen(): void;
|
|
29
|
+
restrictZoom(): void;
|
|
30
|
+
unrestrictZoom(): void;
|
|
31
|
+
play(): void;
|
|
32
|
+
pause(): void;
|
|
33
|
+
setVolume(volume: number): void;
|
|
34
|
+
setQuality(quality: number): void;
|
|
35
|
+
mute(): void;
|
|
36
|
+
destroy(): void;
|
|
37
|
+
startReceiveMessage(): void;
|
|
38
|
+
handleTouchEvent(): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { Player as default };
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function (target) {
|
|
3
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var key in source) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
|
+
target[key] = source[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var basicCSS = "width: 100%; height: 100%; border: none;";
|
|
20
|
+
var fullscreenCSS = "\n position: fixed;\n inset:0;\n z-index:99999;\n top:0;\n left:0;\n right:0;\n bottom:0;\n background-color: black;\n transition: 1s position;\n display:flex;\n align-items:center;\n justify-content:center;\n " + basicCSS + "\n";
|
|
21
|
+
var restrictZoomCSS = 'touch-action: pan-x pan-y;';
|
|
22
|
+
var bodyCSS = 'overflow: hidden; position: relative; background-color: black;';
|
|
23
|
+
|
|
24
|
+
var createEmbed = function createEmbed(_ref, element) {
|
|
25
|
+
var _ref$style = _ref.style,
|
|
26
|
+
style = _ref$style === void 0 ? basicCSS : _ref$style,
|
|
27
|
+
_ref$title = _ref.title,
|
|
28
|
+
title = _ref$title === void 0 ? 'BlendVision' : _ref$title,
|
|
29
|
+
_ref$src = _ref.src,
|
|
30
|
+
src = _ref$src === void 0 ? "https://player.madmax.kkvqa.com" : _ref$src;
|
|
31
|
+
|
|
32
|
+
if (!element) {
|
|
33
|
+
throw new TypeError('An element must be provided');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (element.getAttribute('data-bv-initialized') !== null) {
|
|
37
|
+
return element.querySelector('iframe');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var iframe = document.createElement('iframe'); // @ts-ignore
|
|
41
|
+
|
|
42
|
+
iframe.style = style;
|
|
43
|
+
iframe.width = '100%';
|
|
44
|
+
iframe.height = '100%';
|
|
45
|
+
iframe.src = src;
|
|
46
|
+
iframe.title = title;
|
|
47
|
+
iframe.allow = 'autoplay; encrypted-media';
|
|
48
|
+
iframe.allowFullscreen = true;
|
|
49
|
+
element.appendChild(iframe);
|
|
50
|
+
element.setAttribute('data-bv-initialized', 'true');
|
|
51
|
+
return element.querySelector('iframe');
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var sendMessage = function sendMessage(player, command, payload) {
|
|
55
|
+
var _player$element, _player$element2;
|
|
56
|
+
|
|
57
|
+
if (!((_player$element = player.element) != null && _player$element.contentWindow) || !((_player$element2 = player.element) != null && _player$element2.contentWindow.postMessage)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var message = {
|
|
62
|
+
command: command
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (payload !== undefined) {
|
|
66
|
+
message.payload = payload;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var ieVersion = parseFloat(navigator.userAgent.toLowerCase().replace(/^.*msie (\d+).*$/, '$1'));
|
|
70
|
+
|
|
71
|
+
if (ieVersion >= 8 && ieVersion < 10) {
|
|
72
|
+
message = JSON.stringify(message);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
player.element.contentWindow.postMessage(message, player.targetOrigin);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
var receiveMessage = function receiveMessage(player, event) {
|
|
79
|
+
switch (event.data.command) {
|
|
80
|
+
case 'ping':
|
|
81
|
+
sendMessage(player, 'pong');
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'onEnded':
|
|
85
|
+
player.onEnded == null ? void 0 : player.onEnded();
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'fullscreen':
|
|
89
|
+
{
|
|
90
|
+
if (player.element === document.activeElement) {
|
|
91
|
+
player.fullscreen == null ? void 0 : player.fullscreen();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case 'exitFullscreen':
|
|
98
|
+
{
|
|
99
|
+
if (player.element === document.activeElement) {
|
|
100
|
+
player.exitFullscreen == null ? void 0 : player.exitFullscreen();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
case 'watermark':
|
|
107
|
+
{
|
|
108
|
+
player.restrictZoom == null ? void 0 : player.restrictZoom();
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
case 'noWatermark':
|
|
113
|
+
{
|
|
114
|
+
player.unrestrictZoom == null ? void 0 : player.unrestrictZoom();
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
var startTouch = function startTouch(player, event) {
|
|
121
|
+
if (player.enableWatermark && event.touches.length > 1) {
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
var endTouch = function endTouch(player, event) {
|
|
127
|
+
var now = new Date().getTime();
|
|
128
|
+
|
|
129
|
+
if (player.enableWatermark && now - player.lastTouchEnd <= 300) {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
player.lastTouchEnd = now;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
var toggleMetaToHead = function toggleMetaToHead() {
|
|
137
|
+
var viewportContent = 'viewport-fit=cover';
|
|
138
|
+
var metaElement = document.querySelector('meta[name="viewport"]');
|
|
139
|
+
|
|
140
|
+
if (metaElement) {
|
|
141
|
+
var content = metaElement.getAttribute('content');
|
|
142
|
+
|
|
143
|
+
if (content != null && content.includes(viewportContent)) {
|
|
144
|
+
var splitContent = content.split(',').filter(function (text) {
|
|
145
|
+
return text !== viewportContent;
|
|
146
|
+
});
|
|
147
|
+
metaElement.setAttribute('content', splitContent.join(', '));
|
|
148
|
+
} else {
|
|
149
|
+
metaElement.setAttribute('content', content ? content + ", " + viewportContent : viewportContent);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
var meta = document.createElement('meta');
|
|
153
|
+
meta.name = 'viewport';
|
|
154
|
+
meta.content = 'viewport-fit=cover';
|
|
155
|
+
document.getElementsByTagName('head')[0].appendChild(meta);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
var setElementCSS = function setElementCSS(element, css) {
|
|
160
|
+
if (element) {
|
|
161
|
+
var cssText = element.style.cssText;
|
|
162
|
+
|
|
163
|
+
if (!(cssText != null && cssText.includes(css))) {
|
|
164
|
+
element.style.cssText = cssText ? "" + cssText + css : css;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
var toggleElementCSS = function toggleElementCSS(element, css) {
|
|
170
|
+
if (element) {
|
|
171
|
+
var cssText = element.style.cssText;
|
|
172
|
+
|
|
173
|
+
if (cssText != null && cssText.includes(css)) {
|
|
174
|
+
element.style.cssText = cssText.replaceAll(css, '');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
var Player = /*#__PURE__*/function () {
|
|
180
|
+
function Player(target, config) {
|
|
181
|
+
var _this = this,
|
|
182
|
+
_targetElement;
|
|
183
|
+
|
|
184
|
+
if (config === void 0) {
|
|
185
|
+
config = {};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.targetOrigin = "https://player.madmax.kkvqa.com" ;
|
|
189
|
+
this.element = null;
|
|
190
|
+
this.enableWatermark = false;
|
|
191
|
+
this.lastTouchEnd = 0;
|
|
192
|
+
var targetElement = null; // Find an element by id
|
|
193
|
+
|
|
194
|
+
if (typeof document !== 'undefined' && typeof target === 'string') {
|
|
195
|
+
targetElement = document.getElementById(target);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (target instanceof HTMLElement) {
|
|
199
|
+
targetElement = target;
|
|
200
|
+
} // Not an element
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
if (!(targetElement instanceof Element && targetElement.nodeType === 1 && 'nodeName' in targetElement && targetElement.ownerDocument && targetElement.ownerDocument.defaultView)) {
|
|
204
|
+
throw new TypeError('You must pass either a valid element or a valid id.');
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
this.originalElement = targetElement;
|
|
208
|
+
setElementCSS(document.body, restrictZoomCSS);
|
|
209
|
+
var _config = config,
|
|
210
|
+
_config$playerUrl = _config.playerUrl,
|
|
211
|
+
playerUrl = _config$playerUrl === void 0 ? "https://player.madmax.kkvqa.com" : _config$playerUrl,
|
|
212
|
+
_config$locale = _config.locale,
|
|
213
|
+
locale = _config$locale === void 0 ? 'en' : _config$locale,
|
|
214
|
+
token = _config.token,
|
|
215
|
+
did = _config.did,
|
|
216
|
+
event = _config.event,
|
|
217
|
+
titleSpacing = _config.titleSpacing,
|
|
218
|
+
_config$disableFullsc = _config.disableFullscreen,
|
|
219
|
+
disableFullscreen = _config$disableFullsc === void 0 ? false : _config$disableFullsc;
|
|
220
|
+
|
|
221
|
+
this.onMessage = function (event) {
|
|
222
|
+
return receiveMessage(_this, event);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
this.targetOrigin = playerUrl;
|
|
226
|
+
this.onEnded = event == null ? void 0 : event.onEnded;
|
|
227
|
+
|
|
228
|
+
this.onTouchStart = function (event) {
|
|
229
|
+
return startTouch(_this, event);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
this.lastTouchEnd = 0;
|
|
233
|
+
|
|
234
|
+
this.onTouchEnd = function (event) {
|
|
235
|
+
return endTouch(_this, event);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
this.startReceiveMessage();
|
|
239
|
+
this.handleTouchEvent();
|
|
240
|
+
|
|
241
|
+
if (((_targetElement = targetElement) == null ? void 0 : _targetElement.nodeName) === 'IFRAME') {
|
|
242
|
+
this.element = target;
|
|
243
|
+
} else {
|
|
244
|
+
var _targetElement2;
|
|
245
|
+
|
|
246
|
+
var iframe = (_targetElement2 = targetElement) == null ? void 0 : _targetElement2.querySelector('iframe');
|
|
247
|
+
var url = new URL(playerUrl + "/?t=" + token + "&hl=" + locale + (did ? "&did=" + did : ''));
|
|
248
|
+
|
|
249
|
+
if (titleSpacing) {
|
|
250
|
+
url.searchParams.append('titleSpacing', titleSpacing.toString());
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if (disableFullscreen) {
|
|
254
|
+
url.searchParams.append('disableFullscreen', 'true');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
this.element = iframe ? iframe : createEmbed(_extends({
|
|
258
|
+
src: url.toString()
|
|
259
|
+
}, config), targetElement);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Workaround
|
|
264
|
+
* BM-3091: receive command from player iframe, when watermark is enabled on iOS device mobile.
|
|
265
|
+
* Implement some functions for mock fullscreen UI and zoom prevention, including fullscreen / exitFullscreen and restrictZoom / unrestrictZoom.
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
var _proto = Player.prototype;
|
|
270
|
+
|
|
271
|
+
_proto.fullscreen = function fullscreen() {
|
|
272
|
+
if (this.element) {
|
|
273
|
+
toggleMetaToHead();
|
|
274
|
+
setElementCSS(document.body, bodyCSS);
|
|
275
|
+
this.element.style.cssText = fullscreenCSS;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
_proto.exitFullscreen = function exitFullscreen() {
|
|
280
|
+
if (this.element) {
|
|
281
|
+
toggleMetaToHead();
|
|
282
|
+
toggleElementCSS(document.body, bodyCSS);
|
|
283
|
+
this.element.style.cssText = basicCSS;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
_proto.restrictZoom = function restrictZoom() {
|
|
288
|
+
this.enableWatermark = true;
|
|
289
|
+
setElementCSS(document.body, restrictZoomCSS);
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
_proto.unrestrictZoom = function unrestrictZoom() {
|
|
293
|
+
this.enableWatermark = false;
|
|
294
|
+
toggleElementCSS(document.body, restrictZoomCSS);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
_proto.play = function play() {
|
|
298
|
+
sendMessage(this, 'play');
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
_proto.pause = function pause() {
|
|
302
|
+
sendMessage(this, 'pause');
|
|
303
|
+
} // Workaround BVS-556 live issue
|
|
304
|
+
// seek(time: number) {
|
|
305
|
+
// sendMessage(this, 'seek', { time });
|
|
306
|
+
// }
|
|
307
|
+
//
|
|
308
|
+
// forward() {
|
|
309
|
+
// sendMessage(this, 'forward');
|
|
310
|
+
// }
|
|
311
|
+
//
|
|
312
|
+
// rewind() {
|
|
313
|
+
// sendMessage(this, 'rewind');
|
|
314
|
+
// }
|
|
315
|
+
;
|
|
316
|
+
|
|
317
|
+
_proto.setVolume = function setVolume(volume) {
|
|
318
|
+
sendMessage(this, 'setVolume', {
|
|
319
|
+
volume: volume
|
|
320
|
+
});
|
|
321
|
+
} // Workaround BVS-556 live issue
|
|
322
|
+
// setPlaybackRate(rate: number) {
|
|
323
|
+
// sendMessage(this, 'setPlaybackRate', { rate });
|
|
324
|
+
// }
|
|
325
|
+
;
|
|
326
|
+
|
|
327
|
+
_proto.setQuality = function setQuality(quality) {
|
|
328
|
+
sendMessage(this, 'setQuality', {
|
|
329
|
+
quality: quality
|
|
330
|
+
});
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
_proto.mute = function mute() {
|
|
334
|
+
sendMessage(this, 'mute');
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
_proto.destroy = function destroy() {
|
|
338
|
+
var _this$element, _this$element$parentN;
|
|
339
|
+
|
|
340
|
+
if (this.originalElement) {
|
|
341
|
+
this.originalElement.removeAttribute('data-bv-initialized');
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
(_this$element = this.element) == null ? void 0 : (_this$element$parentN = _this$element.parentNode) == null ? void 0 : _this$element$parentN.removeChild(this.element);
|
|
345
|
+
window.removeEventListener('message', this.onMessage);
|
|
346
|
+
document.body.removeEventListener('touchstart', this.onTouchStart, {
|
|
347
|
+
passive: false
|
|
348
|
+
});
|
|
349
|
+
document.body.removeEventListener('touchend', this.onTouchEnd, false);
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
_proto.startReceiveMessage = function startReceiveMessage() {
|
|
353
|
+
window.addEventListener('message', this.onMessage);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
_proto.handleTouchEvent = function handleTouchEvent() {
|
|
357
|
+
document.body.addEventListener('touchstart', this.onTouchStart, {
|
|
358
|
+
passive: false
|
|
359
|
+
});
|
|
360
|
+
document.body.addEventListener('touchend', this.onTouchEnd, false);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
return Player;
|
|
364
|
+
}();
|
|
365
|
+
|
|
366
|
+
export { Player as default };
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).BlendVision=e.BlendVision||{},e.BlendVision.Player=t())}(this,(function(){"use strict";function e(){return e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},e.apply(this,arguments)}var t="width: 100%; height: 100%; border: none;",n="touch-action: pan-x pan-y;",i="overflow: hidden; position: relative; background-color: black;",o=function(e,t,n){var i,o;if(null!=(i=e.element)&&i.contentWindow&&null!=(o=e.element)&&o.contentWindow.postMessage){var r={command:t};void 0!==n&&(r.payload=n);var a=parseFloat(navigator.userAgent.toLowerCase().replace(/^.*msie (\d+).*$/,"$1"));a>=8&&a<10&&(r=JSON.stringify(r)),e.element.contentWindow.postMessage(r,e.targetOrigin)}},r=function(){var e="viewport-fit=cover",t=document.querySelector('meta[name="viewport"]');if(t){var n=t.getAttribute("content");if(null!=n&&n.includes(e)){var i=n.split(",").filter((function(t){return t!==e}));t.setAttribute("content",i.join(", "))}else t.setAttribute("content",n?n+", "+e:e)}else{var o=document.createElement("meta");o.name="viewport",o.content="viewport-fit=cover",document.getElementsByTagName("head")[0].appendChild(o)}},a=function(e,t){if(e){var n=e.style.cssText;null!=n&&n.includes(t)||(e.style.cssText=n?""+n+t:t)}},l=function(e,t){if(e){var n=e.style.cssText;null!=n&&n.includes(t)&&(e.style.cssText=n.replaceAll(t,""))}};return function(){function s(i,r){var l,s=this;void 0===r&&(r={}),this.targetOrigin="https://player.madmax.kkvqa.com",this.element=null,this.enableWatermark=!1,this.lastTouchEnd=0;var c=null;if("undefined"!=typeof document&&"string"==typeof i&&(c=document.getElementById(i)),i instanceof HTMLElement&&(c=i),!(c instanceof Element&&1===c.nodeType&&"nodeName"in c&&c.ownerDocument&&c.ownerDocument.defaultView))throw new TypeError("You must pass either a valid element or a valid id.");this.originalElement=c,a(document.body,n);var u=r,d=u.playerUrl,m=void 0===d?"https://player.madmax.kkvqa.com":d,h=u.locale,f=void 0===h?"en":h,v=u.token,p=u.did,y=u.event,g=u.titleSpacing,b=u.disableFullscreen,E=void 0!==b&&b;if(this.onMessage=function(e){return function(e,t){switch(t.data.command){case"ping":o(e,"pong");break;case"onEnded":null==e.onEnded||e.onEnded();break;case"fullscreen":e.element===document.activeElement&&(null==e.fullscreen||e.fullscreen());break;case"exitFullscreen":e.element===document.activeElement&&(null==e.exitFullscreen||e.exitFullscreen());break;case"watermark":null==e.restrictZoom||e.restrictZoom();break;case"noWatermark":null==e.unrestrictZoom||e.unrestrictZoom()}}(s,e)},this.targetOrigin=m,this.onEnded=null==y?void 0:y.onEnded,this.onTouchStart=function(e){return function(e,t){e.enableWatermark&&t.touches.length>1&&t.preventDefault()}(s,e)},this.lastTouchEnd=0,this.onTouchEnd=function(e){return function(e,t){var n=(new Date).getTime();e.enableWatermark&&n-e.lastTouchEnd<=300&&t.preventDefault(),e.lastTouchEnd=n}(s,e)},this.startReceiveMessage(),this.handleTouchEvent(),"IFRAME"===(null==(l=c)?void 0:l.nodeName))this.element=i;else{var w,T=null==(w=c)?void 0:w.querySelector("iframe"),k=new URL(m+"/?t="+v+"&hl="+f+(p?"&did="+p:""));g&&k.searchParams.append("titleSpacing",g.toString()),E&&k.searchParams.append("disableFullscreen","true"),this.element=T||function(e,n){var i=e.style,o=void 0===i?t:i,r=e.title,a=void 0===r?"BlendVision":r,l=e.src,s=void 0===l?"https://player.madmax.kkvqa.com":l;if(!n)throw new TypeError("An element must be provided");if(null!==n.getAttribute("data-bv-initialized"))return n.querySelector("iframe");var c=document.createElement("iframe");return c.style=o,c.width="100%",c.height="100%",c.src=s,c.title=a,c.allow="autoplay; encrypted-media",c.allowFullscreen=!0,n.appendChild(c),n.setAttribute("data-bv-initialized","true"),n.querySelector("iframe")}(e({src:k.toString()},r),c)}}var c=s.prototype;return c.fullscreen=function(){this.element&&(r(),a(document.body,i),this.element.style.cssText="\n position: fixed;\n inset:0;\n z-index:99999;\n top:0;\n left:0;\n right:0;\n bottom:0;\n background-color: black;\n transition: 1s position;\n display:flex;\n align-items:center;\n justify-content:center;\n width: 100%; height: 100%; border: none;\n")},c.exitFullscreen=function(){this.element&&(r(),l(document.body,i),this.element.style.cssText=t)},c.restrictZoom=function(){this.enableWatermark=!0,a(document.body,n)},c.unrestrictZoom=function(){this.enableWatermark=!1,l(document.body,n)},c.play=function(){o(this,"play")},c.pause=function(){o(this,"pause")},c.setVolume=function(e){o(this,"setVolume",{volume:e})},c.setQuality=function(e){o(this,"setQuality",{quality:e})},c.mute=function(){o(this,"mute")},c.destroy=function(){var e,t;this.originalElement&&this.originalElement.removeAttribute("data-bv-initialized"),null==(e=this.element)||null==(t=e.parentNode)||t.removeChild(this.element),window.removeEventListener("message",this.onMessage),document.body.removeEventListener("touchstart",this.onTouchStart,{passive:!1}),document.body.removeEventListener("touchend",this.onTouchEnd,!1)},c.startReceiveMessage=function(){window.addEventListener("message",this.onMessage)},c.handleTouchEvent=function(){document.body.addEventListener("touchstart",this.onTouchStart,{passive:!1}),document.body.addEventListener("touchend",this.onTouchEnd,!1)},s}()}));
|