@tivio/sdk-react 12.0.0 → 12.0.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.bak DELETED
@@ -1,940 +0,0 @@
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
- * UNRELEASED
9
- * minor: change frequency getter on PurchsableMonetization entity
10
-
11
- * 9.2.0-alpha.4
12
- * patch: expose getUser, resetPassword and signOut methods in RemoteBundleState type
13
- * patch: more precise types for user profile fields and methods
14
- * patch: add missing jsdocs for some User type fields
15
-
16
- * 9.2.0-alpha.0
17
- * minor: add renderWebPlayer method for rendering outside of React
18
- * minor: "expose createTivio"
19
-
20
- * 9.1.7
21
- * patch: update remote controller component API
22
-
23
- * 9.1.6
24
- * minor: add remote controller
25
-
26
- * 9.1.5
27
- * patch: expose purchase loyalty points through types
28
- * patch: enable setUser check
29
-
30
- * 9.1.4
31
- * patch: disable setUser check
32
- * patch: rollback "add renderWebPlayer method for rendering outside of React"
33
- * patch: rollback "expose createTivio"
34
-
35
- * 9.1.3
36
- * patch: add renderWebPlayer method for rendering outside of React
37
- * patch: expose createTivio
38
-
39
- * 9.1.4
40
- * patch: disable setUser check
41
-
42
- * 9.1.3
43
- * minor: add renderWebPlayer method for rendering outside of React
44
- * minor: expose createTivio
45
-
46
- * 9.1.2
47
- * patch: update PurchaseEndpointPayload type (cityName, externalId, geoPoint)
48
-
49
- * 9.1.1
50
- * patch: fix changelog
51
-
52
- * 9.1.0
53
- * patch: add gateway to Purchase type
54
- * minor: add QerkoPaymentWebhookByApiKeyRequest to exported types
55
-
56
- * 9.0.0
57
- * patch: remove i18next and react-i18next from externals and dependencies
58
- * patch: do not send react-spring to core-react-dom bundle, remove react-spring from dependencies
59
- * patch: clean-up externals in webpack config
60
- * patch: send only required dependencies to the bundle
61
- * major: change purchase statuses lifecycle
62
- * minor: add originalPurchaseId to PurchaseEndpointPayload
63
-
64
- * 8.0.0
65
- * major: deprecated usePurchasesWithVideos hook removed
66
- * patch: add id to user type
67
- * patch: add @types/react to peerDependencies
68
-
69
- * 7.1.0
70
- * minor: export useTvChannelHook
71
- * patch: bump "react-i18next", "i18next" versions.
72
-
73
- * 7.0.1
74
- * patch: fix dependency to @tivio/common
75
-
76
- * 7.0.0
77
- * major: delete deprecated useWatchWithoutAdsOffer hook
78
- * major: consolidate duplicated source types
79
- * patch: add new properties to PlayerInterface
80
- * patch: expose getSeekingMatrixPreviewByTime in Video interface
81
- * major: delete deprecated useBetOffer hook
82
- * major: rework of source types
83
- * major: make useChannelSource deprecated
84
-
85
- * 6.0.1
86
- * patch: fix dependency to @tivio/common
87
-
88
- * 6.0.0
89
- * major: delete usePlayerEvent hook
90
- * major: replace uri attributes in types with url
91
- * major: delete uri attributes from types
92
- * minor: add purchase expiration to PurchaseEndpointPayload
93
- * minor: add optional videoId parameter to useOrganizationSubscription hook
94
-
95
- * 5.0.2
96
- * patch: export hook useChannelSource
97
-
98
- * 5.0.1
99
- * patch: move changelog
100
-
101
- * 5.0.0
102
- * major: upgrade to React 18, change react and react-dom peer dependencies to 17.x || 18.x
103
- * major: fix typing for useReferralInfo, now correctly showing that `null` can be returned
104
- * major: fix typing for `WebRowProps.onTileClick`, now correctly showing that `null` can be accepted
105
- * minor: add analytics
106
- * minor: add getSourceUrl function to video and tv channel types
107
- * minor: add uri property to tv channel type
108
- * minor: add useChannelSource to hooks
109
-
110
- * 4.5.0
111
- * minor: extend PurchaseEndpointPayload type with purchase previousStatus and newStatus fields
112
-
113
- * 4.4.1
114
- * patch: added waitForTags param in useSearch hook for videos
115
-
116
- * 4.4.0
117
- * minor: PrimaryButton component props type set to any for now
118
- * patch: isPurchasableAsVoucher added to PurchasableMonetization
119
- * patch: voucherPurchase flag added to purchase overlays
120
- * patch: item added to MonetizationsSelectOverlayData
121
- * minor: added hungarian language to `LangCode` enum
122
-
123
- * 4.3.0:
124
- * minor: add GetPurchaseInfoResponse and PurchaseEndpointPayload to exported types
125
- * minor: support for disabling purchase of specified subscriptions (new param in useOrganizationSubscriptions hook)
126
- * minor: more specific PurchasableMonetization type usage instead of Monetization
127
- * minor: monetization property deleted from Video type
128
- * minor: monetization now has originalPrice and promotion properties available
129
- * patch: remove not used OrganizationSubscriptionsContext, **this change requires bundle 3.20.0 or newer**
130
-
131
- * 4.2.0:
132
- * minor: fix useSearch loading type
133
- * patch: added italian language to `LangCode` enum
134
-
135
- * 4.1.0
136
- * patch: added italian language to `LangCode` enum
137
- * minor: fixed spanish language code in `LangCode` enum (`sp` -> `es`)
138
- * minor: other misc type changes
139
-
140
- * 4.0.1
141
- * patch: added setBundleVersion setter to bundle type
142
- * patch: added setStorageManager setter to bundle type
143
- * patch: `Purchase.isPurchased` is deprecated
144
- * patch: fill `useSearch` field `hasNextPage` with proper value
145
-
146
- * 4.0.0
147
- * minor: Types cleanup
148
- * MAJOR: Remove deprecated and unused stuff
149
- * auth
150
- * changePassword
151
- * changeUserPhoto
152
- * removeUserPhoto
153
- * getPurchasedVodsWithInitializedVideos
154
- * initializeUser
155
- * createFreePurchase
156
- * components
157
- * videoAdBanner
158
- * getters
159
- * getExportedConfig
160
- * getChannelById
161
- * getSectionById
162
- * getWidgetById
163
- * hooks
164
- * useLastVideoByWidgetId
165
- * useScreen
166
- * useFreePurchase
167
- * useWidget
168
- * useChannel
169
- * useSection
170
- * useVideosInSection
171
- * useSectionsInChannel
172
- * useChannelsInWidget
173
- * subscriptions
174
- * subscribeToWidget
175
- * subscribeToChannel
176
- * subscribeToSection
177
- * subscribeToVideosInSection
178
- * subscribeToSectionsInChannel
179
- * subscribeToChannelsInWidget
180
- * subscribeToScreen
181
- ---
182
- _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)_
183
-
184
- * 3.7.0
185
- * minor: purchase contains created and updated
186
-
187
- * 3.6.3
188
- * patch: improve README.md
189
-
190
- * 3.6.2
191
- * patch: Fix types
192
-
193
- * 3.6.1
194
- * patch: Fix README
195
-
196
- * 3.6.0
197
- * minor: Update types
198
-
199
- * 3.5.2
200
- * patch: All types are available again.
201
-
202
- * 3.5.1
203
- * patch: remove incorrect dependency (@tivio/types)
204
-
205
- * 3.5.0
206
- * minor: Types change - Video.price and Video.detailedPrice can be null
207
- * minor: Types change - Video.cover is marked as deprecated
208
-
209
- * 3.4.0
210
- * minor: more precise type for errors in usePurchaseRecovery and usePurchaseRecovery
211
- * patch: jsdocs for usePurchaseRecovery and usePurchaseRecovery
212
- * minor: inviteCodeReset in useApplyInviteCode
213
- * minor: Reset forgotten password
214
- * minor: Consolidating monetization logic
215
- * 3.3.2
216
- * patch: Adding new optional parameters (where, orderBy) to useTaggedVideos hook
217
- * 3.3.1
218
- * patch: Fixed types of `setUser`
219
- * 3.3.0
220
- * minor: Add getPlayerCapabilities to getters.
221
- * patch: Added option to log out via `setUser(null)`, requires @tivio/core-react-dom@2.17.9
222
- * 3.2.5
223
- * patch: added recovery flag to QerkoPaymentInfo type
224
- * patch: bundle.types changes - internal.components.WebVideoScreen
225
- * patch: types changes - add new onBack prop to WebPlayerProps
226
- * patch: Refactor useVideo hook, now uses hook from core-react
227
- * 3.2.4
228
- * minor: added useApplyInviteCode
229
- * minor: better errors from useVoucher
230
- * 3.2.3
231
- * minor: added usePurchaseRecovery hook
232
- * patch: deprecated `useLastVideoByWidgetId`
233
- * 3.2.2
234
- * minor: useRowsInScreen, useItemsInRow, useTaggedVideos - hasNextPage and loading added to pagination
235
- * minor: useRowsInScreen, useItemsInRow, useTaggedVideos - implementation moved to remote bundle
236
- * patch: Fixed Tivio startup on Tizen 6
237
- * minor: Added `forceCloudFnResolver` option
238
- * 3.2.1
239
- * patch: fix of @tivio/common version
240
- * 3.2.0
241
- * minor: Added `capabilitiesOptions` for finer configuration of device capabilities
242
- * minor: tag names are returned in correct language (the one from tivio config); language value should be one from enum "LangCode"
243
- * 3.1.3
244
- * patch: Hotfix made sure disabled Tivio does not break React Native
245
- * 3.1.2
246
- * patch: Allow `conf` prop of `TivioProvider` to be `null` or `undefined` in order to turn off Tivio
247
- * 3.1.1
248
- * patch: fixed `setUser()` crash when bundle fails to load
249
- * 3.1.0
250
- * patch: `useAdSegment()` now returns null if no monetization is configured, ad segments are not managed in that situation
251
- * minor: enriched `AdSegment` type from `useAdSegment()`
252
- * minor: Added `setUser()` function for login and logout
253
- * 3.0.0
254
- * minor: Added hook `useWatchWithoutAdsOffer` to trigger purchase dialog to "watch without ads", if available
255
- * patch: fix peerDependency declaration for react, react-dom
256
- * major: TivioProvider requires deviceCapabilities
257
- * major: TivioProvider requires currency
258
- * minor: add voucher support (see usePurchaseSubscription and useTransactionPayment hooks)
259
- * minor: device limit support
260
- * minor: drm (Widevine, PlayReady) support
261
- * minor: watermarking support
262
- * minor: add useSearch hook
263
- * patch: price on video is 0 when purchased
264
- * 2.4.2
265
- * patch: added back changelog
266
- * 2.4.1
267
- * patch: improved doc about player wrapper
268
- * 2.4.0
269
- * patch: improved Player wrapper types
270
- * minor: added Tivio DOM events `tivio_key_input_handling_change`, `tivio_context_switch` and `tivio_request_goto`
271
- * 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)
272
- * patch: added support for browsers that do not implement [indexedDB API](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API)
273
- * 2.3.4
274
- * patch: fix of usePurchaseSubscription not reactive
275
- * 2.3.3
276
- * patch: fix of useUser not updating
277
- * 2.3.2
278
- * patch: next app doesn't fail anymore due to "self is not defined"
279
- * 2.3.1
280
- * patch: fix of @tivio/common dependency
281
- * 2.3.0
282
- * minor: add useTaggedVideos that allows to fetch videos with given tags
283
- * minor: add option to fetch tags (on hook useItemsInRow), useVideo always fetching videos tags
284
- * 2.2.1
285
- * patch: disable Sentry when no config is supplied to `TivioProvider`
286
- * 2.2.0
287
- * patch: reduced bundle size
288
- * 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 }`
289
- * 2.1.5
290
- * patch fix of `useVideosInSection` hook (fetching video's monetizations)
291
- * 2.1.4
292
- * patch: fix re-rendering of `useAd` during non-skippable ads (requires core-react-dom@2.1.9)
293
- * 2.1.3
294
- * patch: fix changelog
295
- * 2.1.2
296
- * patch: Fixed exported types
297
- * 2.1.1
298
- * patch: TivioWidget now correctly reports `false` via `onEnabled` callback when in invalid internal state
299
- * 2.1.0
300
- * patch: fix of useItemsInRow hook
301
- * patch: fix of useScreen hook
302
- * add: useRowsInScreen hook
303
- * 2.0.3
304
- * patch: fix of useItemsInRow hook
305
- * 2.0.2
306
- * patch: screen and row IDs fixed
307
- * `TivioBundle.subscriptions.subscribeToItemsInRow` now accepts user-defined ID via studio.tiv.io
308
- * `TivioBundle.subscriptions.subscribeToScreen` now accepts user-defined ID via studio.tiv.io
309
- * `Screen` and `Row` types returned by `useScreen()` return their user-defined IDs (`.id`) correctly
310
- * 2.0.1
311
- * no changes
312
- * 2.0.0
313
- * major: video.channelId can now be `string | null` used to be `string`
314
- * minor: added data API and hooks for screens (screens, rows of screen and row items)
315
- * hooks: `useScreen()`, `useItemsInRow()`
316
- * api: `TivioBundle.subscriptions.subscribeToScreen`, `TivioBundle.subscriptions.subscribeToItemsInRow`
317
- * 1.3.6
318
- * ?
319
- * 1.3.5
320
- * minor: added WebPlayer props (canReplay, showMarkers, customShortcuts, enableKeyboardShortcuts, source.poster)
321
- * 1.3.4
322
- * ...
323
-
324
- ## Installation
325
-
326
- Install @tivio/sdk-react along with its peer dependencies
327
- ```sh
328
- npm i react@18 react-dom@18 @tivio/sdk-react
329
- # or
330
- yarn add react@18 react-dom@18 @tivio/sdk-react
331
- ```
332
-
333
- ## Initialization
334
-
335
- Put Tivio Provider at the top level of your application:
336
-
337
- ``` javascript
338
- import { TivioProvider } from '@tivio/sdk-react'
339
-
340
- const config = {
341
- secret: 'XXXXXXXXXX',
342
- }
343
-
344
- function App({children}) {
345
- return (
346
- <TivioProvider conf={config}>
347
- {children}
348
- </TivioProvider>
349
- )
350
- }
351
- ```
352
-
353
- ## Authentication
354
-
355
- A logged-in user can access more features, such as making purchases. In order to authenticate a user with Tivio, use the `setUser()` method.
356
-
357
- Verification of the user against 3rd party auth servers is implemented per customer.
358
-
359
- ```typescript
360
- import { setUser } from '@tivio/sdk-react'
361
-
362
- // Log in
363
-
364
- // Payload is specific per customer
365
- // A common use-case is sending an auth token inside the payload, which Tivio can use to verify the user
366
- await setUser('userId', { token: 'xxx'})
367
-
368
- // Log out
369
- await setUser(null)
370
- ```
371
-
372
- ## Single Sign-On (SSO) across subdomains
373
- If you want to enable Single Sign-On (SSO) for all subdomains under the same parent domain, you can specify the customTokenCookiesDomain in the configuration object.
374
- ``` javascript
375
- import type { Config } from '@tivio/sdk-react'
376
-
377
- const config: Config = {
378
- // ... other required tivio config properties
379
- customTokenCookiesDomain: 'example.com' // allows SSO across example.com, app.example.com, admin.example.com, etc.
380
- };
381
- ```
382
-
383
- ## Player
384
-
385
- You can choose whether you will use complete player component provided by Tivio or you will wrap your existing player
386
- with the Tivio Player Wrapper.
387
-
388
- ### Tivio Player component
389
-
390
- ```javascript
391
- import { useTivioData } from '@tivio/sdk-react'
392
-
393
- const PlayerExample = () => {
394
- const bundle = useTivioData()
395
-
396
- if (!bundle?.components?.WebPlayer) {
397
- return <p>Loading...</p>
398
- }
399
-
400
- return (
401
- <>
402
- <div
403
- style={{
404
- height: 720,
405
- width: 1280,
406
- }}
407
- >
408
- <bundle.components.WebPlayer
409
- id="player1"
410
- className="web-player"
411
- source="/videos/xxxxxxxxxxxxxxxxxxxx" // dynamically change this based on video you want to play
412
- />
413
- </div>
414
- </>
415
- )
416
- }
417
- ```
418
-
419
- ### Player wrapper
420
-
421
- Player wrapper is the way how you can enhance your video player with Tivio features, such Tivio Ads. In order to start
422
- using Tivio player wrapper, wrap your player methods with PlayerWrapper, start using PlayerWrapper's methods
423
- instead of them to control your playback and start sending player events to Tivio PlayerWrapper.
424
-
425
- #### Wrap your player methods with Tivio player wrapper
426
-
427
- ```javascript
428
- import { useTivioReadyData } from '@tivio/sdk-react'
429
-
430
- function CustomPlayer() {
431
- const tivioData = useTivioReadyData()
432
-
433
- useEffect(() => {
434
- if (tivioData) {
435
- // If your app uses multiple player instances, use different Tivio player wrapper for each
436
- // distinguished by playerWrapperId
437
- const playerWrapper = tivio.getPlayerWrapper({ playerWrapperId: 'PLAYER_1' })
438
-
439
- // Pass your player methods to Tivio player wrapper
440
- playerWrapper.register({
441
- play: () => {
442
- // Un-pause your player
443
- },
444
- pause: () => {
445
- // Pause your player
446
- },
447
- seekTo: (ms: number) => {
448
- // Seek to position in milliseconds using your player
449
- },
450
- setSource: (videoSource: InputSource) => {
451
- // Send this video source to your player to load it
452
- },
453
- })
454
- }
455
- }, [tivioData])
456
- }
457
- ```
458
-
459
- #### Start using Tivio player wrapper methods to control playback
460
-
461
- ```javascript
462
- // Channel source metadata, such as channel name, epg start and epg end are necessary
463
- // for TV ad segment detection and application of ad strategies
464
- const source = new ChannelSource(
465
- 'https://channel_prima_hd.m3u8',
466
- {
467
- // here put any additional metadata, for your use.
468
- // This object will not be touched by Tivio
469
- },
470
- // channel name
471
- // can also be prima hd, prima_hd, prima, Prima, PRIMA, etc.
472
- // we will normalize it to snake case and add '_hd' if necessary
473
- 'Prima HD',
474
- // program name
475
- 'Dr. House',
476
- // description (optional)
477
- 'Episode about Dr. House being awesome',
478
- // EPG start
479
- new Date('2021-12-10T12:00:00'),
480
- // EPG end
481
- new Date('2021-12-10T13:40:00'),
482
- )
483
-
484
- // Send source to player
485
- playerWrapper.onSourceChanged(source)
486
-
487
- // Un-pause player
488
- playerWrapper.play()
489
-
490
- // Pause player
491
- playerWrapper.pause()
492
- }
493
- ```
494
-
495
- #### Start reporting player events to Tivio
496
-
497
- ```javascript
498
- // Report that source is playing
499
- playerWrapper.onStateChanged('playing')
500
-
501
- // Report that source is paused
502
- playerWrapper.onStateChanged('paused')
503
-
504
- // Report that source stopped playing
505
- playerWrapper.onPlaybackEnded()
506
- playerWrapper.onStateChanged('idle')
507
-
508
- // Report video progress
509
- playerWrapper.onTimeChanged(ms)
510
- }
511
- ```
512
-
513
- #### Start reporting playback-related errors to Tivio
514
-
515
- ```javascript
516
- // Report that video failed to load (e.g. due to a wrong URI)
517
- playerWrapper.onLoadError(new Error('video failed to load'))
518
-
519
- // Report that video failed during playback (e.g. due to bad connection, corrupted chunks of stream video etc.)
520
- // This type of error may be auto-recoverable
521
- playerWrapper.onError(new Error('playback error'))
522
- }
523
- ```
524
-
525
- ## JavaScript Methods for Rendering Players
526
-
527
- ### renderWebPlayer
528
-
529
- The `renderWebPlayer` method allows you to render a Tivio player outside of React components. This is useful for scenarios where you need to integrate the player into non-React environments.
530
-
531
- The method is asynchronous and returns a VideoController instance that provides comprehensive control over playback.
532
-
533
- ```typescript
534
- import { renderWebPlayer } from '@tivio/sdk-react'
535
-
536
- // Example usage
537
- const videoController = await renderWebPlayer(
538
- document.getElementById('video-player'),
539
- {
540
- id: 'player-main',
541
- source: 'videos/ID',
542
- }
543
- )
544
-
545
- // Control playback
546
- videoController.play()
547
- videoController.pause()
548
- videoController.togglePause()
549
-
550
- // Seeking
551
- videoController.seekToAbsolutePosition(30000) // Seek to 30 seconds
552
- videoController.seekBy(5000) // Seek forward by 5 seconds
553
- videoController.seekToPercent(50) // Seek to 50% of video
554
- videoController.seekToLive() // Seek to live position (for live streams)
555
-
556
- // Volume control
557
- videoController.changeVolume(0.8) // Set volume to 80%
558
- videoController.volumeUp() // Increase volume by 5%
559
- videoController.volumeDown() // Decrease volume by 5%
560
- videoController.mute()
561
- videoController.unmute()
562
- videoController.toggleMute()
563
-
564
- // Get current source
565
- console.log('Current source:', videoController.currentSource)
566
-
567
- // Change source
568
- videoController.setSource('videos/newVideoId') // Change to a different video
569
- videoController.setSource('tvChannels/channelId') // Change to a TV channel
570
- videoController.setSource(null) // Stop playback
571
-
572
- // Event handling
573
- videoController.addEventListener('video_unit_ended', () => {
574
- console.log('Video playback ended')
575
- })
576
-
577
- videoController.addEventListener('timeupdate', (currentTime) => {
578
- console.log('Current time:', currentTime)
579
- })
580
-
581
- // Cleanup
582
- videoController.destroy()
583
- ```
584
-
585
- #### VideoController Methods
586
-
587
- The VideoController returned by `renderWebPlayer` provides the following methods:
588
-
589
- **Playback Control:**
590
- - `play()` - Resume playback from paused state
591
- - `pause()` - Pause the current playback
592
- - `togglePause()` - Toggle between play and pause states
593
- - `replay()` - Replay the current video from the beginning
594
- - `retry()` - Retry playback if it failed to start
595
-
596
- **Seeking:**
597
- - `seekToAbsolutePosition(ms: number)` - Seek to absolute position in milliseconds
598
- - `seekBy(ms: number)` - Seek relative to current position
599
- - `seekToPercent(percentage: number)` - Seek to percentage of video duration
600
- - `seekToLive()` - Seek to live position (for live streams)
601
-
602
- **Volume Control:**
603
- - `changeVolume(value: number)` - Set volume (0-1)
604
- - `volumeUp()` - Increase volume by 5%
605
- - `volumeDown()` - Decrease volume by 5%
606
- - `mute()` - Mute audio
607
- - `unmute()` - Unmute audio
608
- - `toggleMute()` - Toggle mute state
609
-
610
- **Source Management:**
611
- - `setSource(source: WebPlayerProps['source'])` - Change the current source to a new one (updates player props)
612
- - `currentSource` - Currently playing source or null if no source is loaded
613
-
614
- #### Source Types
615
-
616
- The Tivio player supports different types of sources:
617
-
618
- **VOD_EXTERNAL** - External video-on-demand content from third-party URLs
619
- - Used for playing videos that are hosted outside of Tivio's infrastructure
620
- - Supports various streaming protocols (HLS, DASH, MP4)
621
- - Example usage:
622
- ```typescript
623
- const externalSource = {
624
- type: SourceType.VOD_EXTERNAL,
625
- url: 'https://example.com/video.m3u8',
626
- sourcePlayMode: SourcePlayMode.ON_DEMAND,
627
- poster: 'https://example.com/poster.jpg',
628
- name: 'External Video',
629
- autoplay: false,
630
- continuePositionMs: 10000, // Start at 10 seconds (optional)
631
- }
632
- ```
633
-
634
- #### Source Play Modes
635
-
636
- The `sourcePlayMode` property determines how the content is played:
637
-
638
- - **ON_DEMAND** - Standard video playback with full seeking capabilities
639
- - **LIVE** - Live stream mode with no seeking
640
- - **HYBRID** - Combines LIVE with seeking
641
-
642
- #### Using setSource with VideoController
643
-
644
- The `setSource` method allows you to dynamically change what's playing:
645
-
646
- ```typescript
647
- // Change to a different video
648
- videoController.setSource('videos/newVideoId')
649
-
650
- // Change to an external video
651
- videoController.setSource({
652
- type: SourceType.VOD_EXTERNAL,
653
- url: 'https://example.com/video.mpd',
654
- sourcePlayMode: SourcePlayMode.ON_DEMAND,
655
- name: 'External Video'
656
- })
657
-
658
- // Change to a TV channel
659
- videoController.setSource('tvChannels/channelId')
660
-
661
- // Stop playback
662
- videoController.setSource(null)
663
- ```
664
-
665
- The `setSource` method is particularly useful for:
666
- - Play next
667
- - Implementing playlists
668
- - Dynamic content loading
669
-
670
- **Event Handling:**
671
- - `addEventListener(event: string, callback: (value: T) => void)` - Add event listener
672
- - `removeEventListener(event: string, callback: (value: T) => void)` - Remove event listener
673
-
674
- **Utility:**
675
- - `destroy()` - Destroy player and clean up resources
676
-
677
- #### Playback Events
678
-
679
- The VideoController emits various events that you can listen to:
680
-
681
- ```typescript
682
- // Video state changes
683
- videoController.addEventListener('statechange', (state) => {
684
- console.log('Player state:', state) // 'playing', 'paused', 'idle'
685
- })
686
-
687
- // Time updates
688
- videoController.addEventListener('timeupdate', (currentTime) => {
689
- console.log('Current time:', currentTime)
690
- })
691
-
692
- // Video ended
693
- videoController.addEventListener('video_unit_ended', () => {
694
- console.log('Video playback ended')
695
- })
696
-
697
- // Duration changes
698
- videoController.addEventListener('durationchange', (duration) => {
699
- console.log('Video duration:', duration)
700
- })
701
-
702
- // Volume changes
703
- videoController.addEventListener('volumechange', ({ muted, volume }: { muted: boolean, volume: number }) => {
704
- console.log('Volume changed:', { muted, volume })
705
- })
706
-
707
- // Buffering state
708
- videoController.addEventListener('bufferingchange', (isBuffering) => {
709
- console.log('Buffering:', isBuffering)
710
- })
711
-
712
- // Errors
713
- videoController.addEventListener('error', (error) => {
714
- console.error('Playback error:', error)
715
- })
716
- ```
717
-
718
- ## WebPlayerProps
719
-
720
- The `WebPlayerProps` interface defines the properties that can be passed to the Tivio WebPlayer component. Here's a comprehensive overview of available properties:
721
-
722
- ### Required Properties
723
-
724
- - **`id`** (string): Unique identifier for the player instance. This is required and must be unique across your application.
725
-
726
- ### Source Properties
727
-
728
- - **`source`** (optional): The video or channel source to play. Can be:
729
- - `VideoPath` (string): Path to a video (e.g., "videos/VIDEO_ID")
730
- - `ChannelPath` (string): Path to a TV channel (e.g., "tvChannels/CHANNEL_ID")
731
- - `SourceParams` (object): Complex source parameters
732
- - `null`: No source (player will be idle)
733
-
734
- ### Callback Properties
735
-
736
- - **`onEnded`** (optional): Callback function called when video playback ends
737
- - **`onProgress`** (optional): Callback function for video progress events
738
-
739
- ### Layout Properties
740
-
741
- - **`className`** (optional): CSS class name for the player container
742
- - **`isSameSizeAsParent`** (optional): If `true`, the player will inherit the width and height of its parent element
743
-
744
- ### Playback Control Properties
745
-
746
- - **`autoplay`** (optional, default: `false`): Whether to start playback automatically. Note that autoplay may be blocked by browsers before user interaction
747
- - **`canReplay`** (optional, default: `true`): Whether to show replay functionality
748
- - **`doNotSaveWatchPosition`** (optional): If `true`, the player won't save the watch position
749
- - **`disablePlayNext`** (optional): If `true`, the player won't automatically play the next video when current video ends
750
-
751
- ### Visual Properties
752
-
753
- - **`showMarkers`** (optional, default: `false`): Whether to show video markers
754
- - **`markerColor`** (optional): Color for video markers (CSS color value)
755
- - **`showTvStreamType`** (optional): Whether to show TV stream type indicator
756
- - **`showCookiesSettings`** (optional): Whether to show cookies settings
757
- - **`showOsd`** (optional, default: `true`): Whether to show the On-Screen Display (OSD)
758
- - **`showBufferingSpinner`** (optional, default: `true`): Whether to show buffering spinner
759
-
760
- ### Audio Properties
761
-
762
- - **`isMutedByDefault`** (optional): If `true`, the player starts muted but can be unmuted
763
-
764
- ### Keyboard Shortcuts Properties
765
-
766
- - **`enableKeyboardShortcuts`** (optional, default: `true`): Whether to enable keyboard shortcuts
767
- - **`customShortcuts`** (optional): Custom keyboard shortcuts configuration:
768
- ```typescript
769
- {
770
- toggleFullscreen: number[], // Array of key codes
771
- togglePause: number[],
772
- toggleMute: number[],
773
- jumpForward: number[],
774
- jumpBack: number[],
775
- volumeUp: number[],
776
- volumeDown: number[]
777
- }
778
- ```
779
-
780
- ### Ad Block Properties
781
-
782
- - **`checkAdBlock`** (optional, default: `false`): Whether to check for ad blockers and show warnings
783
-
784
- ## Data hooks
785
- Gets information about current user.
786
-
787
- ```ts
788
- useUser: () => {
789
- user: User | null
790
- error: string | null
791
- isInitialized: boolean
792
- }
793
- ```
794
-
795
- ### useRowsInScreen hook
796
- Gets array of Rows objects of specific screen and subscribes to its changes.
797
-
798
- ```ts
799
- /**
800
- * Use rows in screen
801
- * @param screenId - screen id (from studio.tiv.io)
802
- * @param options - subscription options
803
- */
804
- useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
805
- pagination: PaginationInterface<Row> | null
806
- error: Error | null
807
- }
808
- ```
809
-
810
- ### useItemsInRow hook
811
- Gets array of row items objects of specific row and subscribes to its changes.
812
-
813
- ```ts
814
- /**
815
- * Use row items
816
- * @param rowId - row ID
817
- * @param options - subscription options
818
- */
819
- useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
820
- pagination: PaginationInterface<ItemInRow> | null
821
- error: Error | null
822
- }
823
- ```
824
-
825
- ### useVideo hook
826
-
827
- Gets Video object and subscribes to its changes.
828
-
829
- ```ts
830
- /**
831
- * Use video
832
- * @param videoId - video id
833
- */
834
- useVideo: (videoId: string) => {
835
- error: string | null;
836
- data: Video | null;
837
- }
838
- ```
839
-
840
- ### useTaggedVideos hook
841
- Gets videos with given tag IDs.
842
-
843
- ```ts
844
- /**
845
- * Use tagged videos
846
- * @param tagIds - tag ids
847
- * @param options - subscription options
848
- * @public
849
- */
850
- useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
851
- pagination: PaginationInterface<Video> | null
852
- error: Error | null
853
- }
854
- ```
855
-
856
- ### useVoucher hook
857
-
858
- Activates a voucher for the current user. Reading vouchers directly from the client is
859
- forbidden, so the hook does not fetch the voucher — calling `activate()` invokes the
860
- `activateVoucher` cloud function, which detects on its own whether the code is a single-use
861
- or a multi-use voucher.
862
-
863
- After a successful activation the `voucher` object exposes server-provided metadata
864
- (`voucherInfo`, `videoId`, `subscriptionsToShow`) as flat attributes. Until the voucher is
865
- initialized, `voucher` is `null`.
866
-
867
- ```ts
868
- /**
869
- * Use voucher
870
- * @param voucherId - voucher code entered by the user
871
- */
872
- useVoucher: (voucherId: string) => {
873
- /**
874
- * Triggers the `activateVoucher` cloud function for the current user.
875
- * On success, `activationSuccess` becomes `true` and `voucher` is populated
876
- * with the activation metadata.
877
- */
878
- activate: () => Promise<void>
879
- voucher: {
880
- organizationId: string | null
881
- isInitialized: boolean
882
- /** Public, server-safe metadata about the activated voucher. */
883
- voucherInfo: VoucherInfoPublic | null
884
- /** Video the voucher relates to, when its document references one (`voucherInfo.videoId`). */
885
- videoId?: string
886
- /** Monetizations to offer when the voucher does not fully cover the content. */
887
- subscriptionsToShow: PurchasableMonetization[]
888
- } | null
889
- error: Error | BadRequestError | null
890
- activationSuccess: boolean
891
- }
892
- ```
893
-
894
- `voucherInfo` is a discriminated union by `type`:
895
-
896
- ```ts
897
- type VoucherInfoPublic = VoucherInfoSubscriptionPublic | VoucherInfoTransactionPublic
898
-
899
- interface VoucherInfoBasePublic {
900
- id: string
901
- isExpired: boolean
902
- status: 'NEW' | 'USED' | 'FULFILLED'
903
- /** True when the voucher fully covers the content (no further payment needed). */
904
- fullDiscount?: boolean
905
- /** Video the voucher relates to, when its document references one. Present for both types. */
906
- videoId?: string
907
- }
908
-
909
- interface VoucherInfoSubscriptionPublic extends VoucherInfoBasePublic {
910
- type: 'subscription'
911
- name: string
912
- benefits: string[]
913
- frequency?: MONETIZATION_FREQUENCY
914
- }
915
-
916
- interface VoucherInfoTransactionPublic extends VoucherInfoBasePublic {
917
- type: 'transaction'
918
- name: string
919
- videoId: string
920
- cover: string
921
- description: string
922
- }
923
- ```
924
-
925
- When activation fails, `error` may be a `BadRequestError` whose `details.reason` explains why:
926
-
927
- ```ts
928
- type BadRequestError = Error & {
929
- details?: {
930
- reason?:
931
- | 'DOES_NOT_EXIST'
932
- | 'EXPIRED'
933
- | 'ALREADY_USED'
934
- | 'ALREADY_USED_BY_CURRENT_USER'
935
- | 'LIMIT_REACHED'
936
- | 'FULFILLED'
937
- | 'INVALID_VOUCHER_TYPE'
938
- }
939
- }
940
- ```