@tivio/sdk-react 9.4.0 → 9.6.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.bak 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.
@@ -626,6 +799,56 @@ The `sourcePlayMode` property determines how the content is played:
626
799
  - **LIVE** - Live stream mode with no seeking
627
800
  - **HYBRID** - Combines LIVE with seeking
628
801
 
802
+ #### User Authentication Callbacks
803
+
804
+ The `userAuthCallbacks` property allows you to handle user authentication flows when the player requires user login or registration. This is particularly useful for content that requires authentication (e.g., premium content).
805
+
806
+ ```typescript
807
+ interface UserAuthCallbacks {
808
+ onGoToLogin: () => void
809
+ onGoToRegistration: () => void
810
+ }
811
+ ```
812
+
813
+ **Example Implementation:**
814
+
815
+ ```typescript
816
+ // Usage with renderWebPlayer
817
+ const videoController = await renderWebPlayer(
818
+ document.getElementById('video-player'),
819
+ {
820
+ id: 'player-main',
821
+ source: 'videos/PREMIUM_VIDEO_ID',
822
+ userAuthCallbacks: {
823
+ onGoToLogin: () => {
824
+ // Show your login modal
825
+ setShowLoginModal(true)
826
+ },
827
+ onGoToRegistration: () => {
828
+ // Show your registration modal
829
+ setShowRegistrationModal(true)
830
+ },
831
+ },
832
+ }
833
+ )
834
+
835
+ // Handle login in your modal
836
+ const handleLogin = async (email: string, password: string) => {
837
+ try {
838
+ await tivio.signInWithEmailAndPassword(email, password)
839
+ console.log('Login successful')
840
+ } catch (error) {
841
+ console.error('Login failed:', error)
842
+ throw error
843
+ }
844
+ }
845
+ ```
846
+
847
+ **When are these callbacks triggered?**
848
+
849
+ - **`onGoToLogin`**: Called when the player is trying to play content behind a paywall and user clicks on the login button in the overlay
850
+ - **`onGoToRegistration`**: Called when the player is trying to play content behind a paywall and user clicks on the registration button in the overlay
851
+
629
852
  #### Using setSource with VideoController
630
853
 
631
854
  The `setSource` method allows you to dynamically change what's playing:
@@ -634,6 +857,23 @@ The `setSource` method allows you to dynamically change what's playing:
634
857
  // Change to a different video
635
858
  videoController.setSource('videos/newVideoId')
636
859
 
860
+ // Change to a video with custom ads
861
+ videoController.setSource({
862
+ path: 'videos/newVideoId',
863
+ name: 'Video with Ads',
864
+ staticAdsConfig: [
865
+ {
866
+ type: 'preroll',
867
+ url: 'https://example.com/preroll-ad.xml',
868
+ },
869
+ {
870
+ type: 'midroll',
871
+ from: 30000,
872
+ url: 'https://example.com/midroll-ad.xml',
873
+ },
874
+ ],
875
+ })
876
+
637
877
  // Change to an external video
