@tivio/sdk-react 9.4.0 → 9.5.0

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 CHANGED
@@ -52,6 +52,17 @@ await setUser('userId', { token: 'xxx'})
52
52
  await setUser(null)
53
53
  ```
54
54
 
55
+ ## Single Sign-On (SSO) across subdomains
56
+ 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.
57
+ ``` javascript
58
+ import type { Config } from '@tivio/sdk-react'
59
+
60
+ const config: Config = {
61
+ // ... other required tivio config properties
62
+ customTokenCookiesDomain: 'example.com' // allows SSO across example.com, app.example.com, admin.example.com, etc.
63
+ };
64
+ ```
65
+
55
66
  ### Create user with email and password
56
67
 
57
68
  Returns user's firebase uid or null if error occurs
@@ -315,7 +326,7 @@ const favorites = await tivio.getUser()?.favorites
315
326
  favorites[0]?.removeFromFavorites()
316
327
  ```
317
328
 
318
- > Note: When user saves favorite without profileId, it will only be shown if the app doesn't have any active user profile.
329
+ > ℹ️ **_Note:_** When user saves favorite without profileId, it will only be shown if the app doesn't have any active user profile.
319
330
 
320
331
  ### Get screen by ID
321
332
 
@@ -582,9 +593,63 @@ The VideoController returned by `renderWebPlayer` provides the following methods
582
593
 
583
594
  The Tivio player supports different types of sources:
584
595
 
596
+ **PathSourceParams** - Path-based sources with ad configuration
597
+ - Used for playing Tivio-hosted videos and TV channels with custom VAST ad configurations
598
+ - Supports both `videos/ID` and `tvChannels/ID` paths
599
+ - Includes `staticAdsConfig` for custom VAST ad insertion
600
+ - Example usage:
601
+ ```typescript
602
+ const sourceWithAds = {
603
+ path: 'videos/123', // or 'tvChannels/456'
604
+ staticAdsConfig: [
605
+ {
606
+ type: 'preroll',
607
+ url: 'https://example.com/vast-preroll-ad.xml',
608
+ },
609
+ {
610
+ type: 'midroll',
611
+ from: 30000, // 30 seconds
612
+ url: 'https://example.com/vast-midroll-ad.xml',
613
+ },
614
+ {
615
+ type: 'postroll',
616
+ url: 'https://example.com/vast-postroll-ad.xml',
617
+ },
618
+ ],
619
+ }
620
+ ```
621
+
622
+ **VOD_TIVIO** - Tivio-hosted video-on-demand content
623
+ - Used for playing videos that are hosted within Tivio's infrastructure
624
+ - Example usage:
625
+ ```typescript
626
+ const vodSource = {
627
+ type: SourceType.VOD_TIVIO,
628
+ videoPath: 'videos/123', // Video path
629
+ sourcePlayMode: SourcePlayMode.ON_DEMAND,
630
+ name: 'Tivio Video',
631
+ autoplay: false,
632
+ continuePositionMs: 10000, // Start at 10 seconds (optional)
633
+ }
634
+ ```
635
+
636
+ **CHANNEL** - TV channel content (both classic and virtual channels)
637
+ - Used for playing live TV channels
638
+ - Example usage:
639
+ ```typescript
640
+ const channelSource = {
641
+ type: SourceType.CHANNEL,
642
+ path: 'tvChannels/456', // TV channel path
643
+ sourcePlayMode: SourcePlayMode.LIVE,
644
+ name: 'TV Channel',
645
+ autoplay: true,
646
+ }
647
+ ```
648
+
585
649
  **VOD_EXTERNAL** - External video-on-demand content from third-party URLs
586
650
  - Used for playing videos that are hosted outside of Tivio's infrastructure
587
651
  - Supports various streaming protocols (HLS, DASH, MP4)
652
+ - Optionally, you can include `staticAdsConfig` for custom ad insertion
588
653
  - Example usage (single url):
