@tivio/sdk-react 5.0.0 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,16 @@
1
- # Changelog @tivio/sdk-react
1
+ # @tivio/sdk-react
2
+
3
+ @tivio/sdk-react provides everything which is necessary (components, data hooks etc.) to build a custom React application
4
+ above Tivio Studio. You can comfortably manage all you videos, settings such as application's screens and rows and also monetization
5
+ settings in the administration of Tivio Studio while having the freedom to build your own application.
6
+
7
+ ## Changelog
8
+
9
+ * 5.0.2
10
+ * patch: export hook useChannelSource
11
+
12
+ * 5.0.1
13
+ * patch: move changelog
2
14
 
3
15
  * 5.0.0
4
16
  * major: upgrade to React 18, change react and react-dom peer dependencies to 17.x || 18.x
@@ -9,20 +21,20 @@
9
21
  * minor: add uri property to tv channel type
10
22
  * minor: add useChannelSource to hooks
11
23
 
12
- * v4.5.0
24
+ * 4.5.0
13
25
  * minor: extend PurchaseEndpointPayload type with purchase previousStatus and newStatus fields
14
26
 
15
- * v4.4.1
27
+ * 4.4.1
16
28
  * patch: added waitForTags param in useSearch hook for videos
17
29
 
18
- * v4.4.0
30
+ * 4.4.0
19
31
  * minor: PrimaryButton component props type set to any for now
20
32
  * patch: isPurchasableAsVoucher added to PurchasableMonetization
21
33
  * patch: voucherPurchase flag added to purchase overlays
22
34
  * patch: item added to MonetizationsSelectOverlayData
23
35
  * minor: added hungarian language to `LangCode` enum
24
36
 
25
- * v4.3.0:
37
+ * 4.3.0:
26
38
  * minor: add GetPurchaseInfoResponse and PurchaseEndpointPayload to exported types
27
39
  * minor: support for disabling purchase of specified subscriptions (new param in useOrganizationSubscriptions hook)
28
40
  * minor: more specific PurchasableMonetization type usage instead of Monetization
@@ -30,22 +42,22 @@
30
42
  * minor: monetization now has originalPrice and promotion properties available
31
43
  * patch: remove not used OrganizationSubscriptionsContext, **this change requires bundle 3.20.0 or newer**
32
44
 
33
- * v4.2.0:
45
+ * 4.2.0:
34
46
  * minor: fix useSearch loading type
35
47
  * patch: added italian language to `LangCode` enum
36
48
 
37
- * v4.1.0
49
+ * 4.1.0
38
50
  * patch: added italian language to `LangCode` enum
39
51
  * minor: fixed spanish language code in `LangCode` enum (`sp` -> `es`)
40
52
  * minor: other misc type changes
41
53
 
42
- * v4.0.1
54
+ * 4.0.1
43
55
  * patch: added setBundleVersion setter to bundle type
44
56
  * patch: added setStorageManager setter to bundle type
45
57
  * patch: `Purchase.isPurchased` is deprecated
46
58
  * patch: fill `useSearch` field `hasNextPage` with proper value
47
59
 
48
- * v4.0.0
60
+ * 4.0.0
49
61
  * minor: Types cleanup
50
62
  * MAJOR: Remove deprecated and unused stuff
51
63
  * auth
@@ -56,7 +68,7 @@
56
68
  * initializeUser
57
69
  * createFreePurchase
58
70
  * components
59
- * VideoAdBanner
71
+ * videoAdBanner
60
72
  * getters
61
73
  * getExportedConfig
62
74
  * getChannelById
@@ -83,76 +95,76 @@
83
95
  ---
84
96
  _Versions <= v3.7.0 requires core-react-dom bundle < v3.0.0 (because sdk-react used some sdk API deleted in core-react-dom@4.0.0)_
85
97
 
86
- * v3.7.0
98
+ * 3.7.0
87
99
  * minor: purchase contains created and updated
88
100
 
89
- * v3.6.3
101
+ * 3.6.3
90
102
  * patch: improve README.md
91
103
 
92
- * v3.6.2
104
+ * 3.6.2
93
105
  * patch: Fix types
94
106
 
95
- * v3.6.1
107
+ * 3.6.1
96
108
  * patch: Fix README
