@tivio/sdk-react 3.6.0 → 3.6.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +85 -229
- package/README.md.bak +85 -229
- package/dist/index.d.ts +966 -156
- package/dist/index.js +1 -1
- package/dist/sdk-react.d.ts +2653 -0
- package/doc/changelog.md +0 -0
- package/package.json +6 -5
package/README.md
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
# @tivio/sdk-react
|
2
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
|
+
|
3
7
|
## Changelog
|
4
8
|
|
5
|
-
* v3.
|
9
|
+
* v3.6.3
|
10
|
+
* patch: improve README.md
|
11
|
+
|
12
|
+
* v3.6.2
|
13
|
+
* patch: Fix types
|
14
|
+
|
15
|
+
* v3.6.1
|
16
|
+
* patch: Fix README
|
17
|
+
|
18
|
+
* v3.6.0
|
6
19
|
* minor: Update types
|
7
20
|
|
8
21
|
* v3.5.2
|
@@ -179,46 +192,51 @@ await setUser('userId', { token: 'xxx'})
|
|
179
192
|
await setUser(null)
|
180
193
|
```
|
181
194
|
|
182
|
-
##
|
195
|
+
## Player
|
183
196
|
|
184
|
-
|
185
|
-
|
197
|
+
You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player
|
198
|
+
with the Tivio Player Wrapper.
|
186
199
|
|
187
|
-
|
188
|
-
import { TivioWidget } from '@tivio/sdk-react'
|
200
|
+
### Tivio Player component
|
189
201
|
|
190
|
-
|
191
|
-
|
192
|
-
<TivioWidget id="theWidgetId" />
|
193
|
-
)
|
194
|
-
}
|
195
|
-
```
|
196
|
-
|
197
|
-
### Usage with smart TV navigation (focus control)
|
202
|
+
```javascript
|
203
|
+
import { useTivioData } from '@tivio/sdk-react'
|
198
204
|
|
199
|
-
|
200
|
-
|
205
|
+
const PlayerExample = () => {
|
206
|
+
const bundle = useTivioData()
|
201
207
|
|
202
|
-
|
203
|
-
|
208
|
+
if (!bundle?.components?.WebPlayer) {
|
209
|
+
return <p>Loading...</p>
|
210
|
+
}
|
204
211
|
|
205
212
|
return (
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
213
|
+
<>
|
214
|
+
<div
|
215
|
+
style={{
|
216
|
+
height: 720,
|
217
|
+
width: 1280,
|
218
|
+
}}
|
219
|
+
>
|
220
|
+
<bundle.components.WebPlayer
|
221
|
+
id="player1"
|
222
|
+
className="web-player"
|
223
|
+
source="/videos/xxxxxxxxxxxxxxxxxxxx" // dynamically change this based on video you want to play
|
224
|
+
/>
|
225
|
+
</div>
|
226
|
+
</>
|
211
227
|
)
|
212
228
|
}
|
213
229
|
```
|
214
230
|
|
215
|
-
|
231
|
+
### Player wrapper
|
216
232
|
|
217
|
-
Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start
|
233
|
+
Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start
|
234
|
+
using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods
|
235
|
+
instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
|
218
236
|
|
219
|
-
|
237
|
+
#### Wrap your player methods with Tivio player wrapper
|
220
238
|
|
221
|
-
```
|
239
|
+
```javascript
|
222
240
|
import { useTivioReadyData } from '@tivio/sdk-react'
|
223
241
|
|
224
242
|
function CustomPlayer() {
|
@@ -250,9 +268,9 @@ function CustomPlayer() {
|
|
250
268
|
}
|
251
269
|
```
|
252
270
|
|
253
|
-
|
271
|
+
#### Start using Tivio player wrapper methods to control playback
|
254
272
|
|
255
|
-
```
|
273
|
+
```javascript
|
256
274
|
// Channel source metadata, such as channel name, epg start and epg end are necessary
|
257
275
|
// for TV ad segment detection and application of ad strategies
|
258
276
|
const source = new ChannelSource(
|
@@ -286,9 +304,9 @@ function CustomPlayer() {
|
|
286
304
|
}
|
287
305
|
```
|
288
306
|
|
289
|
-
|
307
|
+
#### Start reporting player events to Tivio
|
290
308
|
|
291
|
-
```
|
309
|
+
```javascript
|
292
310
|
// Report that source is playing
|
293
311
|
playerWrapper.onStateChanged('playing')
|
294
312
|
|
@@ -304,9 +322,9 @@ function CustomPlayer() {
|
|
304
322
|
}
|
305
323
|
```
|
306
324
|
|
307
|
-
|
325
|
+
#### Start reporting playback-related errors to Tivio
|
308
326
|
|
309
|
-
```
|
327
|
+
```javascript
|
310
328
|
// Report that video failed to load (e.g. due to a wrong URI)
|
311
329
|
playerWrapper.onLoadError(new Error('video failed to load'))
|
312
330
|
|
@@ -316,87 +334,46 @@ function CustomPlayer() {
|
|
316
334
|
}
|
317
335
|
```
|
318
336
|
|
319
|
-
## Tivio DOM events
|
320
|
-
|
321
|
-
`TivioWidget` triggers these events on `window.document`.
|
322
|
-
|
323
|
-
1. To instruct the parent app to navigate to and focus a specific TivioWidget (e.g. after going back from a Tivio screen)
|
324
|
-
|
325
|
-
```typescript
|
326
|
-
document.addEventListener("tivio_request_goto", e => {
|
327
|
-
e.detail.widgetId; // string - Tivio widget ID to go navigate to in UI
|
328
|
-
});
|
329
|
-
```
|
330
|
-
2. To notify the parent app about context switch, i.e. where is the user located or what is he focusing
|
331
|
-
|
332
|
-
```typescript
|
333
|
-
document.addEventListener("tivio_context_switch", e => {
|
334
|
-
e.detail.context; // 'tivio' | 'parent' - where is the user located? - in Tivio or in parent app
|
335
|
-
|
336
|
-
// For context Tivio there are additional fields
|
337
|
-
e.detail.context; // 'tivio'
|
338
|
-
e.detail.contextLocation; // 'route' | 'overlay' | 'widget' - where in Tivio is the user located?
|
339
|
-
// - on a Tivio route, in parent app but looking at a full screen Tivio overlay,
|
340
|
-
// or in parent app and focus is on a Tivio widget
|
341
|
-
|
342
|
-
// For context Tivio contextLocation 'widget' there is an additional field of widget ID
|
343
|
-
e.detail.widgetId; // string - which Tivio widget is focused right now
|
344
|
-
});
|
345
|
-
```
|
346
|
-
3. To notify the parent app about whether it should be handling key input from RC (TV remote) or not. When inputHandler is 'tivio', the parent app should stop reacting to key input, when inputHandler is 'parent' the parent app should start reacting again.
|
347
|
-
|
348
|
-
```typescript
|
349
|
-
document.addEventListener("tivio_key_input_handling_change", e => {
|
350
|
-
e.detail.inputHandler; // 'tivio' | 'parent' - who should be handling RC input? - Tivio or parent app
|
351
|
-
});
|
352
|
-
```
|
353
|
-
|
354
337
|
## Data hooks
|
355
338
|
|
356
|
-
|
357
|
-
|
358
|
-
### useWidget hook
|
359
|
-
|
360
|
-
Gets Widget object and subscribes to its changes.
|
339
|
+
### useUser hook
|
340
|
+
Gets information about current user.
|
361
341
|
|
362
|
-
```
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
useWidget: (widgetId: string) => {
|
368
|
-
error: string | null;
|
369
|
-
data: Widget | null;
|
342
|
+
```ts
|
343
|
+
useUser: () => {
|
344
|
+
user: User | null
|
345
|
+
error: string | null
|
346
|
+
isInitialized: boolean
|
370
347
|
}
|
371
348
|
```
|
372
349
|
|
373
|
-
###
|
374
|
-
|
375
|
-
Gets Channel object and subscribes to its changes.
|
350
|
+
### useRowsInScreen hook
|
351
|
+
Gets array of Rows objects of specific screen and subscribes to its changes.
|
376
352
|
|
377
|
-
```
|
353
|
+
```ts
|
378
354
|
/**
|
379
|
-
* Use
|
380
|
-
* @param
|
355
|
+
* Use rows in screen
|
356
|
+
* @param screenId - screen id (from studio.tiv.io)
|
357
|
+
* @param options - subscription options
|
381
358
|
*/
|
382
|
-
|
383
|
-
|
384
|
-
|
359
|
+
useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
|
360
|
+
pagination: PaginationInterface<Row> | null
|
361
|
+
error: Error | null
|
385
362
|
}
|
386
363
|
```
|
387
364
|
|
388
|
-
###
|
389
|
-
|
390
|
-
Gets Section object and subscribes to its changes.
|
365
|
+
### useItemsInRow hook
|
366
|
+
Gets array of row items objects of specific row and subscribes to its changes.
|
391
367
|
|
392
|
-
```
|
368
|
+
```ts
|
393
369
|
/**
|
394
|
-
* Use
|
395
|
-
* @param
|
370
|
+
* Use row items
|
371
|
+
* @param rowId - row ID
|
372
|
+
* @param options - subscription options
|
396
373
|
*/
|
397
|
-
|
398
|
-
|
399
|
-
|
374
|
+
useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
|
375
|
+
pagination: PaginationInterface<ItemsInRow> | null
|
376
|
+
error: Error | null
|
400
377
|
}
|
401
378
|
```
|
402
379
|
|
@@ -404,7 +381,7 @@ useSection: (sectionId: string) => {
|
|
404
381
|
|
405
382
|
Gets Video object and subscribes to its changes.
|
406
383
|
|
407
|
-
```
|
384
|
+
```ts
|
408
385
|
/**
|
409
386
|
* Use video
|
410
387
|
* @param videoId - video id
|
@@ -415,139 +392,18 @@ useVideo: (videoId: string) => {
|
|
415
392
|
}
|
416
393
|
```
|
417
394
|
|
418
|
-
###
|
419
|
-
|
420
|
-
Gets array of Channel objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
|
421
|
-
for pagination (returned in `data` object).
|
422
|
-
|
423
|
-
``` javascript
|
424
|
-
/**
|
425
|
-
* Use channels in widget
|
426
|
-
* @param widgetId - widget id
|
427
|
-
* @param [limit] - channels count, defaults to 10
|
428
|
-
*/
|
429
|
-
useChannelsInWidget: (widgetId: string, limit?: number) => {
|
430
|
-
error: string | null;
|
431
|
-
data: PaginationData<Channel> | null;
|
432
|
-
}
|
433
|
-
```
|
434
|
-
|
435
|
-
### useSectionsInChannel hook
|
436
|
-
|
437
|
-
Gets array of Section objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
|
438
|
-
for pagination (returned in `data` object).
|
439
|
-
|
440
|
-
``` javascript
|
441
|
-
/**
|
442
|
-
* Use section in channel
|
443
|
-
* @param channelId - channel id
|
444
|
-
* @param [limit] - sections count, defaults to 10
|
445
|
-
*/
|
446
|
-
useSectionsInChannel: (channelId: string, limit?: number) => {
|
447
|
-
error: string | null;
|
448
|
-
data: PaginationData<Section> | null;
|
449
|
-
}
|
450
|
-
```
|
451
|
-
|
452
|
-
### useVideosInSection hook
|
453
|
-
|
454
|
-
Gets array of Video objects and subscribes to their changes. It is possible to use `hasNextPage` and `fetchMore`
|
455
|
-
for pagination (returned in `data` object).
|
456
|
-
|
457
|
-
``` javascript
|
458
|
-
/**
|
459
|
-
* Use videos in section
|
460
|
-
* @param sectionId - section id
|
461
|
-
* @param [limit] - videos count, defaults to 10
|
462
|
-
*/
|
463
|
-
useVideosInSection: (sectionId: string, limit?: number) => {
|
464
|
-
error: string | null;
|
465
|
-
data: PaginationData<Video> | null;
|
466
|
-
}
|
467
|
-
```
|
468
|
-
|
469
|
-
### useScreen hook
|
470
|
-
Gets Screen object and subscribes to its changes.
|
471
|
-
|
472
|
-
```ts
|
473
|
-
/**
|
474
|
-
* Hook to fetch an app screen
|
475
|
-
* @param screenId - screen ID configured via studio.tiv.io
|
476
|
-
*/
|
477
|
-
useScreen: (screenId: string) => {
|
478
|
-
error: Error | null
|
479
|
-
data: Screen | null
|
480
|
-
}
|
481
|
-
|
482
|
-
// Example:
|
483
|
-
// Screens with their screenIds are configured via studio.tiv.io
|
484
|
-
const screenId = '890sdfvxoi'
|
485
|
-
const { error, data } = useScreen(screenId)
|
486
|
-
|
487
|
-
if (data) {
|
488
|
-
const screenName = data.name
|
489
|
-
const screenRows = data.rows
|
490
|
-
// ...
|
491
|
-
}
|
492
|
-
```
|
493
|
-
|
494
|
-
### useItemsInRow hook
|
495
|
-
|
496
|
-
Gets array of Video or Tag objects for a specified row. It is possible to use
|
497
|
-
`hasNextPage` and `fetchMore` for pagination (returned in `data` object).
|
498
|
-
|
499
|
-
*(Note: Does not subscribe to changes in video objects, in order to refresh data it is necessary to reload the app.)*
|
500
|
-
|
501
|
-
```ts
|
502
|
-
/**
|
503
|
-
* Hook to fetch row items for rows received from `useScreen()`
|
504
|
-
* @param id - row ID configured via studio.tiv.io
|
505
|
-
* @param options.limit - items limit
|
506
|
-
* @param options.noLimit - disable/enable pagination (will fetch all items)
|
507
|
-
* @param options.fecthTags - disable/enable tags fetching
|
508
|
-
*/
|
509
|
-
useItemsInRow: (id: string, options: {limit?: number, noLimit?: boolean, fecthTags?: boolean}) => {
|
510
|
-
error: Error | null
|
511
|
-
data: PaginationData<Video | Tag> | null
|
512
|
-
isLoading: boolean
|
513
|
-
}
|
514
|
-
|
515
|
-
// Example:
|
516
|
-
// Rows and their row ID can be loaded using useScreen() hook
|
517
|
-
const Row = ({ id }: { id: string}) => {
|
518
|
-
const rowData = useItemsInRow(id, 10)
|
519
|
-
|
520
|
-
return <div>
|
521
|
-
<div>Row id: {id}</div>
|
522
|
-
Count: ({rowData.data?.items.length})
|
523
|
-
<div>
|
524
|
-
{rowData.isLoading && <div>Loading...</div>}
|
525
|
-
{rowData.data?.items.map(item => (
|
526
|
-
<div>
|
527
|
-
<div>{item.name}</div>
|
528
|
-
<img src={item.cover} alt={item.name} />
|
529
|
-
</div>
|
530
|
-
))}
|
531
|
-
</div>
|
532
|
-
<button onClick={() => rowData.data?.fetchMore()}>more</button>
|
533
|
-
</div>
|
534
|
-
}
|
535
|
-
```
|
536
|
-
|
537
|
-
### useTaggedItems hook
|
538
|
-
|
539
|
-
Allows to fetch videos with given tags.
|
395
|
+
### useTaggedVideos hook
|
396
|
+
Gets videos with given tag IDs.
|
540
397
|
|
541
398
|
```ts
|
542
399
|
/**
|
543
|
-
*
|
544
|
-
* @param
|
545
|
-
* @param options
|
546
|
-
* @
|
547
|
-
* @param options.fecthTags - disable/enable tags fetching
|
400
|
+
* Use tagged videos
|
401
|
+
* @param tagIds - tag ids
|
402
|
+
* @param options - subscription options
|
403
|
+
* @public
|
548
404
|
*/
|
549
|
-
|
405
|
+
useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
|
406
|
+
pagination: PaginationInterface<Video> | null
|
550
407
|
error: Error | null
|
551
|
-
data: PaginationData<Video> | null
|
552
408
|
}
|
553
409
|
```
|