589
654
  ```typescript
590
655
  const externalSource = {
@@ -595,6 +660,114 @@ const externalSource = {
595
660
  name: 'External Video',
596
661
  autoplay: false,
597
662
  continuePositionMs: 10000, // Start at 10 seconds (optional)
663
+ staticAdsConfig: [
664
+ {
665
+ type: 'preroll',
666
+ url: 'https://example.com/preroll-ad.xml',
667
+ },
668
+ {
669
+ type: 'midroll',
670
+ from: 20000, // 20 seconds
671
+ url: 'https://example.com/midroll-ad.xml',
672
+ },
673
+ ],
674
+ }
675
+ ```
676
+
677
+ **Path-Based Sources**
678
+ You can also use simple path strings for both video and TV channel sources:
679
+ ```typescript
680
+ // Video path
681
+ videoController.setSource('videos/123')
682
+
683
+ // TV channel path
684
+ videoController.setSource('tvChannels/456')
685
+ ```
686
+
687
+ #### Static Ads Configuration
688
+
689
+ > ℹ️ **_Note:_** To enable ad functionality, you must configure the IMA ad service in your Tivio configuration:
690
+ > ```typescript
691
+ > import { AD_SERVICE_PROXY_NAME } from '@tivio/sdk-react'
692
+ >
693
+ > const config = {
694
+ > // ... other config properties
695
+ > player: {
696
+ > adService: {
697
+ > name: AD_SERVICE_PROXY_NAME.IMA,
698
+ > },
699
+ > },
700
+ > }
701
+ > ```
702
+
703
+ The `staticAdsConfig` property lets you specify custom ad insertion points within your content.
704
+ If multiple ads are set for the same entry point, they will be played one after another in sequence. For example, if you have two preroll ads, the first will play, followed by the second. Similarly, midroll ads that share the same `from` time will be grouped and played sequentially.
705
+
706
+ It supports the following ad types:
707
+
708
+ **Preroll Ads** - Play before the main content starts
709
+ ```typescript
710
+ {
711
+ type: 'preroll',
712
+ url: 'https://example.com/preroll-ad.xml',
713
+ }
714
+ ```
715
+
716
+ **Midroll Ads** - Play during the main content at specified time
717
+ ```typescript
718
+ {
719
+ type: 'midroll',
720
+ from: 30000, // Time in milliseconds (30 seconds)
721
+ url: 'https://example.com/midroll-ad.xml',
722
+ }
723
+ ```
724
+
725
+ **Postroll Ads** - Play after the main content ends
726
+ ```typescript
727
+ {
728
+ type: 'postroll',
729
+ url: 'https://example.com/postroll-ad.xml',
730
+ }
731
+ ```
732
+
733
+ **Complete Example:**
734
+ ```typescript
735
+ const sourceWithAds = {
736
+ path: 'videos/123',
737
+ name: 'Video with Multiple Ad Types',
738
+ staticAdsConfig: [
739
+ // multiple preroll ads
740
+ {
741
+ type: 'preroll',
742
+ url: 'https://vasterix.joj.sk/api/v1/creative?id=0c5d96fd-2ab9-4207-a325-4607437965e3&vast=4.0',
743
+ },
744
+ {
745
+ type: 'preroll',
746
+ url: 'https://example.com/preroll-ad.xml',
747
+ },
748
+ // multiple midroll ads (with same from time)
749
+ {
750
+ type: 'midroll',
751
+ from: 30000, // 30 seconds
752
+ url: 'https://example.com/midroll-ad-1.xml',
753
+ },
754
+ {
755
+ type: 'midroll',
756
+ from: 30000, // 30 seconds
757
+ url: 'https://example.com/midroll-ad-2.xml',
758
+ },
759
+ // one midroll ad with different from time
760
+ {
761
+ type: 'midroll',
762
+ from: 60000, // 1 minute
763
+ url: 'https://example.com/midroll-ad-2.xml',
764
+ },
765
+ // postroll ad
766
+ {
767
+ type: 'postroll',
768
+ url: 'https://example.com/postroll-ad.xml',
769
+ },
770
+ ],
598
771
  }
599
772
  ```
600
773
  - It is also possible to set multiple urls for external source type, e.g. when you want to use both DASH and HLS formats. Player then automatically will pick most suitable format to play depending on device capabilities.
@@ -634,6 +807,23 @@ The `setSource` method allows you to dynamically change what's playing:
634
807
  // Change to a different video
635
808
  videoController.setSource('videos/newVideoId')
636
809
 