638
878
  videoController.setSource({
639
879
  type: SourceType.VOD_EXTERNAL,
@@ -645,6 +885,18 @@ videoController.setSource({
645
885
  // Change to a TV channel
646
886
  videoController.setSource('tvChannels/channelId')
647
887
 
888
+ // Change to a TV channel with custom ads
889
+ videoController.setSource({
890
+ path: 'tvChannels/channelId',
891
+ name: 'TV Channel with Ads',
892
+ staticAdsConfig: [
893
+ {
894
+ type: 'preroll',
895
+ url: 'https://example.com/tv-preroll-ad.xml',
896
+ },
897
+ ],
898
+ })
899
+
648
900
  // Stop playback
649
901
  videoController.setSource(null)
650
902
  ```
@@ -665,6 +917,107 @@ The `setSource` method is particularly useful for:
665
917
 
666
918
  The VideoController emits various events that you can listen to:
667
919
 
920
+ #### Ad events
921
+
922
+ ```typescript
923
+ videoController.addEventListener('ad-started', (adMetadata: AdMetadata | null) => {
924
+ if (!adMetadata) {
925
+ console.log('Ad started playing (no metadata available)')
926
+ return
927
+ }
928
+
929
+ console.log('Ad started playing', adMetadata)
930
+
931
+ if ('customAdMetadata' in adMetadata && adMetadata.customAdMetadata) {
932
+ console.log('Ad custom metadata:', adMetadata.customAdMetadata)
933
+ // customAdMetadata contains VAST trafficking parameters (from VAST AdParameters tag)
934
+ }
935
+
936
+ // Access CTA element for rendering custom call-to-action buttons
937
+ const { ctaElement } = adMetadata
938
+ if (ctaElement) {
939
+ console.log('CTA element available for rendering custom buttons', ctaElement)
940
+
941
+ const { customAdMetadata } = adMetadata
942
+ if (!customAdMetadata) {
943
+ console.log('No custom ad metadata available')
944
+ return
945
+ }
946
+
947
+ const { extensions } = customAdMetadata
948
+ if (!extensions) {
949
+ console.log('No extensions available')
950
+ return
951
+ }
952
+
953
+ const { parameters } = extensions[0]
954
+ if (!parameters) {
955
+ console.log('No parameters available')
956
+ return
957
+ }
958
+
959
+ const metadataParameters = parameters as {
960
+ main_title?: string
961
+ subtitle?: string
962
+ image?: string
963
+ button_text: string
964
+ url: string
965
+ }
966
+
967
+ const buttonText = metadataParameters.button_text as string | undefined
968
+
969
+ if (!buttonText) {
970
+ console.log('No button text available')
971
+ return
972
+ }
973
+
974
+ // Example: Create a custom CTA button using React portal
975
+ const CTAButton = () => (
976
+ <div style={{
977
+ position: 'absolute',
978
+ bottom: '20px',
979
+ right: '20px',
980
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
981
+ color: 'white',
982
+ padding: '12px 24px',
983
+ borderRadius: '6px',
984
+ cursor: 'pointer',
985
+ fontSize: '16px',
986
+ fontWeight: 'bold',
987
+ pointerEvents: 'auto',
988
+ }}>
989
+ Learn More
990
+ </div>
991
+ )
992
+
993
+ // Render the CTA button using React portal
994
+ const root = ReactDOM.createRoot(ctaElement)
995
+ root.render(<CTAButton />)
996
+ }
997
+
998
+ // adMetadata contains information like:
999
+ // - ctaElement?: HTMLElement (for rendering custom CTA buttons)
1000
+ // - customAdMetadata?: Record<string, unknown> (for IMA ads with rich metadata)
1001
+ // - type: 'ad'
1002
+ // - subType: 'inserted' | 'original'
1003
+ // - secondsToEnd: number
1004
+ // - secondsToSkippable: number | null
1005
+ // - canTriggerSkip: boolean
1006
+ // - isSkippable: boolean
1007
+ // - order: number | null
1008
+ // - totalCount: number | null
1009
+ // - skip: () => void
1010
+ // Update UI, show ad overlay, etc.
1011
+ })
1012
+
1013
+ videoController.addEventListener('ad-ended', () => {
1014
+ console.log('Ad finished playing')
1015
+ })
1016
+ ```
1017
+
1018
+ > ℹ️ **_Note:_** The CTA overlay element is visible in the WebPlayer only while an ad is playing and is automatically cleaned up on source changes.
1019
+
1020
+ #### Video state changes
668
1021
  ```typescript
669
1022
  // Video state changes
670
1023
  videoController.addEventListener('statechange', (state) => {
@@ -752,7 +1105,7 @@ The `WebPlayerProps` interface defines the properties that can be passed to the
752
1105
 
753
1106
  - **`enableKeyboardShortcuts`** (optional, default: `true`): Whether to enable keyboard shortcuts
754
1107
  - **`customShortcuts`** (optional): Custom keyboard shortcuts configuration:
755
- ```typescript
1108
+ ```typescript
756
1109
  {
757
1110
  toggleFullscreen: number[], // Array of key codes
758
1111
  togglePause: number[],
@@ -762,7 +1115,7 @@ The `WebPlayerProps` interface defines the properties that can be passed to the
762
1115
  volumeUp: number[],
763
1116
  volumeDown: number[]
764
1117
  }
765
- ```
1118
+ ```
766
1119
 
767
1120
  ### Ad Block Properties
768
1121