@tivio/sdk-react 2.4.0 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Changelog
4
4
  * Unreleased
5
+ * v2.4.2
6
+ * patch: added back changelog
7
+ * v2.4.1
8
+ * patch: improved doc about player wrapper
5
9
  * v2.4.0
6
10
  * patch: improved Player wrapper types
7
11
  * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
@@ -58,16 +62,14 @@
58
62
  * v1.3.4
59
63
  * ...
60
64
 
61
- ## Installation
62
65
 
63
- Check/install peer dependencies
64
- ``` sh
65
- npm install --save mobx@6.0.4 styled-components@5.2.1 firebase@8.2.3 react@17.0.2 react-dom@17.0.2
66
- ```
66
+ ## Installation
67
67
 
68
- Install SDK itself
69
- ``` sh
70
- npm install --save @tivio/sdk-react
68
+ Install @tivio/sdk-react along with its peer dependencies
69
+ ```sh
70
+ npm i react@17 react-dom@17 @tivio/sdk-react
71
+ # or
72
+ yarn add react@17 react-dom@17 @tivio/sdk-react
71
73
  ```
72
74
 
73
75
  ## Initialization
@@ -77,13 +79,13 @@ Put Tivio Provider at the top level of your application:
77
79
  ``` javascript
78
80
  import { TivioProvider } from '@tivio/sdk-react'
79
81
 
80
- const tivioConf = {
82
+ const config = {
81
83
  secret: 'XXXXXXXXXX',
82
84
  }
83
85
 
84
86
  function App({children}) {
85
87
  return (
86
- <TivioProvider conf={tivioConf}>
88
+ <TivioProvider conf={config}>
87
89
  {children}
88
90
  </TivioProvider>
89
91
  )
@@ -95,7 +97,7 @@ function App({children}) {
95
97
  ``` javascript
96
98
  import { TivioProvider, setUser } from '@tivio/sdk-react'
97
99
 
98
- const tivioConf = {
100
+ const config = {
99
101
  secret: 'XXXXXXXXXX',
100
102
  }
101
103
 
@@ -103,7 +105,7 @@ setUser('user-id', { some: 'payload' })
103
105
 
104
106
  function App({children}) {
105
107
  return (
106
- <TivioProvider conf={tivioConf}>
108
+ <TivioProvider conf={config}>
107
109
  {children}
108
110
  </TivioProvider>
109
111
  )
@@ -112,7 +114,7 @@ function App({children}) {
112
114
  ## Tivio widget
113
115
 
114
116
  Tivio widget is the main Tivio component which shows the widget and provides access to its channels, sections and videos.
115
- Usage is very simple (be sure to set `id` to the widget ID you have configured in Tivio Studio):
117
+ Usage is very simple (be sure to set `id` to the widget ID you have configured in [Tivio Studio](https://studio.tiv.io/)):
116
118
 
117
119
  ``` javascript
118
120
  import { TivioWidget } from '@tivio/sdk-react'
@@ -141,45 +143,108 @@ function Screen() {
141
143
  )
142
144
  }
143
145
  ```
146
+
144
147
  ## Player wrapper
145
148
 
146
- Player wrapper is the way how you can enhance your video player with Tivio features (e.g. inserting of ads).
149
+ Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
150
+
151
+ ### Wrap your player methods with Tivio player wrapper
147
152
 
148
153
  ``` javascript
149
- import { useTivioData } from '@tivio/sdk-react'
154
+ import { useTivioReadyData } from '@tivio/sdk-react'
150
155
 
151
156
  function CustomPlayer() {
152
- const tivio = useTivioData()
153
- const [isPlaying, setIsPlaying] = useState()
157
+ const tivioData = useTivioReadyData()
154
158
 
155
159
  useEffect(() => {
156
- (async () => {
157
- if (tivio.getPlayerWrapper) {
158
- const playerWrapper = await tivio.getPlayerWrapper(
159
- { playerWrapperId: 'default' }
160
- )
161
-
162
- playerWrapper.register({
163
- play: () => {
164
- setIsPlaying(true)
165
- // start playback using your player here
166
- },
167
- pause: () => {
168
- setIsPlaying(false)
169
- // pause playback using your player here
170
- },
171
- seekTo: (ms: number) => {
172
- // seek using your player here
173
- },
174
- setSource: (videoSource: InputSource) => {
175
- // play videoSource using your player here
176
- },
177
- })
178
- }
179
- })()
180
- }, [])
181
-
182
- return (<div>Example is {isPlaying ? null : 'not '}playing.</div>)
160
+ if (tivioData) {
161
+ // If your app uses multiple player instances, use different Tivio player wrapper for each
162
+ // distinguished by playerWrapperId
163
+ const playerWrapper = tivio.getPlayerWrapper({ playerWrapperId: 'PLAYER_1' })
164
+
165
+ // Pass your player methods to Tivio player wrapper
166
+ playerWrapper.register({
167
+ play: () => {
168
+ // Un-pause your player
169
+ },
170
+ pause: () => {
171
+ // Pause your player
172
+ },
173
+ seekTo: (ms: number) => {
174
+ // Seek to position in milliseconds using your player
175
+ },
176
+ setSource: (videoSource: InputSource) => {
177
+ // Send this video source to your player to load it
178
+ },
179
+ })
180
+ }
181
+ }, [tivioData])
182
+ }
183
+ ```
184
+
185
+ ### Start using Tivio player wrapper methods to control playback
186
+
187
+ ``` javascript
188
+ // Channel source metadata, such as channel name, epg start and epg end are necessary
189
+ // for TV ad segment detection and application of ad strategies
190
+ const source = new ChannelSource(
191
+ 'https://channel_prima_hd.m3u8',
192
+ {
193
+ // here put any additional metadata, for your use.
194
+ // This object will not be touched by Tivio
195
+ },
196
+ // channel name
197
+ // can also be prima hd, prima_hd, prima, Prima, PRIMA, etc.
198
+ // we will normalize it to snake case and add '_hd' if necessary
199
+ 'Prima HD',
200
+ // program name
201
+ 'Dr. House',
202
+ // description (optional)
203
+ 'Episode about Dr. House being awesome',
204
+ // EPG start
205
+ new Date('2021-12-10T12:00:00'),
206
+ // EPG end
207
+ new Date('2021-12-10T13:40:00'),
208
+ )
209
+
210
+ // Send source to player
211
+ playerWrapper.onSourceChanged(source)
212
+
213
+ // Un-pause player
214
+ playerWrapper.play()
215
+
216
+ // Pause player
217
+ playerWrapper.pause()
218
+ }
219
+ ```
220
+
221
+ ### Start reporting player events to Tivio
222
+
223
+ ``` javascript
224
+ // Report that source is playing
225
+ playerWrapper.onStateChanged('playing')
226
+
227
+ // Report that source is paused
228
+ playerWrapper.onStateChanged('paused')
229
+
230
+ // Report that source stopped playing
231
+ playerWrapper.onPlaybackEnded()
232
+ playerWrapper.onStateChanged('idle')
233
+
234
+ // Report video progress
235
+ playerWrapper.onTimeChanged(ms)
236
+ }
237
+ ```
238
+
239
+ ### Start reporting playback-related errors to Tivio
240
+
241
+ ``` javascript
242
+ // Report that video failed to load (e.g. due to a wrong URI)
243
+ playerWrapper.onLoadError(new Error('video failed to load'))
244
+
245
+ // Report that video failed during playback (e.g. due to bad connection, corrupted chunks of stream video etc.)
246
+ // This type of error may be auto-recoverable
247
+ playerWrapper.onError(new Error('playback error'))
183
248
  }