97
109
 
98
- * v3.6.0
110
+ * 3.6.0
99
111
  * minor: Update types
100
112
 
101
- * v3.5.2
113
+ * 3.5.2
102
114
  * patch: All types are available again.
103
115
 
104
- * v3.5.1
116
+ * 3.5.1
105
117
  * patch: remove incorrect dependency (@tivio/types)
106
118
 
107
- * v3.5.0
119
+ * 3.5.0
108
120
  * minor: Types change - Video.price and Video.detailedPrice can be null
109
121
  * minor: Types change - Video.cover is marked as deprecated
110
122
 
111
- * v3.4.0
123
+ * 3.4.0
112
124
  * minor: more precise type for errors in usePurchaseRecovery and usePurchaseRecovery
113
125
  * patch: jsdocs for usePurchaseRecovery and usePurchaseRecovery
114
126
  * minor: inviteCodeReset in useApplyInviteCode
115
127
  * minor: Reset forgotten password
116
128
  * minor: Consolidating monetization logic
117
- * v3.3.2
129
+ * 3.3.2
118
130
  * patch: Adding new optional parameters (where, orderBy) to useTaggedVideos hook
119
- * v3.3.1
131
+ * 3.3.1
120
132
  * patch: Fixed types of `setUser`
121
- * v3.3.0
133
+ * 3.3.0
122
134
  * minor: Add getPlayerCapabilities to getters.
123
135
  * patch: Added option to log out via `setUser(null)`, requires @tivio/core-react-dom@2.17.9
124
- * v3.2.5
136
+ * 3.2.5
125
137
  * patch: added recovery flag to QerkoPaymentInfo type
126
138
  * patch: bundle.types changes - internal.components.WebVideoScreen
127
139
  * patch: types changes - add new onBack prop to WebPlayerProps
128
140
  * patch: Refactor useVideo hook, now uses hook from core-react
129
- * v3.2.4
141
+ * 3.2.4
130
142
  * minor: added useApplyInviteCode
131
143
  * minor: better errors from useVoucher
132
- * v3.2.3
144
+ * 3.2.3
133
145
  * minor: added usePurchaseRecovery hook
134
146
  * patch: deprecated `useLastVideoByWidgetId`
135
- * v3.2.2
147
+ * 3.2.2
136
148
  * minor: useRowsInScreen, useItemsInRow, useTaggedVideos - hasNextPage and loading added to pagination
137
149
  * minor: useRowsInScreen, useItemsInRow, useTaggedVideos - implementation moved to remote bundle
138
150
  * patch: Fixed Tivio startup on Tizen 6
139
151
  * minor: Added `forceCloudFnResolver` option
140
- * v3.2.1
152
+ * 3.2.1
141
153
  * patch: fix of @tivio/common version
142
- * v3.2.0
154
+ * 3.2.0
143
155
  * minor: Added `capabilitiesOptions` for finer configuration of device capabilities
144
156
  * minor: tag names are returned in correct language (the one from tivio config); language value should be one from enum "LangCode"
145
- * v3.1.3
157
+ * 3.1.3
146
158
  * patch: Hotfix made sure disabled Tivio does not break React Native
147
- * v3.1.2
159
+ * 3.1.2
148
160
  * patch: Allow `conf` prop of `TivioProvider` to be `null` or `undefined` in order to turn off Tivio
149
- * v3.1.1
161
+ * 3.1.1
150
162
  * patch: fixed `setUser()` crash when bundle fails to load
151
- * v3.1.0
163
+ * 3.1.0
152
164
  * patch: `useAdSegment()` now returns null if no monetization is configured, ad segments are not managed in that situation
153
165
  * minor: enriched `AdSegment` type from `useAdSegment()`
154
166
  * minor: Added `setUser()` function for login and logout
155
- * v3.0.0
167
+ * 3.0.0
156
168
  * minor: Added hook `useWatchWithoutAdsOffer` to trigger purchase dialog to "watch without ads", if available
157
169
  * patch: fix peerDependency declaration for react, react-dom
158
170
  * major: TivioProvider requires deviceCapabilities
