@tivio/sdk-js 1.0.0-alpha
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE.md +35 -0
- package/README.md +155 -0
- package/dist/api.types.d.ts +220 -0
- package/dist/conf.d.ts +20 -0
- package/dist/conf.test.d.ts +1 -0
- package/dist/customPlayer.types.d.ts +36 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/services/bundleLoader.d.ts +33 -0
- package/dist/services/bundleLoader.test.d.ts +1 -0
- package/dist/services/dependencyResolver.d.ts +12 -0
- package/dist/services/dependencyResolver.test.d.ts +1 -0
- package/dist/services/logger.d.ts +28 -0
- package/dist/services/logger.test.d.ts +1 -0
- package/dist/services/packageLoader.d.ts +6 -0
- package/dist/services/packageLoader.test.d.ts +1 -0
- package/dist/services/settings.d.ts +17 -0
- package/dist/services/settings.test.d.ts +1 -0
- package/dist/setupTests.d.ts +20 -0
- package/dist/types.d.ts +11 -0
- package/package.json +48 -0
package/LICENSE.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Copyright © 2021, nangu.TV, a.s.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
This software and related documentation are provided under a
|
5
|
+
license agreement containing restrictions on use and
|
6
|
+
disclosure and are protected by intellectual property laws.
|
7
|
+
Except as expressly permitted in your license agreement or
|
8
|
+
allowed by law, you may not use, copy, reproduce, translate,
|
9
|
+
broadcast, modify, license, transmit, distribute, exhibit,
|
10
|
+
perform, publish, or display any part, in any form, or by
|
11
|
+
any means. Except as expressly permitted in your license agreement
|
12
|
+
or allowed by law, reverse engineering, disassembly, or decompilation
|
13
|
+
of this software is prohibited.
|
14
|
+
|
15
|
+
The information contained herein is subject to change
|
16
|
+
without notice and is not warranted to be error-free. If you
|
17
|
+
find any errors, please report them to us in writing.
|
18
|
+
|
19
|
+
This software is developed for general use. It is not
|
20
|
+
developed or intended for use in any inherently dangerous
|
21
|
+
applications, including applications that may create a risk
|
22
|
+
of personal injury. If you use this software or hardware in
|
23
|
+
dangerous applications, then you shall be responsible to
|
24
|
+
take all appropriate fail-safe, backup, redundancy, and
|
25
|
+
other measures to ensure its safe use. Nangu.TV, a.s. disclaims any
|
26
|
+
liability for any damages caused by use of this software or
|
27
|
+
hardware in dangerous applications.
|
28
|
+
|
29
|
+
This software and documentation may provide
|
30
|
+
access to or information on content, products, and services
|
31
|
+
from third parties. Nangu.TV, a.s. is not responsible for and expressly
|
32
|
+
disclaim all warranties of any kind with respect to third-party content,
|
33
|
+
products, and services. Nangu.TV, a.s. will not be responsible for any
|
34
|
+
loss, costs, or damages incurred due to your access to or use of third-party
|
35
|
+
content, products, or services.
|
package/README.md
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
# Tivio SDK
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
``` sh
|
6
|
+
npm install --save @tivio/sdk-js
|
7
|
+
```
|
8
|
+
or
|
9
|
+
``` sh
|
10
|
+
yarn add @tivio/sdk-js
|
11
|
+
```
|
12
|
+
|
13
|
+
# Changelog
|
14
|
+
|
15
|
+
* 1.0.0
|
16
|
+
* initial public release
|
17
|
+
<!--
|
18
|
+
####################################################################################################
|
19
|
+
TODO FIXME: This file describes how it should look like based on https://jira.nangu.tv/browse/NS-96,
|
20
|
+
it needs to be checked/corrected before @tivio/sdk-js will be really published!
|
21
|
+
####################################################################################################
|
22
|
+
-->
|
23
|
+
|
24
|
+
<!--
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
``` typescript
|
28
|
+
import { todo } from '@tivio/js'
|
29
|
+
|
30
|
+
```
|
31
|
+
|
32
|
+
## Example usage
|
33
|
+
|
34
|
+
```typescript
|
35
|
+
import { initTivio } from '@tivio/sdk-js'
|
36
|
+
|
37
|
+
(async () => {
|
38
|
+
const tivio = await initTivio({secret: 'HG3PbieoHQ5DSH9f2xxx'})
|
39
|
+
|
40
|
+
const channels = tivio.getWidgetById('myWidget').getChannels()
|
41
|
+
|
42
|
+
for (const channel of channels.records) {
|
43
|
+
const sections = await channel.getSections()
|
44
|
+
|
45
|
+
for (const section of sections.records) {
|
46
|
+
let hasNextPage = true
|
47
|
+
|
48
|
+
do {
|
49
|
+
const videos = await section.getVideos({count: 10})
|
50
|
+
|
51
|
+
for (const video of videos.records) {
|
52
|
+
console.log(video.name, video.url.hls)
|
53
|
+
}
|
54
|
+
|
55
|
+
hasNextPage = videos.hasNextPage
|
56
|
+
|
57
|
+
} while (hasNextPage)
|
58
|
+
}
|
59
|
+
}
|
60
|
+
})()
|
61
|
+
```
|
62
|
+
|
63
|
+
## Api Description
|
64
|
+
|
65
|
+
### Init
|
66
|
+
|
67
|
+
- The init method is called with parameter `secret` that is generated in administration and identifies the application.
|
68
|
+
- Init returns a Tivio instance.
|
69
|
+
|
70
|
+
```typescript
|
71
|
+
interface Config {
|
72
|
+
secret: string
|
73
|
+
}
|
74
|
+
|
75
|
+
type initTivio = (config: Config) => Promise<Tivio>
|
76
|
+
|
77
|
+
interface Tivio {
|
78
|
+
getWidgetById: (id: string) => Widget
|
79
|
+
}
|
80
|
+
```
|
81
|
+
|
82
|
+
### Pagination
|
83
|
+
|
84
|
+
- Result of methods that can return a larger amount of data is wrapped in the `Pagination` object.
|
85
|
+
- To get all records iterate until the `hasNextPage` is true.
|
86
|
+
- Called method can have a `count` parameter to change the number of returned records.
|
87
|
+
|
88
|
+
```typescript
|
89
|
+
type Pagination<T> = (props?: {count?: number}) => Promise<{
|
90
|
+
records: T[]
|
91
|
+
hasNextPage: boolean
|
92
|
+
}>
|
93
|
+
```
|
94
|
+
|
95
|
+
### Widget
|
96
|
+
|
97
|
+
- A Widget holds together multiple channels with some specific configuration.
|
98
|
+
|
99
|
+
```typescript
|
100
|
+
interface Widget {
|
101
|
+
id: string
|
102
|
+
name: string
|
103
|
+
getChannels: Pagination<Channel>
|
104
|
+
getRecent: Pagination<Video>
|
105
|
+
}
|
106
|
+
```
|
107
|
+
|
108
|
+
### Channel
|
109
|
+
|
110
|
+
- A Channel holds together multiple Sections (if it is the deepest Channel in the hierarchy) OR Channels
|
111
|
+
(if it is a container; this allows deeper hierarchy like "Widget > Channel > Channel > Section > Video"
|
112
|
+
instead of typical "Widget > Channel > Section > Video")
|
113
|
+
|
114
|
+
```typescript
|
115
|
+
interface Channel {
|
116
|
+
id: string
|
117
|
+
name: string
|
118
|
+
getChannels?: Pagination<Channel>
|
119
|
+
getSections?: Pagination<Section>
|
120
|
+
getRecent: Pagination<Video>
|
121
|
+
images: {
|
122
|
+
cover?: string
|
123
|
+
logo?: string
|
124
|
+
}
|
125
|
+
}
|
126
|
+
```
|
127
|
+
|
128
|
+
### Section
|
129
|
+
|
130
|
+
- The Section is a container for multiple videos.
|
131
|
+
|
132
|
+
```typescript
|
133
|
+
interface Section {
|
134
|
+
id: string
|
135
|
+
name: string
|
136
|
+
getVideos: Pagination<Video>
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
### Video
|
141
|
+
|
142
|
+
```typescript
|
143
|
+
interface Video {
|
144
|
+
id: string
|
145
|
+
name: string
|
146
|
+
durationMs: number
|
147
|
+
created: Date
|
148
|
+
images: {
|
149
|
+
cover?: string
|
150
|
+
}
|
151
|
+
url: {
|
152
|
+
hls: string
|
153
|
+
}
|
154
|
+
}
|
155
|
+
``` -->
|
@@ -0,0 +1,220 @@
|
|
1
|
+
import type { Video, SubscribeToScreen, SubscribeToItemsInRow } from '@tivio/common';
|
2
|
+
declare type Language = 'cs' | 'en' | 'sk' | 'de' | 'pl';
|
3
|
+
declare type Widget = {
|
4
|
+
channels: Channel[];
|
5
|
+
isEnabled: boolean | null;
|
6
|
+
name: string | null;
|
7
|
+
recentVideos: Video[] | null;
|
8
|
+
widgetId: string | null;
|
9
|
+
};
|
10
|
+
declare type Channel = {
|
11
|
+
name: string;
|
12
|
+
header: string;
|
13
|
+
headerLogo: string;
|
14
|
+
recentVideos: Video[];
|
15
|
+
};
|
16
|
+
declare type Section = {
|
17
|
+
name: string;
|
18
|
+
channel: Channel;
|
19
|
+
videos: Video[];
|
20
|
+
};
|
21
|
+
declare type Player = {
|
22
|
+
ad: any;
|
23
|
+
currentTime: any;
|
24
|
+
adSegment: any;
|
25
|
+
event: any;
|
26
|
+
events: any;
|
27
|
+
source: any;
|
28
|
+
state: any;
|
29
|
+
onPlaybackEnded: any;
|
30
|
+
onSourceChanged: any;
|
31
|
+
onStateChanged: any;
|
32
|
+
onTimeChanged: any;
|
33
|
+
pause: any;
|
34
|
+
play: any;
|
35
|
+
togglePlayPause: any;
|
36
|
+
register: any;
|
37
|
+
seekTo: any;
|
38
|
+
setVolume: any;
|
39
|
+
triggerEvent: any;
|
40
|
+
};
|
41
|
+
declare type Source = {
|
42
|
+
type: 'tv_program';
|
43
|
+
uri: string;
|
44
|
+
tvMode: 'startover' | 'timeshift' | null;
|
45
|
+
channelName: string;
|
46
|
+
epgFrom: Date;
|
47
|
+
epgTo: Date;
|
48
|
+
positionMs: number;
|
49
|
+
additionalPayload?: Record<string, any>;
|
50
|
+
} | {
|
51
|
+
type: 'tivio_vod';
|
52
|
+
uri: string;
|
53
|
+
positionMs: number;
|
54
|
+
videoPath: string;
|
55
|
+
additionalPayload?: Record<string, any>;
|
56
|
+
} | {
|
57
|
+
type: 'ad';
|
58
|
+
uri: string;
|
59
|
+
additionalPayload?: Record<string, any>;
|
60
|
+
} | {
|
61
|
+
type: 'other';
|
62
|
+
uri: string;
|
63
|
+
positionMs: number;
|
64
|
+
additionalPayload?: Record<string, any>;
|
65
|
+
} | {
|
66
|
+
type: 'live_tv_channel';
|
67
|
+
uri: string;
|
68
|
+
channelName: string;
|
69
|
+
positionMs: number;
|
70
|
+
additionalPayload?: Record<string, any>;
|
71
|
+
};
|
72
|
+
declare type AdMetadata = {
|
73
|
+
type: 'ad';
|
74
|
+
subType: 'inserted' | 'original';
|
75
|
+
secondsToEnd: number;
|
76
|
+
secondsToSkippable: number | null;
|
77
|
+
canTriggerSkip: boolean;
|
78
|
+
skip: () => void;
|
79
|
+
} | null;
|
80
|
+
declare enum PlayerWrapperEventType {
|
81
|
+
adMetadata = "adMetadata"
|
82
|
+
}
|
83
|
+
declare type TivioPlayerWrapper = {
|
84
|
+
addEventListener: (eventType: PlayerWrapperEventType.adMetadata, listener: (metadata: AdMetadata) => void) => void;
|
85
|
+
reportLoadError: (error: Error) => void;
|
86
|
+
reportPlaybackEnded: () => void;
|
87
|
+
reportTimeProgress: (ms: number) => void;
|
88
|
+
seekTo: (ms: number) => void;
|
89
|
+
setSource: (source: Source | null) => void;
|
90
|
+
};
|
91
|
+
declare type ExposedApi = {
|
92
|
+
AdSource: any;
|
93
|
+
ChannelSource: any;
|
94
|
+
VodTivioSource: any;
|
95
|
+
/**
|
96
|
+
* Get channel by its id.
|
97
|
+
* @param channelId - channel id
|
98
|
+
* @returns {Promise<Channel | null>} channel or null if channel does not exists
|
99
|
+
*/
|
100
|
+
getChannelById: (channelId: string) => Promise<Channel | null>;
|
101
|
+
/**
|
102
|
+
* Get (or create) player wrapper instance
|
103
|
+
* @param id - player wrapper id
|
104
|
+
* @returns {Player} player wrapper instance
|
105
|
+
*/
|
106
|
+
getPlayer: (id: string) => Player;
|
107
|
+
/**
|
108
|
+
* Get section by its id.
|
109
|
+
* @param sectionId - section id
|
110
|
+
* @returns {Promise<{section: Section, channel: Channel} | null>} section and channel or null if channel or section does not exists
|
111
|
+
*/
|
112
|
+
getSectionById: (sectionId: string) => Promise<Section | null>;
|
113
|
+
/**
|
114
|
+
* Get video by its id.
|
115
|
+
* @param videoId - video id
|
116
|
+
* @returns {Promise<Video | null>} video or null if video does not exists
|
117
|
+
*/
|
118
|
+
getVideoById: (videoId: string) => Promise<Video | null>;
|
119
|
+
/**
|
120
|
+
* Get widget by its id.
|
121
|
+
* @param widgetId - widget id
|
122
|
+
* @returns {Promise<Widget | null>} widget or null if widget does not exists
|
123
|
+
*/
|
124
|
+
getWidgetById: (widgetId: string) => Promise<Widget | null>;
|
125
|
+
/**
|
126
|
+
* Set tivio language.
|
127
|
+
* @param language
|
128
|
+
*/
|
129
|
+
setLanguage: (language: Language) => void;
|
130
|
+
/**
|
131
|
+
* Set user.
|
132
|
+
* @param userId
|
133
|
+
* @param payload
|
134
|
+
* @param additionalUserData
|
135
|
+
*/
|
136
|
+
setUser: (userId: string, payload: unknown, additionalUserData?: unknown) => Promise<void>;
|
137
|
+
/**
|
138
|
+
* Listen to widget changes.
|
139
|
+
* @param widgetId - widget id
|
140
|
+
* @param cb - callback on widget updates or on error
|
141
|
+
*/
|
142
|
+
subscribeToWidget: (widgetId: string, cb: (error: Error | null, data: Widget | null) => void) => void;
|
143
|
+
/**
|
144
|
+
* Listen to channel changes.
|
145
|
+
* @param channelId - channel id
|
146
|
+
* @param cb - callback on channel updates or on error
|
147
|
+
*/
|
148
|
+
subscribeToChannel: (channelId: string, cb: (error: Error | null, data: Channel | null) => void) => void;
|
149
|
+
/**
|
150
|
+
* Listen to section changes.
|
151
|
+
* @param sectionId - section id
|
152
|
+
* @param cb - callback on section updates or on error
|
153
|
+
*/
|
154
|
+
subscribeToSection: (sectionId: string, cb: (error: Error | null, data: Section | null) => void) => void;
|
155
|
+
/**
|
156
|
+
* Listen to video changes.
|
157
|
+
* @param videoId - video id
|
158
|
+
* @param cb - callback on video updates or on error
|
159
|
+
*/
|
160
|
+
subscribeToVideo: (videoId: string, cb: (error: Error | null, data: Video | null) => void) => void;
|
161
|
+
/**
|
162
|
+
* Listen to videos in section changes.
|
163
|
+
* @param channelId - channel id
|
164
|
+
* @param sectionId - section id
|
165
|
+
* @param cb - callback on videos change or error
|
166
|
+
* @param limit - videos count
|
167
|
+
*/
|
168
|
+
subscribeToVideosInSection: (sectionId: string, cb: (error: null | Error, data: null | {
|
169
|
+
videos: Video[];
|
170
|
+
hasNextPage: boolean;
|
171
|
+
}, fetchMore: null | ((count?: number) => void)) => void, limit?: number) => void;
|
172
|
+
/**
|
173
|
+
* Listen to section in channel changes
|
174
|
+
* @param channelId - channel id
|
175
|
+
* @param cb - callback on sections change or error
|
176
|
+
* @param limit - sections count
|
177
|
+
*/
|
178
|
+
subscribeToSectionsInChannel: (channelId: string, cb: (error: null | Error, data: null | {
|
179
|
+
sections: Section[];
|
180
|
+
hasNextPage: boolean;
|
181
|
+
}, fetchMore: null | ((count?: number) => void)) => void, limit?: number) => void;
|
182
|
+
/**
|
183
|
+
* Listen to channels in widget changes
|
184
|
+
* @param widgetId - widget id
|
185
|
+
* @param cb - callback on channels change or error
|
186
|
+
* @param limit - channels count
|
187
|
+
*/
|
188
|
+
subscribeToChannelsInWidget: (widgetId: string, cb: (error: null | Error, data: null | {
|
189
|
+
channels: Channel[];
|
190
|
+
hasNextPage: boolean;
|
191
|
+
}, fetchMore: null | ((count?: number) => void)) => void, limit?: number) => void;
|
192
|
+
/**
|
193
|
+
* @param screenId - screen id
|
194
|
+
* @param cb - callback on screen or error
|
195
|
+
* @param options - additional options
|
196
|
+
*/
|
197
|
+
subscribeToScreen: SubscribeToScreen;
|
198
|
+
/**
|
199
|
+
* @param rowId - screen id
|
200
|
+
* @param cb - callback on items or error
|
201
|
+
* @param options - additional options
|
202
|
+
*/
|
203
|
+
subscribeToItemsInRow: SubscribeToItemsInRow;
|
204
|
+
/**
|
205
|
+
* @param email
|
206
|
+
* @param password
|
207
|
+
*/
|
208
|
+
createUserWithEmailAndPassword: (email: string, password: string) => Promise<void>;
|
209
|
+
/**
|
210
|
+
* Sign in the user and starts listening on his purchases
|
211
|
+
* @param email
|
212
|
+
* @param password
|
213
|
+
*/
|
214
|
+
signInWithEmailAndPassword: (email: string, password: string) => Promise<void>;
|
215
|
+
createPlayerWrapper: (playerImplementation: {
|
216
|
+
setSource: (source: Source | null) => void;
|
217
|
+
seekTo: (ms: number) => void;
|
218
|
+
}) => TivioPlayerWrapper;
|
219
|
+
};
|
220
|
+
export { AdMetadata, ExposedApi, TivioPlayerWrapper, PlayerWrapperEventType, Source, };
|
package/dist/conf.d.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
|
3
|
+
* nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
4
|
+
*/
|
5
|
+
import { Conf as ExternalConf } from './types';
|
6
|
+
import { Logger } from './services/logger';
|
7
|
+
import { FetchPackage } from './services/packageLoader';
|
8
|
+
export declare type InternalConf = {
|
9
|
+
secret: string;
|
10
|
+
resolverUrl: string;
|
11
|
+
logger?: Logger | null;
|
12
|
+
fetchPackage: FetchPackage;
|
13
|
+
language?: string;
|
14
|
+
sdkVersion: string;
|
15
|
+
};
|
16
|
+
export declare const defaultConf: {
|
17
|
+
resolverUrl: string;
|
18
|
+
fetchPackage: FetchPackage;
|
19
|
+
};
|
20
|
+
export declare const createInternalConf: (conf: ExternalConf) => InternalConf;
|
@@ -0,0 +1 @@
|
|
1
|
+
import './setupTests';
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import type { Empty } from './types';
|
2
|
+
interface BasicSource {
|
3
|
+
description: string;
|
4
|
+
name: string;
|
5
|
+
uri: string;
|
6
|
+
type: 'AD' | 'VOD' | 'CHANNEL';
|
7
|
+
}
|
8
|
+
interface ChannelSource extends BasicSource {
|
9
|
+
from: Date;
|
10
|
+
channelName: string;
|
11
|
+
to: Date;
|
12
|
+
type: 'CHANNEL';
|
13
|
+
}
|
14
|
+
interface AdSource extends BasicSource {
|
15
|
+
durationMs: number;
|
16
|
+
skipDelayMs: number | null;
|
17
|
+
type: 'AD';
|
18
|
+
}
|
19
|
+
interface VodSource extends BasicSource {
|
20
|
+
type: 'VOD';
|
21
|
+
}
|
22
|
+
export declare type InputSource = AdSource | ChannelSource | VodSource;
|
23
|
+
export declare type PlayerInterface = {
|
24
|
+
play: () => Empty;
|
25
|
+
pause: () => Empty;
|
26
|
+
seekTo: (positionMs: number) => Empty;
|
27
|
+
setSource: (source: InputSource | null) => Empty;
|
28
|
+
setVolume: (volume: number) => Empty;
|
29
|
+
};
|
30
|
+
export declare type PlayerWrapper = {
|
31
|
+
events: {
|
32
|
+
addListener: <T = any>(event: string, cb: (value: T) => Empty) => Empty;
|
33
|
+
removeAllListeners: () => Empty;
|
34
|
+
};
|
35
|
+
};
|
36
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@sentry/browser"),require("firebase/app"),require("firebase/auth"),require("firebase/firestore"),require("mobx")):"function"==typeof define&&define.amd?define("@tivio/sdk-js",["@sentry/browser","firebase/app","firebase/auth","firebase/firestore","mobx"],t):"object"==typeof exports?exports["@tivio/sdk-js"]=t(require("@sentry/browser"),require("firebase/app"),require("firebase/auth"),require("firebase/firestore"),require("mobx")):e["@tivio/sdk-js"]=t(e["@sentry/browser"],e["firebase/app"],e["firebase/auth"],e["firebase/firestore"],e.mobx)}(this,(function(e,t,r,n,o){return i={992:(e,t)=>{"use strict";var r;Object.defineProperty(t,"__esModule",{value:!0}),t.PlayerWrapperEventType=void 0,function(e){e.adMetadata="adMetadata"}(r||(r={})),t.PlayerWrapperEventType=r},958:function(e,t,r){"use strict";var n=this&&this.__assign||function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.createInternalConf=t.defaultConf=void 0;var o=r(782),i=r(373);t.defaultConf={resolverUrl:"https://tivio-resolver.firebaseapp.com/resolver.js",fetchPackage:i.fetchPackage},t.createInternalConf=function(e){return n(n(n({},t.defaultConf),e),{logger:void 0!==e.logger?e.logger:(0,o.createLogger)({isConsoleEnabled:!0}),sdkVersion:"1.0.0-alpha"})}},920:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),o(r(643),t),o(r(173),t),o(r(992),t)},643:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.createTivio=t.createRemotePackageLoader=t.fetchResolver=void 0;var i=r(958),a=r(229),s=r(614);t.fetchResolver=function(e){return n(void 0,void 0,void 0,(function(){var t;return o(this,(function(r){return t=e.resolverUrl,[2,(0,e.fetchPackage)(t).then((function(t){var r,n={},o={exports:n};try{new Function("require","module","exports",t)(a.resolveShared,o,n)}catch(e){throw new Error("Cannot load Tivio Resolver "+e)}if("function"!=typeof(null===(r=o.exports.tivio)||void 0===r?void 0:r.fetch))throw new Error("Invalid Tivio Resolver export");return o.exports.tivio.fetch(e.secret,e.sdkVersion)}))]}))}))},t.createRemotePackageLoader=function(){return function(e){return(0,t.fetchResolver)(e).then((function(e){var t={},r={exports:t};try{new Function("require","module","exports",e)(a.resolveShared,r,t)}catch(e){throw new Error("Cannot load module "+e)}if("object"!=typeof r.exports.Tivio)throw new Error('Tivio package does not export "Tivio" namespace');if("function"!=typeof r.exports.Tivio.setUser)throw new Error('Tivio namespace does not export "setUser" member');if("function"!=typeof r.exports.Tivio.init)throw new Error('Tivio namespace does not export "init" member');return r.exports.Tivio}))}},t.createTivio=function(){var e=(0,t.createRemotePackageLoader)(),r=!1;return function(t){return n(void 0,void 0,void 0,(function(){var a,u;return o(this,(function(c){return a=(0,i.createInternalConf)(t),u=(0,s.createSettings)(a),[2,e(a).then((function(e){return n(void 0,void 0,void 0,(function(){return o(this,(function(t){switch(t.label){case 0:return r?[3,2]:[4,e.init(a)];case 1:t.sent(),r=!0,t.label=2;case 2:return u.onSetUser(e.setUser),[2,{state:"ready",error:null,settings:u,conf:a,AdSource:e.AdSource,ChannelSource:e.ChannelSource,VodTivioSource:e.VodTivioSource,getChannelById:e.getChannelById,getPlayer:e.getPlayer,getSectionById:e.getSectionById,getVideoById:e.getVideoById,getWidgetById:e.getWidgetById,setLanguage:e.setLanguage,setUser:e.setUser,subscribeToWidget:e.subscribeToWidget,subscribeToChannel:e.subscribeToChannel,subscribeToSection:e.subscribeToSection,subscribeToVideo:e.subscribeToVideo,subscribeToVideosInSection:e.subscribeToVideosInSection,subscribeToSectionsInChannel:e.subscribeToSectionsInChannel,subscribeToChannelsInWidget:e.subscribeToChannelsInWidget,subscribeToScreen:e.subscribeToScreen,subscribeToItemsInRow:e.subscribeToItemsInRow,createUserWithEmailAndPassword:e.createUserWithEmailAndPassword,signInWithEmailAndPassword:e.signInWithEmailAndPassword,createPlayerWrapper:e.createPlayerWrapper}]}}))}))})).catch((function(e){var t;return null===(t=a.logger)||void 0===t||t.exception(e),{state:"error",error:""+e,conf:a,settings:u}}))]}))}))}}},229:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return o(t,e),t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.resolveShared=void 0;var s=a(r(937));r(703),r(462);var u=i(r(259)),c=i(r(970)),l={mobx:u,firebase:s.default,"firebase/app":s.default,"firebase/auth":null,"firebase/firestore":null,timers:c};t.resolveShared=function(e){if(!(e in l))throw new Error("Could not resolve shared dependency "+e);return l[e]}},782:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&n(t,e,r);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.createLogger=void 0;var a=i(r(356));t.createLogger=function(e){var t=!1!==e.isSentryEnabled&&!0;t&&(a.init({dsn:"https://f318b29129f84c459ea756907bc1a2e6@o507550.ingest.sentry.io/5600272",release:"@tivio/sdk-js@1.0.0-alpha",tracesSampleRate:1}),window.sentry=a),console.info("Sentry "+(t?"on":"off"));var r=function(r,n){e.isConsoleEnabled&&console[r]("Tivio sdk-js "+n.join(" ")),t&&a.captureMessage(""+n,a.Severity.fromString(r))};return{error:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r("error",e)},info:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r("info",e)},warn:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r("warn",e)},debug:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r("debug",e)},exception:function(r){e.isConsoleEnabled&&console.error(r),t&&a.captureException(r)}}}},373:function(e,t){"use strict";var r=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))},n=this&&this.__generator||function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.fetchPackage=void 0;var o={cache:"no-store"},i=function(e){var t=e.headers.get("content-type");return 200!==e.status?Promise.reject('Incorrect status "'+e.status+'" was obtained while fetching the module.'):t&&(t.includes("application/javascript")||t.includes("text/javascript"))?e.text():Promise.reject('Incorrect content "'+t+'" was obtained while fetching the module.')},a=function(e){return Promise.reject("Network failure: "+e)};t.fetchPackage=function(e){return r(void 0,void 0,void 0,(function(){return n(this,(function(t){return[2,fetch(e,o).then(i).catch(a)]}))}))}},614:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.createSettings=void 0,t.createSettings=function(e){var t=null,r=null;return{onSetUser:function(n){var o;"function"!=typeof n?null===(o=e.logger)||void 0===o||o.exception("Tivio Bundle setUser handler must be a function"):(t=n,null!==r&&n(r.userId,r.userPayload))},setUser:function(e,n){"function"==typeof t?(r=null,t(e,n)):r={userId:e,userPayload:n}}}}},173:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},356:t=>{"use strict";t.exports=e},937:e=>{"use strict";e.exports=t},703:e=>{"use strict";e.exports=r},462:e=>{"use strict";e.exports=n},259:e=>{"use strict";e.exports=o},970:()=>{}},a={},function e(t){var r=a[t];if(void 0!==r)return r.exports;var n=a[t]={exports:{}};return i[t].call(n.exports,n,n.exports,e),n.exports}(920);var i,a}));
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
|
3
|
+
* nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* Tivio Bundle downloader service.
|
7
|
+
* This package knows internal structure of Tivio Bundle and
|
8
|
+
* is responsible for life-cycle control of the bundle.
|
9
|
+
*/
|
10
|
+
import { InternalConf } from '../conf';
|
11
|
+
import { Conf } from '../types';
|
12
|
+
import { Settings } from './settings';
|
13
|
+
import type { ExposedApi } from '../api.types';
|
14
|
+
export declare type RemoteProviderProps = {
|
15
|
+
language?: string;
|
16
|
+
};
|
17
|
+
export declare type TivioBundle = {
|
18
|
+
init: (config: Conf) => void | Promise<void>;
|
19
|
+
setUser: (userId: string, payload: unknown, additionalUserData?: unknown) => void;
|
20
|
+
} & ExposedApi;
|
21
|
+
export declare type RemoteBundleState = {
|
22
|
+
state: 'loading' | 'error' | 'ready';
|
23
|
+
error: string | null;
|
24
|
+
conf: InternalConf;
|
25
|
+
settings: Settings;
|
26
|
+
} & Partial<ExposedApi>;
|
27
|
+
export declare type Api = RemoteBundleState;
|
28
|
+
export declare const fetchResolver: (conf: InternalConf) => Promise<string>;
|
29
|
+
/**
|
30
|
+
* Fetch & load CommonJS remote module.
|
31
|
+
*/
|
32
|
+
export declare const createRemotePackageLoader: () => (conf: InternalConf) => Promise<TivioBundle>;
|
33
|
+
export declare const createTivio: () => (conf: Conf) => Promise<RemoteBundleState>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
|
3
|
+
* nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
4
|
+
*/
|
5
|
+
/// <reference types="node" />
|
6
|
+
import firebase from 'firebase/app';
|
7
|
+
import 'firebase/auth';
|
8
|
+
import 'firebase/firestore';
|
9
|
+
import * as mobx from 'mobx';
|
10
|
+
import * as timers from 'timers';
|
11
|
+
export declare type SharedDependency = typeof mobx | typeof firebase | typeof timers | null;
|
12
|
+
export declare const resolveShared: (name: string) => SharedDependency;
|
@@ -0,0 +1 @@
|
|
1
|
+
import '../setupTests';
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
|
3
|
+
* nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
4
|
+
*/
|
5
|
+
export declare type LoggerArgs = any[];
|
6
|
+
export interface Logger {
|
7
|
+
/** important messages */
|
8
|
+
warn(...data: LoggerArgs): void;
|
9
|
+
/** errors */
|
10
|
+
error(...data: LoggerArgs): void;
|
11
|
+
/** critical errors */
|
12
|
+
exception(...data: LoggerArgs): void;
|
13
|
+
/** metrics */
|
14
|
+
info(...data: LoggerArgs): void;
|
15
|
+
/** non-production messages */
|
16
|
+
debug(...data: LoggerArgs): void;
|
17
|
+
}
|
18
|
+
export declare type LoggerConf = {
|
19
|
+
isConsoleEnabled: boolean;
|
20
|
+
isSentryEnabled?: boolean;
|
21
|
+
};
|
22
|
+
declare type LogLevel = 'warn' | 'error' | 'info' | 'debug';
|
23
|
+
export declare type Severity = LogLevel | 'exception';
|
24
|
+
/**
|
25
|
+
* Factory
|
26
|
+
**/
|
27
|
+
export declare const createLogger: (conf: LoggerConf) => Logger;
|
28
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
import '../setupTests';
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
|
3
|
+
* nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* The settings can be called before Tivio is loaded.
|
7
|
+
* So this package is responsible for settings from the beginning of the life cycle.
|
8
|
+
*/
|
9
|
+
import { InternalConf } from '../conf';
|
10
|
+
export declare type Settings = {
|
11
|
+
onSetUser: (handler: (userId: string, userPayload: unknown) => void) => void;
|
12
|
+
setUser: (userId: string, userPayload: unknown) => void;
|
13
|
+
};
|
14
|
+
export declare const createSettings: (conf: InternalConf) => {
|
15
|
+
onSetUser: (handler: (userId: string, userPayload: unknown) => void) => void;
|
16
|
+
setUser: (userId: string, userPayload: unknown) => void;
|
17
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export declare const fetch: import("jest-fetch-mock").FetchMock;
|
2
|
+
export declare const loggerMock: {
|
3
|
+
error: {
|
4
|
+
(...data: any[]): void;
|
5
|
+
(message?: any, ...optionalParams: any[]): void;
|
6
|
+
};
|
7
|
+
info: {
|
8
|
+
(...data: any[]): void;
|
9
|
+
(message?: any, ...optionalParams: any[]): void;
|
10
|
+
};
|
11
|
+
warn: {
|
12
|
+
(...data: any[]): void;
|
13
|
+
(message?: any, ...optionalParams: any[]): void;
|
14
|
+
};
|
15
|
+
debug: {
|
16
|
+
(...data: any[]): void;
|
17
|
+
(message?: any, ...optionalParams: any[]): void;
|
18
|
+
};
|
19
|
+
exception: (error: any) => never;
|
20
|
+
};
|
package/dist/types.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2021, nangu.TV, a.s. All rights reserved.
|
3
|
+
* nangu.TV, a.s PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
|
4
|
+
*/
|
5
|
+
/**
|
6
|
+
* Export public client side API
|
7
|
+
*/
|
8
|
+
import { InternalConf } from './conf';
|
9
|
+
export declare type Conf = Pick<InternalConf, 'secret' | 'logger' | 'language'>;
|
10
|
+
export declare type Empty = Promise<void> | void;
|
11
|
+
export declare type Disposer = () => void;
|
package/package.json
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
{
|
2
|
+
"name": "@tivio/sdk-js",
|
3
|
+
"version": "1.0.0-alpha",
|
4
|
+
"main": "dist/index.js",
|
5
|
+
"typings": "dist/index.d.ts",
|
6
|
+
"source": "src/index.ts",
|
7
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
8
|
+
"publishConfig": {
|
9
|
+
"access": "public"
|
10
|
+
},
|
11
|
+
"scripts": {
|
12
|
+
"build": "yarn run clean && webpack --config=webpack.config.prod.js",
|
13
|
+
"dev": "yarn run clean && webpack --config=webpack.config.dev.js",
|
14
|
+
"test": "jest --config=./jest.config.js --coverage",
|
15
|
+
"start": "webpack -w",
|
16
|
+
"clean": "rm -rf dist",
|
17
|
+
"prepublishOnly": "yarn && rm -rf ./dist && yarn run build"
|
18
|
+
},
|
19
|
+
"dependencies": {
|
20
|
+
"@sentry/browser": "^6.1.0",
|
21
|
+
"firebase": "^8.2.3",
|
22
|
+
"mobx": "^6.0.4"
|
23
|
+
},
|
24
|
+
"devDependencies": {
|
25
|
+
"@tivio/common": "*",
|
26
|
+
"@types/jest": "^26.0.23",
|
27
|
+
"@types/node": "^14.14.21",
|
28
|
+
"@types/node-fetch": "^2.5.8",
|
29
|
+
"@typescript-eslint/eslint-plugin": "^4.14.0",
|
30
|
+
"@typescript-eslint/parser": "^4.14.2",
|
31
|
+
"dotenv": "^8.2.0",
|
32
|
+
"dotenv-webpack": "^7.0.3",
|
33
|
+
"eslint": "^7.19.0",
|
34
|
+
"firebase": "^8.2.3",
|
35
|
+
"jest": "^26.6.3",
|
36
|
+
"jest-cli": "^26.6.3",
|
37
|
+
"jest-fetch-mock": "^3.0.3",
|
38
|
+
"mobx": "^6.0.4",
|
39
|
+
"node-fetch": "^2.6.1",
|
40
|
+
"stream-browserify": "^3.0.0",
|
41
|
+
"timers-browserify": "^2.0.12",
|
42
|
+
"ts-jest": "^26.4.4",
|
43
|
+
"typescript": "^4.0.2",
|
44
|
+
"webpack": "^5.15.0",
|
45
|
+
"webpack-cli": "^4.4.0",
|
46
|
+
"webpack-merge": "^5.7.3"
|
47
|
+
}
|
48
|
+
}
|