184
249
  ```
185
250
 
@@ -1,3 +1,8 @@
1
1
  import React from 'react';
2
- declare const ContextProvider: React.FC;
2
+ import { RemoteBundleState } from '../services/bundleLoader';
3
+ interface Props {
4
+ bundleState: RemoteBundleState;
5
+ children: any;
6
+ }
7
+ declare const ContextProvider: React.FC<Props>;
3
8
  export { ContextProvider, };
@@ -1,8 +1,5 @@
1
1
  export * from './ChannelsContext';
2
- export * from './OrganizationSubscriptionsContext';
3
- export * from './PurchasesWithVideosContext';
4
2
  export * from './ScreensContext';
5
3
  export * from './SectionsContext';
6
- export * from './UserContext';
7
4
  export * from './VideosContext';
8
5
  export * from './RowItemsContext';
@@ -1,4 +1,3 @@
1
- declare const useOrganizationSubscriptions: () => {
1
+ export declare const useOrganizationSubscriptions: () => {
2
2
  subscriptions: import("@tivio/common").Monetization[];
3
3
  };
4
- export { useOrganizationSubscriptions, };
@@ -1,5 +1,4 @@
1
- declare const useUser: () => {
1
+ export declare const useUser: () => {
2
2
  user: import("@tivio/common/dist/types/externalTypes/user").User | null;
3
3
  error: string | null;
4
4
  };
5
- export { useUser, };