@@ -163,62 +175,326 @@ _Versions <= v3.7.0 requires core-react-dom bundle < v3.0.0 (because sdk-react u
163
175
  * minor: watermarking support
164
176
  * minor: add useSearch hook
165
177
  * patch: price on video is 0 when purchased
166
- * v2.4.2
178
+ * 2.4.2
167
179
  * patch: added back changelog
168
- * v2.4.1
180
+ * 2.4.1
169
181
  * patch: improved doc about player wrapper
170
- * v2.4.0
182
+ * 2.4.0
171
183
  * patch: improved Player wrapper types
172
184
  * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
173
185
  * patch: added support for remote code on browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
174
186
  * patch: added support for browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
175
- * v2.3.4
187
+ * 2.3.4
176
188
  * patch: fix of usePurchaseSubscription not reactive
177
- * v2.3.3
189
+ * 2.3.3
178
190
  * patch: fix of useUser not updating
179
- * v2.3.2
191
+ * 2.3.2
180
192
  * patch: next app doesn't fail anymore due to "self is not defined"
181
- * v2.3.1
193
+ * 2.3.1
182
194
  * patch: fix of @tivio/common dependency
183
- * v2.3.0
195
+ * 2.3.0
184
196
  * minor: add useTaggedVideos that allows to fetch videos with given tags
185
197
  * minor: add option to fetch tags (on hook useItemsInRow), useVideo always fetching videos tags
186
- * v2.2.1
198
+ * 2.2.1
187
199
  * patch: disable Sentry when no config is supplied to `TivioProvider`
188
- * v2.2.0
200
+ * 2.2.0
189
201
  * patch: reduced bundle size
190
202
  * minor: disable Sentry when no config is supplied to `TivioProvider` or when Tivio is disabled `{ enable: false }`, or when Sentry is disabled via config `{ enableSentry: false }`
191
- * v2.1.5
203
+ * 2.1.5
192
204
  * patch fix of `useVideosInSection` hook (fetching video's monetizations)
193
- * v2.1.4
205
+ * 2.1.4
194
206
  * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react-dom@2.1.9)
195
- * v2.1.3
207
+ * 2.1.3
196
208
  * patch: fix changelog
197
- * v2.1.2
209
+ * 2.1.2
198
210
  * patch: Fixed exported types
199
- * v2.1.1
211
+ * 2.1.1
200
212
  * patch: TivioWidget now correctly reports `false` via `onEnabled` callback when in invalid internal state
201
- * v2.1.0
213
+ * 2.1.0
202
214
  * patch: fix of useItemsInRow hook
203
215
  * patch: fix of useScreen hook
204
216
  * add: useRowsInScreen hook
205
- * v2.0.3
217
+ * 2.0.3
206
218
  * patch: fix of useItemsInRow hook
207
- * v2.0.2
219
+ * 2.0.2
208
220
  * patch: screen and row IDs fixed
209
221
  * `TivioBundle.subscriptions.subscribeToItemsInRow` now accepts user-defined ID via studio.tiv.io
210
222
  * `TivioBundle.subscriptions.subscribeToScreen` now accepts user-defined ID via studio.tiv.io
211
223
  * `Screen` and `Row` types returned by `useScreen()` return their user-defined IDs (`.id`) correctly
212
- * v2.0.1
224
+ * 2.0.1
213
225
  * no changes
214
- * v2.0.0
226
+ * 2.0.0
215
227
  * major: video.channelId can now be `string | null` used to be `string`
216
228
  * minor: added data API and hooks for screens (screens, rows of screen and row items)
217
229
  * hooks: `useScreen()`, `useItemsInRow()`
218
230
  * api: `TivioBundle.subscriptions.subscribeToScreen`, `TivioBundle.subscriptions.subscribeToItemsInRow`
219
- * v1.3.6
231
+ * 1.3.6
220
232
  * ?
221
- * v1.3.5
233
+ * 1.3.5
222
234
  * minor: added WebPlayer props (canReplay, showMarkers, customShortcuts, enableKeyboardShortcuts, source.poster)
223
- * v1.3.4
235
+ * 1.3.4
224
236
  * ...
237
+
238
+ ## Installation
239
+
240
+ Install @tivio/sdk-react along with its peer dependencies
241
+ ```sh
242
+ npm i react@17 react-dom@17 @tivio/sdk-react
243
+ # or
244
+ yarn add react@17 react-dom@17 @tivio/sdk-react
245
+ ```
246
+
247
+ ## Initialization
248
+
249
+ Put Tivio Provider at the top level of your application:
250
+
251
+ ``` javascript
252
+ import { TivioProvider } from '@tivio/sdk-react'
253
+
254
+ const config = {
255
+ secret: 'XXXXXXXXXX',
256
+ }
257
+
258
+ function App({children}) {
259
+ return (
260
+ <TivioProvider conf={config}>
261
+ {children}
262
+ </TivioProvider>
263
+ )
264
+ }
265
+ ```
266
+
267
+ ## Authentication
268
+
269
+ A logged-in user can access more features, such as making purchases. In order to authenticate a user with Tivio, use the `setUser()` method.
270
+
271
+ Verification of the user against 3rd party auth servers is implemented per customer.
272
+
273
+ ```typescript
274
+ import { setUser } from '@tivio/sdk-react'
275
+
276
+ // Log in
277
+
278
+ // Payload is specific per customer
279
+ // A common use-case is sending an auth token inside the payload, which Tivio can use to verify the user
280
+ await setUser('userId', { token: 'xxx'})
281
+
282
+ // Log out
283
+ await setUser(null)
284
+ ```
285
+
286
+ ## Player
287
+
288
+ You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player
289
+ with the Tivio Player Wrapper.
290
+
291
+ ### Tivio Player component
292
+
293
+ ```javascript
294
+ import { useTivioData } from '@tivio/sdk-react'
295
+
296
+ const PlayerExample = () => {
297
+ const bundle = useTivioData()
298
+
299
+ if (!bundle?.components?.WebPlayer) {
300
+ return <p>Loading...</p>
301
+ }
302
+
303
+ return (
304
+ <>
305
+ <div
306
+ style={{
307
+ height: 720,
308
+ width: 1280,
309
+ }}
310
+ >
311
+ <bundle.components.WebPlayer
312
+ id="player1"
313
+ className="web-player"
314
+ source="/videos/xxxxxxxxxxxxxxxxxxxx" // dynamically change this based on video you want to play
315
+ />
316
+ </div>
317
+ </>
318
+ )
319
+ }
320
+ ```
321
+
322
+ ### Player wrapper
323
+
324
+ Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start
325
+ using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods
326
+ instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
327
+
328
+ #### Wrap your player methods with Tivio player wrapper
329
+
330
+ ```javascript
331
+ import { useTivioReadyData } from '@tivio/sdk-react'
332
+
333
+ function CustomPlayer() {
334
+ const tivioData = useTivioReadyData()
335
+
336
+ useEffect(() => {
337
+ if (tivioData) {
338
+ // If your app uses multiple player instances, use different Tivio player wrapper for each
339
+ // distinguished by playerWrapperId
340
+ const playerWrapper = tivio.getPlayerWrapper({ playerWrapperId: 'PLAYER_1' })
341
+
342
+ // Pass your player methods to Tivio player wrapper
343
+ playerWrapper.register({
344
+ play: () => {
345
+ // Un-pause your player
346
+ },
347
+ pause: () => {
348
+ // Pause your player
349
+ },
350
+ seekTo: (ms: number) => {
351
+ // Seek to position in milliseconds using your player
352
+ },
353
+ setSource: (videoSource: InputSource) => {
354
+ // Send this video source to your player to load it
355
+ },
356
+ })
357
+ }
358
+ }, [tivioData])
359
+ }
360
+ ```
361
+
362
+ #### Start using Tivio player wrapper methods to control playback
363
+
364
+ ```javascript
365
+ // Channel source metadata, such as channel name, epg start and epg end are necessary
366
+ // for TV ad segment detection and application of ad strategies
367
+ const source = new ChannelSource(
368
+ 'https://channel_prima_hd.m3u8',
369
+ {
370
+ // here put any additional metadata, for your use.
371
+ // This object will not be touched by Tivio
372
+ },
373
+ // channel name
374
+ // can also be prima hd, prima_hd, prima, Prima, PRIMA, etc.
375
+ // we will normalize it to snake case and add '_hd' if necessary
376
+ 'Prima HD',
377
+ // program name
378
+ 'Dr. House',
379
+ // description (optional)
380
+ 'Episode about Dr. House being awesome',
381
+ // EPG start
382
+ new Date('2021-12-10T12:00:00'),
383
+ // EPG end
384
+ new Date('2021-12-10T13:40:00'),
385
+ )
386
+
387
+ // Send source to player
388
+ playerWrapper.onSourceChanged(source)
389
+
390
+ // Un-pause player
391
+ playerWrapper.play()
392
+
393
+ // Pause player
394
+ playerWrapper.pause()
395
+ }
396
+ ```
397
+
398
+ #### Start reporting player events to Tivio
399
+
400
+ ```javascript
401
+ // Report that source is playing
402
+ playerWrapper.onStateChanged('playing')
403
+
404
+ // Report that source is paused
405
+ playerWrapper.onStateChanged('paused')
406
+
407
+ // Report that source stopped playing
408
+ playerWrapper.onPlaybackEnded()
409
+ playerWrapper.onStateChanged('idle')
410
+
411
+ // Report video progress
412
+ playerWrapper.onTimeChanged(ms)
413
+ }
414
+ ```
415
+
416
+ #### Start reporting playback-related errors to Tivio
417
+
418
+ ```javascript
419
+ // Report that video failed to load (e.g. due to a wrong URI)
420
+ playerWrapper.onLoadError(new Error('video failed to load'))
421
+
422
+ // Report that video failed during playback (e.g. due to bad connection, corrupted chunks of stream video etc.)
423
+ // This type of error may be auto-recoverable
424
+ playerWrapper.onError(new Error('playback error'))
425
+ }
426
+ ```
427
+
428
+ ## Data hooks
429
+
430
+ ### useUser hook
431
+ Gets information about current user.
432
+
433
+ ```ts
434
+ useUser: () => {
435
+ user: User | null
436
+ error: string | null
437
+ isInitialized: boolean
438
+ }
439
+ ```
440
+
441
+ ### useRowsInScreen hook
442
+ Gets array of Rows objects of specific screen and subscribes to its changes.
443
+
444
+ ```ts
445
+ /**
446
+ * Use rows in screen
447
+ * @param screenId - screen id (from studio.tiv.io)
448
+ * @param options - subscription options
449
+ */
450
+ useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
451
+ pagination: PaginationInterface<Row> | null
452
+ error: Error | null
453
+ }
454
+ ```
455
+
456
+ ### useItemsInRow hook
457
+ Gets array of row items objects of specific row and subscribes to its changes.
458
+
459
+ ```ts
460
+ /**
461
+ * Use row items
462
+ * @param rowId - row ID
463
+ * @param options - subscription options
464
+ */
465
+ useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
466
+ pagination: PaginationInterface<ItemsInRow> | null
467
+ error: Error | null
468
+ }
469
+ ```
470
+
471
+ ### useVideo hook
472
+
473
+ Gets Video object and subscribes to its changes.
474
+
475
+ ```ts
476
+ /**
477
+ * Use video
478
+ * @param videoId - video id
479
+ */
480
+ useVideo: (videoId: string) => {
481
+ error: string | null;
482
+ data: Video | null;
483
+ }
484
+ ```
485
+
486
+ ### useTaggedVideos hook
487
+ Gets videos with given tag IDs.
488
+
489
+ ```ts
490
+ /**
491
+ * Use tagged videos
492
+ * @param tagIds - tag ids
493
+ * @param options - subscription options
494
+ * @public
495
+ */
496
+ useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
497
+ pagination: PaginationInterface<Video> | null
498
+ error: Error | null
499
+ }
500
+ ```
package/dist/index.d.ts CHANGED
@@ -2899,6 +2899,16 @@ export declare type UseChannelSource = (tvChannelId: string) => {
2899
2899
  error: Error | null;
2900
2900
  };
2901
2901
 
2902
+ /**
2903
+ * Use channel source
2904
+ * @param tvChannelId
2905
+ * @public
2906
+ */
2907
+ export declare const useChannelSource: (tvChannelId: string) => {
2908
+ source: ChannelSourcePojo | null;
2909
+ error: Error | null;
2910
+ };
2911
+
2902
2912
  /**
2903
2913
  * @public
2904
2914
  */