810
+ // Change to a video with custom ads
811
+ videoController.setSource({
812
+ path: 'videos/newVideoId',
813
+ name: 'Video with Ads',
814
+ staticAdsConfig: [
815
+ {
816
+ type: 'preroll',
817
+ url: 'https://example.com/preroll-ad.xml',
818
+ },
819
+ {
820
+ type: 'midroll',
821
+ from: 30000,
822
+ url: 'https://example.com/midroll-ad.xml',
823
+ },
824
+ ],
825
+ })
826
+
637
827
  // Change to an external video
638
828
  videoController.setSource({
639
829
  type: SourceType.VOD_EXTERNAL,
@@ -645,6 +835,18 @@ videoController.setSource({
645
835
  // Change to a TV channel
646
836
  videoController.setSource('tvChannels/channelId')
647
837
 
838
+ // Change to a TV channel with custom ads
839
+ videoController.setSource({
840
+ path: 'tvChannels/channelId',
841
+ name: 'TV Channel with Ads',
842
+ staticAdsConfig: [
843
+ {
844
+ type: 'preroll',
845
+ url: 'https://example.com/tv-preroll-ad.xml',
846
+ },
847
+ ],
848
+ })
849
+
648
850
  // Stop playback
649
851
  videoController.setSource(null)
650
852
  ```
@@ -665,6 +867,107 @@ The `setSource` method is particularly useful for:
665
867
 
666
868
  The VideoController emits various events that you can listen to:
667
869
 
870
+ #### Ad events
871
+
872
+ ```typescript
873
+ videoController.addEventListener('ad_started', (adMetadata: AdMetadata | null) => {
874
+ if (!adMetadata) {
875
+ console.log('Ad started playing (no metadata available)')
876
+ return
877
+ }
878
+
879
+ console.log('Ad started playing', adMetadata)
880
+
881
+ if ('customAdMetadata' in adMetadata && adMetadata.customAdMetadata) {
882
+ console.log('Ad custom metadata:', adMetadata.customAdMetadata)
883
+ // customAdMetadata contains VAST trafficking parameters (from VAST AdParameters tag)
884
+ }
885
+
886
+ // Access CTA element for rendering custom call-to-action buttons
887
+ const { ctaElement } = adMetadata
888
+ if (ctaElement) {
889
+ console.log('CTA element available for rendering custom buttons', ctaElement)
890
+
891
+ const { customAdMetadata } = adMetadata
892
+ if (!customAdMetadata) {
893
+ console.log('No custom ad metadata available')
894
+ return
895
+ }
896
+
897
+ const { extensions } = customAdMetadata
898
+ if (!extensions) {
899
+ console.log('No extensions available')
900
+ return
901
+ }
902
+
903
+ const { parameters } = extensions[0]
904
+ if (!parameters) {
905
+ console.log('No parameters available')
906
+ return
907
+ }
908
+
909
+ const metadataParameters = parameters as {
910
+ main_title?: string
911
+ subtitle?: string
912
+ image?: string
913
+ button_text: string
914
+ url: string
915
+ }
916
+
917
+ const buttonText = metadataParameters.button_text as string | undefined
918
+
919
+ if (!buttonText) {
920
+ console.log('No button text available')
921
+ return
922
+ }
923
+
924
+ // Example: Create a custom CTA button using React portal
925
+ const CTAButton = () => (
926
+ <div style={{
927
+ position: 'absolute',
928
+ bottom: '20px',
929
+ right: '20px',
930
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
931
+ color: 'white',
932
+ padding: '12px 24px',
933
+ borderRadius: '6px',
934
+ cursor: 'pointer',
935
+ fontSize: '16px',
936
+ fontWeight: 'bold',
937
+ pointerEvents: 'auto',
938
+ }}>
939
+ Learn More
940
+ </div>
941
+ )
942
+
943
+ // Render the CTA button using React portal
944
+ const root = ReactDOM.createRoot(ctaElement)
945
+ root.render(<CTAButton />)
946
+ }
947
+
948
+ // adMetadata contains information like:
949
+ // - ctaElement?: HTMLElement (for rendering custom CTA buttons)
950
+ // - customAdMetadata?: Record<string, unknown> (for IMA ads with rich metadata)
951
+ // - type: 'ad'
952
+ // - subType: 'inserted' | 'original'
953
+ // - secondsToEnd: number
954
+ // - secondsToSkippable: number | null
955
+ // - canTriggerSkip: boolean
956
+ // - isSkippable: boolean
957
+ // - order: number | null
958
+ // - totalCount: number | null
959
+ // - skip: () => void
960
+ // Update UI, show ad overlay, etc.
961
+ })
962
+
963
+ videoController.addEventListener('ad_ended', () => {
964
+ console.log('Ad finished playing')
965
+ })
966
+ ```
967
+
968
+ > ℹ️ **_Note:_** The CTA overlay element is visible in the WebPlayer only while an ad is playing and is automatically cleaned up on source changes.
969
+
970
+ #### Video state changes
668
971
  ```typescript
669
972
  // Video state changes
670
973
  videoController.addEventListener('statechange', (state) => {
@@ -737,105 +1040,4 @@ The `WebPlayerProps` interface defines the properties that can be passed to the
737
1040
 
738
1041
  ### Visual Properties
739
1042
 
740
- - **`showMarkers`** (optional, default: `false`): Whether to show video markers
741
- - **`markerColor`** (optional): Color for video markers (CSS color value)
742
- - **`showTvStreamType`** (optional): Whether to show TV stream type indicator
743
- - **`showCookiesSettings`** (optional): Whether to show cookies settings
744
- - **`showOsd`** (optional, default: `true`): Whether to show the On-Screen Display (OSD)
745
- - **`showBufferingSpinner`** (optional, default: `true`): Whether to show buffering spinner
746
-
747
- ### Audio Properties
748
-
749
- - **`isMutedByDefault`** (optional): If `true`, the player starts muted but can be unmuted
750
-
751
- ### Keyboard Shortcuts Properties
752
-
753
- - **`enableKeyboardShortcuts`** (optional, default: `true`): Whether to enable keyboard shortcuts
754
- - **`customShortcuts`** (optional): Custom keyboard shortcuts configuration:
755
- ```typescript
756
- {
757
- toggleFullscreen: number[], // Array of key codes
758
- togglePause: number[],
759
- toggleMute: number[],
760
- jumpForward: number[],
761
- jumpBack: number[],
762
- volumeUp: number[],
763
- volumeDown: number[]
764
- }
765
- ```
766
-
767
- ### Ad Block Properties
768
-
769
- - **`checkAdBlock`** (optional, default: `false`): Whether to check for ad blockers and show warnings
770
-
771
- ## Data hooks
772
- Gets information about current user.
773
-
774
- ```ts
775
- useUser: () => {
776
- user: User | null
777
- error: string | null
778
- isInitialized: boolean
779
- }
780
- ```
781
-
782
- ### useRowsInScreen hook
783
- Gets array of Rows objects of specific screen and subscribes to its changes.
784
-
785
- ```ts
786
- /**
787
- * Use rows in screen
788
- * @param screenId - screen id (from studio.tiv.io)
789
- * @param options - subscription options
790
- */
791
- useRowsInScreen: (screenId: string, options?: PaginationOptions) => {
792
- pagination: PaginationInterface<Row> | null
793
- error: Error | null
794
- }
795
- ```
796
-
797
- ### useItemsInRow hook
798
- Gets array of row items objects of specific row and subscribes to its changes.
799
-
800
- ```ts
801
- /**
802
- * Use row items
803
- * @param rowId - row ID
804
- * @param options - subscription options
805
- */
806
- useItemsInRow: (rowId: string, options?: SubscribeToItemsInRowOptions) => {
807
- pagination: PaginationInterface<ItemInRow> | null
808
- error: Error | null
809
- }
810
- ```
811
-
812
- ### useVideo hook
813
-
814
- Gets Video object and subscribes to its changes.
815
-
816
- ```ts
817
- /**
818
- * Use video
819
- * @param videoId - video id
820
- */
821
- useVideo: (videoId: string) => {
822
- error: string | null;
823
- data: Video | null;
824
- }
825
- ```
826
-
827
- ### useTaggedVideos hook
828
- Gets videos with given tag IDs.
829
-
830
- ```ts
831
- /**
832
- * Use tagged videos
833
- * @param tagIds - tag ids
834
- * @param options - subscription options
835
- * @public
836
- */
837
- useTaggedVideos: (tagIds: string[], options?: SubscribeToItemsInRowOptions) => {
838
- pagination: PaginationInterface<Video> | null
839
- error: Error | null
840
- }
841
- ```
1043
+ - **`showMarkers`