@hopecloud/jetstream-player 0.2.8 → 0.2.9

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.
@@ -9,7 +9,6 @@ You can try Jetstrem player API directly in your browser on [StackBlitz](https:/
9
9
  If you want to use the library in your project, you need to perform the following steps:
10
10
 
11
11
  - Installation
12
- - Initialization of Player instance and methods
13
12
  - Initialization `JetstreamPlayer` with iframe
14
13
 
15
14
  ## Installation
@@ -20,32 +19,14 @@ Jetstrem player API can be installed in an existing project via npm.
20
19
  npm i @hopecloud/jetstream-player
21
20
  ```
22
21
 
23
- Once installed, you will be able to import the required methods or variables from the library into your component
22
+ Once installed, you will be able to import `JetstreamPlayer` clas from the library into your component
24
23
 
25
24
  ```
26
- import { JetstreamPlayer, onEnded, initPlayerMethods, embedVideosSrc } from '@hopecloud/jetstream-player';
25
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
27
26
  ```
28
- ## Initialization of Player instance and methods
29
27
 
30
- In order for the library to be able to interact with all the embedded windows on your component, you need to grab all the iframes from the web page. To do this, you need to import and call a special function `initPlayerMethods`. This function under the hood grabs and sorts all the iframes present on the web page and determines which player exactly you want to interact with. Also inside the library, the function creates the `JetstreamPlayer` class, which we need to initialize our player and call the necessary methods.
31
-
32
- ```
33
- import { initPlayerMethods, JetstreamPlayer } from '@hopecloud/jetstream-player';
34
- ```
35
-
36
- ### Important ☝️⬇️
37
-
38
- The `initPlayerMethods` function should be called when all DOM elements are loaded. Therefore, in our [Vue.js example](https://stackblitz.com/edit/hcc-jetstream-player-demo?file=src%2Fcomponents%2FVideoSandbox.vue), we call this function inside the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) lifecycle hook. The function will be executed when the template is fully loaded.
39
-
40
- ```
41
- onMounted(() => {
42
- initPlayerMethods();
43
- });
44
- ```
45
-
46
- ## Initialization `JetstreamPlayer` with iframe
47
-
48
- As mentioned earlier, the library creates a `JetstreamPlayer` class in which we have methods `play`, `pause`, etc.
28
+ Inside of `JetstreamPlayer` class there are methods `play`, `pause`, etc.
29
+ You can find all available [methods](../usage/player-methods) and [events](../usage/player-events) in the following sections.
49
30
 
50
31
  ```
51
32
  class JetstreamPlayer {
@@ -63,9 +44,11 @@ class JetstreamPlayer {
63
44
  }
64
45
  ```
65
46
 
47
+ ## Initialization `JetstreamPlayer` with iframe
48
+
66
49
  ### Important ☝️⬇️
67
50
 
68
- In order to connect our iframe with `JetstreamPlayer` class, we need to somehow distinguish between embedded windows in our template. Since we can have **_one_** or **_many_** iframes, we **strongly recommend** to assign a separate `id` to each iframe.
51
+ In order to connect our iframe with `JetstreamPlayer` class, we need determines which player exactly you want to interact with. We should somehow distinguish between embedded windows in our template. Since we can have **_one_** or **_many_** iframes, we **strongly recommend** to assign a separate `id` to each iframe.
69
52
 
70
53
  For example `id="iframe1"`, `id="iframe2"`
71
54
 
@@ -91,15 +74,23 @@ let player: JetstreamPlayer | null;
91
74
  player = new JetstreamPlayer('#iframe1');
92
75
  ```
93
76
 
77
+ ### Pay attention ☝️⬇️
78
+
79
+ Initialization must occur when all DOM elements are loaded. Therefore, in our [Vue.js example](https://stackblitz.com/edit/hcc-jetstream-player-demo?file=src%2Fcomponents%2FVideoSandbox.vue), we initialize our players inside the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) lifecycle hook. Thus the player is initialized when template is fully loaded.
80
+
81
+ ```
82
+ onMounted(() => {
83
+ player = new JetstreamPlayer('#iframe1');
84
+ });
85
+ ```
86
+
94
87
  After that, we can access the `player` variable and call the methods available in the `JetstreamPlayer` class.
95
- Please note that for DOM loading purposes, we do the assignment inside the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) lifecycle hook, along with the `initPlayerMethods` function we mentioned earlier.
96
88
 
97
89
  ```
98
90
  setup() {
99
91
  let player: JetstreamPlayer | null;
100
92
 
101
93
  onMounted(() => {
102
- initPlayerMethods();
103
94
  player = new JetstreamPlayer('#iframe1');
104
95
  })
105
96
 
@@ -10,73 +10,98 @@
10
10
 
11
11
  This list is not exhaustive. New events can be added as needed.
12
12
 
13
- In order to use these events, it is enough to import them from library.
13
+ In order to use these events, it is enough to import `JetstreamPlayer` class which contains these methods.
14
14
 
15
15
  ```
16
- import { onEnded, playVideo, pauseVideo } from '@hopecloud/jetstream-player';
16
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
17
+
18
+ setup() {
19
+ let player: JetstreamPlayer | null;
20
+
21
+ onMounted(() => {
22
+ player = new JetstreamPlayer('#iframe1');
23
+
24
+ player.onEnded(() => {
25
+ console.log('Video is ENDED');
26
+ })
27
+
28
+ ...
29
+ })
30
+ }
17
31
  ```
18
32
 
19
- These events are `callbacks` that act as **listeners**. That is, if a certain video or video in the **playlist** ends, the event `onEnded` will fire and transmit the **index** of the embedded window. Let's consider each event separately.
33
+ ### Pay attention ☝️⬇️
34
+
35
+ These events are `callbacks` that act as **listeners**.
36
+ In order to subscribe to events, all DOM elements must be loaded. That's why we put this listener in the [onMounted](https://vuejs.org/api/composition-api-lifecycle.html#onmounted) hook.
37
+ Otherwise, events may not work.
38
+
20
39
 
21
40
  ## `onEnded()` event
22
41
 
23
- This event is called when a video or a video in a playlist ends. For example, if your component has two iframes, the first is a video and the second is a playlist. If some video ends in the playlist, `onEnded()` event will be triggered, and we will get index `1` _(the playlist is the second iframe in our component)_.
42
+ This event is called when a video or a video in a playlist ends. For example, if your component has two iframes, the first is a video and the second is a playlist. If some video ends in the playlist, `onEnded()` event will be triggered.
24
43
 
25
44
  ### Example of use:
26
45
 
27
46
  ```
28
- import { JetstreamPlayer, initPlayerMethods, onEnded } from '@hopecloud/jetstream-player';
47
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
29
48
 
30
- setup() {
49
+ setup() {
50
+ const players = [];
51
+
31
52
  onMounted(() => {
32
- initPlayerMethods();
33
- })
34
-
35
- onEnded((index) => {
36
- console.log(`VIDEO ${index} ENDED`);
37
- // Will console 'VIDEO 1 ENDED'
53
+ players.push(new JetstreamPlayer('#iframe1'));
54
+ players.push(new JetstreamPlayer('#iframe2'));
55
+
56
+ players[1]?.onEnded(() => {
57
+ console.log('Video 2 is ENDED');
58
+ });
38
59
  });
39
60
  }
40
61
  ```
41
62
 
42
63
  ## `playVideo()` event
43
64
 
44
- This event is a listener that fires when any video or playlist on your page starts playing. If your page has one or more embedded iframes and a video starts playing in the first window, event will be triggered and we will get index `0`.
65
+ This event is a listener that fires when any video or playlist on your page starts playing. If your page has one or more embedded iframes and a video starts playing in the first window, event will be triggered for first player.
45
66
 
46
67
  ### Example of use:
47
68
 
48
69
  ```
49
- import { initPlayerMethods, playVideo } from '@hopecloud/jetstream-player';
70
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
50
71
 
51
- setup() {
72
+ setup() {
73
+ const players = [];
74
+
52
75
  onMounted(() => {
53
- initPlayerMethods();
54
- })
55
-
56
- playVideo((index) => {
57
- console.log(`VIDEO ${index} IS PLAYING`);
58
- // Will console 'VIDEO 0 IS PLAYING'
76
+ players.push(new JetstreamPlayer('#iframe1'));
77
+ players.push(new JetstreamPlayer('#iframe2'));
78
+
79
+ players[0]?.playVideo(() => {
80
+ console.log('Video 1 is PLAYING');
81
+ });
59
82
  });
60
83
  }
61
84
  ```
62
85
 
63
86
  ## `pauseVideo()` event
64
87
 
65
- This event is a listener that fires when any video or playlist on your page paused. If your page has one or more embedded iframes and a video paused in the second window, event will be triggered, and we will get index `1`.
88
+ This event is a listener that fires when any video or playlist on your page paused. If your page has one or more embedded iframes and a video paused in the second window, event will be triggered for second player.
66
89
 
67
90
  ### Example of use:
68
91
 
69
92
  ```
70
- import { initPlayerMethods, pauseVideo } from '@hopecloud/jetstream-player';
93
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
71
94
 
72
- setup() {
95
+ setup() {
96
+ const players = [];
97
+
73
98
  onMounted(() => {
74
- initPlayerMethods();
75
- })
76
-
77
- pauseVideo((index) => {
78
- console.log(`VIDEO ${index} PAUSED`);
79
- // Will console 'VIDEO 1 PAUSED'
99
+ players.push(new JetstreamPlayer('#iframe1'));
100
+ players.push(new JetstreamPlayer('#iframe2'));
101
+
102
+ players[1]?.pauseVideo(() => {
103
+ console.log('Video 2 is PAUSED');
104
+ });
80
105
  });
81
106
  }
82
107
  ```
@@ -6,6 +6,7 @@
6
6
 
7
7
  - `play()`
8
8
  - `pause()`
9
+ - `seekTo()`
9
10
  - `playNext()`
10
11
  - `playPrevious()`
11
12
 
@@ -20,7 +21,6 @@ setup() {
20
21
  let player: JetstreamPlayer | null;
21
22
 
22
23
  onMounted(() => {
23
- initPlayerMethods();
24
24
  player = new JetstreamPlayer('#iframe1');
25
25
  })
26
26
 
@@ -43,17 +43,73 @@ setup() {
43
43
 
44
44
  The `play` or `pause` method can be called for a video as well as for a playlist. We are able to interact with our videos or playlists programmatically in the same way as pressing pause or play within the iframe itself.
45
45
 
46
- ### Important ☝️⬇️
46
+ ### Pay attention ☝️⬇️
47
47
 
48
48
  When the web page with our embedded windows is just loaded and there has been no user action _(click, play)_ and video has the `sound settings on`, the programmatic `play()` function **will not execute**!
49
49
 
50
- The `play()` function will not work due to [Autoplay policy in Chrome](https://developer.chrome.com/blog/autoplay/). The same behavior occurs with services YouTube, Facebook, etc.
50
+ The `play()` function will not work due to [Autoplay policy in Chrome](https://developer.chrome.com/blog/autoplay/). The same behavior occurs with services **YouTube**, **Facebook**, etc.
51
51
 
52
52
  Modern browsers don't provide an opportunity to avoid this setting. Therefore, for the first time, an action on the user side is necessary _(click in the iframe window)_. After this action, all methods will work clearly.
53
53
 
54
54
  If the video or playlist has **sound settings off** `(muted)`, then all methods work in normal mode.
55
55
 
56
+ ## `seekTo(seconds: Number)` method
57
+
58
+ Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing), the player will play the video.
59
+ The function pass one parameter `seconds`.
60
+
61
+ The **seconds** parameter identifies the time to which the player should advance.
62
+ The player will advance to that time if the player has already downloaded the portion of the video to which the user is seeking.
63
+
64
+ The specified time must be shorter than video duration. If the user sets a time that exceeds video duration, nothing will happen.
65
+
66
+
67
+ ```
68
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
69
+
70
+ setup() {
71
+ let player: JetstreamPlayer | null;
72
+
73
+ onMounted(() => {
74
+ player = new JetstreamPlayer('#iframe1');
75
+ })
76
+
77
+ const seekTo = () => {
78
+ player.seekTo(45); // Set time on 45 second
79
+ }
80
+
81
+ return {
82
+ seekTo
83
+ }
84
+ }
85
+ ```
86
+
56
87
  ## `playNext()` `playPrevious()` methods
57
88
 
58
89
  The `playNext` or `playPrevious` method can be called only for a **playlist**. Calling these methods for a simple video will do nothing.
59
- We are able to interact with playlist programmatically in the same way as pressing `playNext` or `playPrevious` within the playlist itself.
90
+ We are able to interact with playlist programmatically in the same way as pressing `playNext` or `playPrevious` within the playlist itself.
91
+
92
+ ```
93
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
94
+
95
+ setup() {
96
+ let playlistPlayer: JetstreamPlayer | null;
97
+
98
+ onMounted(() => {
99
+ playlistPlayer = new JetstreamPlayer('#iframe1');
100
+ })
101
+
102
+ const playNextVideo = () => {
103
+ playlistPlayer.playNext();
104
+ };
105
+
106
+ const playPreviousVideo = () => {
107
+ playlistPlayer.playPrevious();
108
+ };
109
+
110
+ return {
111
+ playNextVideo,
112
+ playPreviousVideo,
113
+ }
114
+ }
115
+ ```
@@ -11,7 +11,6 @@ setup() {
11
11
  let player: JetstreamPlayer | null;
12
12
 
13
13
  onMounted(() => {
14
- initPlayerMethods();
15
14
  player = new JetstreamPlayer('#iframe1');
16
15
  })
17
16
 
@@ -41,7 +40,6 @@ setup() {
41
40
  let secondPlayer: JetstreamPlayer | null;
42
41
 
43
42
  onMounted(() => {
44
- initPlayerMethods();
45
43
  firstPlayer = new JetstreamPlayer('#iframe1');
46
44
  secondPlayer = new JetstreamPlayer('#iframe2');
47
45
  })
@@ -63,27 +61,21 @@ setup() {
63
61
 
64
62
  ### Recommended method
65
63
 
66
- Instead, we can use a simpler method. We can grab all players into an `array`. To do this, we need to import the `embedVideosSrc` variable from the library. This variable is an array that contains all `src` of iframes from our page. This variable will help us create our array of players
67
-
68
- ```
69
- import { embedVideosSrc } from '@hopecloud/jetstream-player';
70
- ```
64
+ Instead, we can use a simpler method. We can grab all players into an `array`.
71
65
 
72
66
  All we need is to create an empty array `const players = [];` and push each player there.
73
67
 
74
68
  ### Example
75
69
 
76
70
  ```
77
- import { JetstreamPlayer, initPlayerMethods, embedVideosSrc } from '@hopecloud/jetstream-player';
71
+ import { JetstreamPlayer } from '@hopecloud/jetstream-player';
78
72
 
79
73
  setup() {
80
74
  const players = [];
81
75
 
82
76
  onMounted(() => {
83
- initPlayerMethods();
84
- embedVideosSrc.forEach((src, index) => {
85
- players.push(new JetstreamPlayer(`#iframe${index + 1}`));
86
- });
77
+ players.push(new JetstreamPlayer('#iframe1'));
78
+ players.push(new JetstreamPlayer('#iframe2'));
87
79
  });
88
80
 
89
81
  const playEmbedVideo = (index) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hopecloud/jetstream-player",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Embeddable player for Jetstream videos",
5
5
  "scripts": {
6
6
  "build": "tsc",