@rixl/media-core 1.0.1 → 1.1.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.
Files changed (173) hide show
  1. package/README.md +74 -84
  2. package/dist/chunks/B-QvSqjj.js +1 -0
  3. package/dist/chunks/B2DDE32u.js +1 -0
  4. package/dist/chunks/BZFoe94X.js +1 -0
  5. package/dist/chunks/DMkwQjgA.js +1 -0
  6. package/dist/index.d.ts +2005 -82
  7. package/dist/index.js +6 -73
  8. package/package.json +13 -6
  9. package/dist/api/analytics.d.ts +0 -16
  10. package/dist/api/analytics.js +0 -227
  11. package/dist/api/feed.js +0 -52
  12. package/dist/api/heatmap.d.ts +0 -6
  13. package/dist/api/heatmap.js +0 -28
  14. package/dist/api/hot-segments.d.ts +0 -7
  15. package/dist/api/hot-segments.js +0 -20
  16. package/dist/api/image.js +0 -11
  17. package/dist/api/rixl-client.d.ts +0 -3
  18. package/dist/api/rixl-client.js +0 -14
  19. package/dist/api/upload.d.ts +0 -76
  20. package/dist/api/upload.js +0 -150
  21. package/dist/api/video.js +0 -11
  22. package/dist/lib/analytics-builders.d.ts +0 -59
  23. package/dist/lib/analytics-builders.js +0 -88
  24. package/dist/lib/analytics-initialize.d.ts +0 -1
  25. package/dist/lib/analytics-initialize.js +0 -59
  26. package/dist/lib/analytics-utils.d.ts +0 -43
  27. package/dist/lib/analytics-utils.js +0 -85
  28. package/dist/lib/analytics-wire.js +0 -153
  29. package/dist/lib/buffer-progress.d.ts +0 -20
  30. package/dist/lib/buffer-progress.js +0 -37
  31. package/dist/lib/caption-styles.d.ts +0 -20
  32. package/dist/lib/caption-styles.js +0 -56
  33. package/dist/lib/caption-utils.d.ts +0 -80
  34. package/dist/lib/caption-utils.js +0 -111
  35. package/dist/lib/chapter-utils.d.ts +0 -102
  36. package/dist/lib/chapter-utils.js +0 -147
  37. package/dist/lib/click-disambiguation.d.ts +0 -44
  38. package/dist/lib/click-disambiguation.js +0 -80
  39. package/dist/lib/click-outside.d.ts +0 -68
  40. package/dist/lib/click-outside.js +0 -64
  41. package/dist/lib/colors.d.ts +0 -6
  42. package/dist/lib/colors.js +0 -16
  43. package/dist/lib/content-analytics.d.ts +0 -27
  44. package/dist/lib/content-analytics.js +0 -38
  45. package/dist/lib/environment-effects.d.ts +0 -89
  46. package/dist/lib/environment-effects.js +0 -139
  47. package/dist/lib/feed-autoscroll.d.ts +0 -10
  48. package/dist/lib/feed-autoscroll.js +0 -13
  49. package/dist/lib/feed-container-height.d.ts +0 -7
  50. package/dist/lib/feed-container-height.js +0 -11
  51. package/dist/lib/feed-description-overflow.d.ts +0 -1
  52. package/dist/lib/feed-description-overflow.js +0 -9
  53. package/dist/lib/feed-dwell.d.ts +0 -2
  54. package/dist/lib/feed-dwell.js +0 -8
  55. package/dist/lib/feed-loop.d.ts +0 -10
  56. package/dist/lib/feed-loop.js +0 -21
  57. package/dist/lib/feed-scroll.d.ts +0 -11
  58. package/dist/lib/feed-scroll.js +0 -19
  59. package/dist/lib/feed-transforms.d.ts +0 -5
  60. package/dist/lib/feed-transforms.js +0 -30
  61. package/dist/lib/filter-undefined.js +0 -11
  62. package/dist/lib/fullscreen-utils.d.ts +0 -1
  63. package/dist/lib/fullscreen-utils.js +0 -7
  64. package/dist/lib/hls-buffer-flush.js +0 -46
  65. package/dist/lib/hls-error-recovery.d.ts +0 -35
  66. package/dist/lib/hls-error-recovery.js +0 -75
  67. package/dist/lib/hls-event-handlers.js +0 -61
  68. package/dist/lib/hls-loader.js +0 -23
  69. package/dist/lib/hls-setup.d.ts +0 -72
  70. package/dist/lib/hls-setup.js +0 -144
  71. package/dist/lib/hls-utils.d.ts +0 -31
  72. package/dist/lib/hls-utils.js +0 -34
  73. package/dist/lib/image-render.d.ts +0 -29
  74. package/dist/lib/image-render.js +0 -63
  75. package/dist/lib/keyboard-config.d.ts +0 -66
  76. package/dist/lib/keyboard-config.js +0 -127
  77. package/dist/lib/keyboard-utils.d.ts +0 -4
  78. package/dist/lib/keyboard-utils.js +0 -11
  79. package/dist/lib/lifecycle-effects.d.ts +0 -67
  80. package/dist/lib/lifecycle-effects.js +0 -78
  81. package/dist/lib/loading-debounce.d.ts +0 -26
  82. package/dist/lib/loading-debounce.js +0 -38
  83. package/dist/lib/numbers.d.ts +0 -6
  84. package/dist/lib/numbers.js +0 -36
  85. package/dist/lib/pip-utils.d.ts +0 -16
  86. package/dist/lib/pip-utils.js +0 -32
  87. package/dist/lib/playback-handlers.d.ts +0 -33
  88. package/dist/lib/playback-handlers.js +0 -51
  89. package/dist/lib/playback-slider.d.ts +0 -23
  90. package/dist/lib/playback-slider.js +0 -24
  91. package/dist/lib/player-labels.d.ts +0 -23
  92. package/dist/lib/player-labels.js +0 -132
  93. package/dist/lib/player-menu-labels.d.ts +0 -80
  94. package/dist/lib/player-menu-labels.js +0 -829
  95. package/dist/lib/player-ui-actions.d.ts +0 -10
  96. package/dist/lib/player-ui-actions.js +0 -58
  97. package/dist/lib/progress-fraction.d.ts +0 -11
  98. package/dist/lib/progress-fraction.js +0 -20
  99. package/dist/lib/progress-persist.d.ts +0 -28
  100. package/dist/lib/progress-persist.js +0 -54
  101. package/dist/lib/segment-analytics.d.ts +0 -20
  102. package/dist/lib/segment-analytics.js +0 -29
  103. package/dist/lib/subtitle-logic.d.ts +0 -31
  104. package/dist/lib/subtitle-logic.js +0 -75
  105. package/dist/lib/subtitle-utils.d.ts +0 -16
  106. package/dist/lib/subtitle-utils.js +0 -37
  107. package/dist/lib/time.d.ts +0 -1
  108. package/dist/lib/time.js +0 -17
  109. package/dist/lib/track-persistence.d.ts +0 -4
  110. package/dist/lib/track-persistence.js +0 -35
  111. package/dist/lib/video-preload-config.d.ts +0 -34
  112. package/dist/lib/video-preload-config.js +0 -41
  113. package/dist/lib/video-spinner.d.ts +0 -25
  114. package/dist/lib/video-spinner.js +0 -35
  115. package/dist/lib/video-stats.d.ts +0 -28
  116. package/dist/lib/video-stats.js +0 -44
  117. package/dist/lib/volume-utils.d.ts +0 -59
  118. package/dist/lib/volume-utils.js +0 -55
  119. package/dist/progressbar.d.ts +0 -10
  120. package/dist/progressbar.js +0 -123
  121. package/dist/store/analytics-context-store.d.ts +0 -4
  122. package/dist/store/analytics-context-store.js +0 -13
  123. package/dist/store/analytics-device-store.d.ts +0 -8
  124. package/dist/store/analytics-device-store.js +0 -44
  125. package/dist/store/analytics-session-store.d.ts +0 -8
  126. package/dist/store/analytics-session-store.js +0 -40
  127. package/dist/store/analytics-store.d.ts +0 -30
  128. package/dist/store/analytics-store.js +0 -88
  129. package/dist/store/controls-store.d.ts +0 -16
  130. package/dist/store/controls-store.js +0 -53
  131. package/dist/store/feed-cache-store.d.ts +0 -24
  132. package/dist/store/feed-cache-store.js +0 -165
  133. package/dist/store/feed-interaction-store.d.ts +0 -17
  134. package/dist/store/feed-interaction-store.js +0 -32
  135. package/dist/store/feed-store.d.ts +0 -16
  136. package/dist/store/feed-store.js +0 -38
  137. package/dist/store/generic-store.js +0 -24
  138. package/dist/store/image-store.d.ts +0 -2
  139. package/dist/store/image-store.js +0 -8
  140. package/dist/store/player-container-element-store.d.ts +0 -10
  141. package/dist/store/player-container-element-store.js +0 -38
  142. package/dist/store/player-global-actions.js +0 -53
  143. package/dist/store/player-media-element-store.d.ts +0 -10
  144. package/dist/store/player-media-element-store.js +0 -38
  145. package/dist/store/player-store-actions.js +0 -197
  146. package/dist/store/player-store.d.ts +0 -94
  147. package/dist/store/player-store.js +0 -127
  148. package/dist/store/player-track-actions.js +0 -44
  149. package/dist/store/postStore.d.ts +0 -20
  150. package/dist/store/postStore.js +0 -112
  151. package/dist/store/settings/constants.d.ts +0 -15
  152. package/dist/store/settings/constants.js +0 -47
  153. package/dist/store/settings/defaults.d.ts +0 -2
  154. package/dist/store/settings/defaults.js +0 -24
  155. package/dist/store/settings/storage.d.ts +0 -3
  156. package/dist/store/settings/storage.js +0 -28
  157. package/dist/store/settings/store.d.ts +0 -32
  158. package/dist/store/settings/store.js +0 -59
  159. package/dist/store/settings/types.d.ts +0 -27
  160. package/dist/store/settings/validation.d.ts +0 -7
  161. package/dist/store/settings/validation.js +0 -55
  162. package/dist/store/settings-menu-store.d.ts +0 -19
  163. package/dist/store/settings-menu-store.js +0 -30
  164. package/dist/store/video-store.d.ts +0 -2
  165. package/dist/store/video-store.js +0 -8
  166. package/dist/types/analytics.d.ts +0 -113
  167. package/dist/types/feed.d.ts +0 -21
  168. package/dist/types/file.d.ts +0 -12
  169. package/dist/types/heatmap.d.ts +0 -5
  170. package/dist/types/hot-segments.d.ts +0 -9
  171. package/dist/types/image.d.ts +0 -9
  172. package/dist/types/uuid.d.ts +0 -1
  173. package/dist/types/video.d.ts +0 -22
@@ -1,3 +0,0 @@
1
- import { AuthConfig, ConnectConfig, client } from "@rixl/sdk";
2
- declare function connect$1(config: ConnectConfig): Promise<string | undefined>;
3
- export { type AuthConfig, type ConnectConfig, connect$1 as connect };
@@ -1,14 +0,0 @@
1
- import { initializeAnalyticsContext } from "../lib/analytics-initialize.js";
2
- import { client, connect } from "@rixl/sdk";
3
-
4
- // src/api/rixl-client.ts
5
- function getRixlClient() {
6
- return client;
7
- }
8
- async function connect$1(config) {
9
- const result = await connect(config);
10
- initializeAnalyticsContext();
11
- return result;
12
- }
13
-
14
- export { connect$1 as connect, getRixlClient };
@@ -1,76 +0,0 @@
1
- export interface CreateImageUploadOptions {
2
- projectId: string;
3
- orgId?: string;
4
- name: string;
5
- }
6
- export interface ImageUploadResult {
7
- imageId: string;
8
- uploadUrl: string;
9
- }
10
- export declare function createImageUpload(options: CreateImageUploadOptions): Promise<ImageUploadResult>;
11
- export declare function uploadImage(file: Blob | Uint8Array, options: CreateImageUploadOptions): Promise<ImageUploadResult>;
12
- export interface CreateVideoUploadOptions {
13
- projectId: string;
14
- orgId?: string;
15
- name: string;
16
- videoQuality?: string;
17
- }
18
- export interface VideoUploadResult {
19
- videoId: string;
20
- posterId: string;
21
- videoUploadUrl: string;
22
- posterUploadUrl: string;
23
- }
24
- export declare function createVideoUpload(options: CreateVideoUploadOptions): Promise<VideoUploadResult>;
25
- export declare function uploadVideo(videoFile: Blob | Uint8Array, posterFile: Blob | Uint8Array, options: CreateVideoUploadOptions): Promise<VideoUploadResult>;
26
- export interface AudioTrackUploadItem {
27
- languageCode: string;
28
- label?: string;
29
- fileName: string;
30
- format: string;
31
- size?: number;
32
- }
33
- export interface AudioTrackUploadTarget {
34
- id: string;
35
- languageCode?: string;
36
- uploadUrl?: string;
37
- }
38
- export interface AudioTrackUploadResult {
39
- targets: AudioTrackUploadTarget[];
40
- }
41
- export declare function createAudioTrackUpload(projectId: string, videoId: string, items: AudioTrackUploadItem[]): Promise<AudioTrackUploadResult>;
42
- export interface SubtitleUploadItem {
43
- languageCode: string;
44
- label?: string;
45
- fileName: string;
46
- format: string;
47
- size?: number;
48
- }
49
- export interface SubtitleUploadTarget {
50
- id: string;
51
- languageCode?: string;
52
- uploadUrl?: string;
53
- }
54
- export interface SubtitleUploadResult {
55
- targets: SubtitleUploadTarget[];
56
- }
57
- export declare function createSubtitleUpload(projectId: string, videoId: string, items: SubtitleUploadItem[]): Promise<SubtitleUploadResult>;
58
- export interface CreatePostUploadOptions {
59
- projectId: string;
60
- feedId: string;
61
- orgId?: string;
62
- creatorId: string;
63
- description?: string;
64
- contentType: string;
65
- fileName: string;
66
- videoQuality?: string;
67
- }
68
- export interface PostUploadResult {
69
- postId: string;
70
- contentId: string;
71
- posterId: string;
72
- contentUploadUrl: string;
73
- posterUploadUrl: string;
74
- }
75
- export declare function uploadPost(contentFile: Blob | Uint8Array, posterFile: Blob | Uint8Array, options: CreatePostUploadOptions): Promise<PostUploadResult>;
76
- export declare function createPostUpload(options: CreatePostUploadOptions): Promise<PostUploadResult>;
@@ -1,150 +0,0 @@
1
- import { getRixlClient } from "./rixl-client.js";
2
- import { imagesV1ImageServiceCreateImageUpload, postsV1PostServiceCreatePostUpload, videosV1AudioTrackServiceCreateAudioTrackUpload, videosV1SubtitleServiceCreateSubtitleUpload, videosV1VideoServiceCreateVideoUpload } from "@rixl/sdk";
3
-
4
- // src/api/upload.ts
5
- async function putFileToPresignedUrl(url, file) {
6
- const res = await fetch(url, {
7
- method: "PUT",
8
- body: file
9
- });
10
- if (!res.ok) throw new Error(`PUT to presigned URL failed: ${res.status} ${res.statusText}`);
11
- }
12
- async function createImageUpload(options) {
13
- const client = getRixlClient();
14
- const result = await imagesV1ImageServiceCreateImageUpload({
15
- client,
16
- path: { project_id: options.projectId },
17
- body: {
18
- project_id: options.projectId,
19
- org_id: options.orgId,
20
- name: options.name
21
- }
22
- });
23
- if (result.error) throw result.error;
24
- const d = result.data;
25
- return {
26
- imageId: d.image_id,
27
- uploadUrl: d.upload_url
28
- };
29
- }
30
- async function uploadImage(file, options) {
31
- const upload = await createImageUpload(options);
32
- await putFileToPresignedUrl(upload.uploadUrl, file);
33
- return upload;
34
- }
35
- async function createVideoUpload(options) {
36
- const client = getRixlClient();
37
- const result = await videosV1VideoServiceCreateVideoUpload({
38
- client,
39
- path: { project_id: options.projectId },
40
- body: {
41
- project_id: options.projectId,
42
- org_id: options.orgId,
43
- name: options.name,
44
- video_quality: options.videoQuality
45
- }
46
- });
47
- if (result.error) throw result.error;
48
- const d = result.data;
49
- return {
50
- videoId: d.video_id,
51
- posterId: d.poster_id,
52
- videoUploadUrl: d.video_upload_url,
53
- posterUploadUrl: d.poster_upload_url
54
- };
55
- }
56
- async function uploadVideo(videoFile, posterFile, options) {
57
- const upload = await createVideoUpload(options);
58
- await Promise.all([putFileToPresignedUrl(upload.videoUploadUrl, videoFile), putFileToPresignedUrl(upload.posterUploadUrl, posterFile)]);
59
- return upload;
60
- }
61
- async function createAudioTrackUpload(projectId, videoId, items) {
62
- const client = getRixlClient();
63
- const result = await videosV1AudioTrackServiceCreateAudioTrackUpload({
64
- client,
65
- path: {
66
- project_id: projectId,
67
- video_id: videoId
68
- },
69
- body: {
70
- project_id: projectId,
71
- video_id: videoId,
72
- items: items.map((item) => ({
73
- language_code: item.languageCode,
74
- label: item.label,
75
- file_name: item.fileName,
76
- format: item.format,
77
- ...item.size !== void 0 ? { size: item.size } : {}
78
- }))
79
- }
80
- });
81
- if (result.error) throw result.error;
82
- return { targets: (result.data.targets ?? []).map((t) => ({
83
- id: t.id,
84
- languageCode: t.language_code,
85
- uploadUrl: t.upload_url
86
- })) };
87
- }
88
- async function createSubtitleUpload(projectId, videoId, items) {
89
- const client = getRixlClient();
90
- const result = await videosV1SubtitleServiceCreateSubtitleUpload({
91
- client,
92
- path: {
93
- project_id: projectId,
94
- video_id: videoId
95
- },
96
- body: {
97
- project_id: projectId,
98
- video_id: videoId,
99
- items: items.map((item) => ({
100
- language_code: item.languageCode,
101
- label: item.label,
102
- file_name: item.fileName,
103
- format: item.format,
104
- ...item.size !== void 0 ? { size: item.size } : {}
105
- }))
106
- }
107
- });
108
- if (result.error) throw result.error;
109
- return { targets: (result.data.targets ?? []).map((t) => ({
110
- id: t.id,
111
- languageCode: t.language_code,
112
- uploadUrl: t.upload_url
113
- })) };
114
- }
115
- async function uploadPost(contentFile, posterFile, options) {
116
- const upload = await createPostUpload(options);
117
- await Promise.all([putFileToPresignedUrl(upload.contentUploadUrl, contentFile), putFileToPresignedUrl(upload.posterUploadUrl, posterFile)]);
118
- return upload;
119
- }
120
- async function createPostUpload(options) {
121
- const client = getRixlClient();
122
- const result = await postsV1PostServiceCreatePostUpload({
123
- client,
124
- path: {
125
- project_id: options.projectId,
126
- feed_id: options.feedId
127
- },
128
- body: {
129
- project_id: options.projectId,
130
- feed_id: options.feedId,
131
- org_id: options.orgId,
132
- creator_id: options.creatorId,
133
- description: options.description,
134
- content_type: options.contentType,
135
- file_name: options.fileName,
136
- video_quality: options.videoQuality
137
- }
138
- });
139
- if (result.error) throw result.error;
140
- const d = result.data;
141
- return {
142
- postId: d.post_id,
143
- contentId: d.content_id,
144
- posterId: d.poster_id,
145
- contentUploadUrl: d.content_upload_url,
146
- posterUploadUrl: d.poster_upload_url
147
- };
148
- }
149
-
150
- export { createAudioTrackUpload, createImageUpload, createPostUpload, createSubtitleUpload, createVideoUpload, uploadImage, uploadPost, uploadVideo };
package/dist/api/video.js DELETED
@@ -1,11 +0,0 @@
1
- import { videosV1VideoServiceGetVideo } from "@rixl/sdk";
2
-
3
- // src/api/video.ts
4
- const fetchVideo = async (videoId) => {
5
- const { data, error, response } = await videosV1VideoServiceGetVideo({ path: { video_id: videoId } });
6
- if (error) throw new Error(`HTTP error! status: ${response?.status ?? 500}`);
7
- if (!data?.video) throw new Error(`HTTP error! status: 404`);
8
- return data.video;
9
- };
10
-
11
- export { fetchVideo };
@@ -1,59 +0,0 @@
1
- export interface BuildEngagementParams {
2
- engagementType: string;
3
- resourceType?: string;
4
- resourceId?: string;
5
- page?: string;
6
- commentText?: string;
7
- sharePlatform?: string;
8
- country?: string;
9
- deviceType?: string;
10
- sessionId?: string;
11
- }
12
- export interface BuildInteractionParams {
13
- interactionType: string;
14
- elementType?: string;
15
- elementId?: string;
16
- sessionId?: string;
17
- page?: string;
18
- pageUrl?: string;
19
- scrollDepth?: number;
20
- searchQuery?: string;
21
- clickX?: number;
22
- clickY?: number;
23
- deviceType?: string;
24
- browser?: string;
25
- resourceId?: string;
26
- resourceType?: string;
27
- feedId?: string;
28
- postId?: string;
29
- contentId?: string;
30
- }
31
- export interface BuildErrorParams {
32
- errorType: string;
33
- errorCode?: string;
34
- errorMessage?: string;
35
- stackTrace?: string;
36
- resourceType?: string;
37
- resourceId?: string;
38
- endpoint?: string;
39
- sessionId?: string;
40
- deviceType?: string;
41
- browser?: string;
42
- os?: string;
43
- }
44
- export interface BuildSessionStartParams {
45
- browser?: string;
46
- language?: string;
47
- screenResolution?: string;
48
- platform?: string;
49
- tgPlatform?: string;
50
- tgVersion?: string;
51
- timezone?: string;
52
- timezoneOffset?: number;
53
- colorDepth?: number;
54
- touchSupport?: boolean;
55
- country?: string;
56
- userId?: string;
57
- utmSource?: string;
58
- utmCampaign?: string;
59
- }
@@ -1,88 +0,0 @@
1
- import { filterUndefined } from "./filter-undefined.js";
2
-
3
- // src/lib/analytics-builders.ts
4
- function buildEngagementEvent(params) {
5
- return {
6
- _type: "engagement",
7
- timestamp: Date.now() / 1e3,
8
- engagement_type: params.engagementType,
9
- ...filterUndefined({
10
- resource_type: params.resourceType,
11
- resource_id: params.resourceId,
12
- page: params.page,
13
- comment_text: params.commentText,
14
- share_platform: params.sharePlatform,
15
- country: params.country,
16
- device_type: params.deviceType,
17
- session_id: params.sessionId
18
- })
19
- };
20
- }
21
- function buildInteractionEvent(params) {
22
- return {
23
- _type: "interaction",
24
- timestamp: Date.now() / 1e3,
25
- interaction_type: params.interactionType,
26
- ...filterUndefined({
27
- element_type: params.elementType,
28
- element_id: params.elementId,
29
- session_id: params.sessionId,
30
- page: params.page,
31
- page_url: params.pageUrl,
32
- scroll_depth: params.scrollDepth,
33
- search_query: params.searchQuery,
34
- click_x: params.clickX,
35
- click_y: params.clickY,
36
- device_type: params.deviceType,
37
- browser: params.browser,
38
- resource_id: params.resourceId,
39
- resource_type: params.resourceType,
40
- feed_id: params.feedId,
41
- post_id: params.postId,
42
- content_id: params.contentId
43
- })
44
- };
45
- }
46
- function buildErrorEvent(params) {
47
- return {
48
- _type: "error",
49
- timestamp: Date.now() / 1e3,
50
- error_type: params.errorType,
51
- ...filterUndefined({
52
- error_code: params.errorCode,
53
- error_message: params.errorMessage,
54
- stack_trace: params.stackTrace,
55
- resource_type: params.resourceType,
56
- resource_id: params.resourceId,
57
- endpoint: params.endpoint,
58
- session_id: params.sessionId,
59
- device_type: params.deviceType,
60
- browser: params.browser,
61
- os: params.os
62
- })
63
- };
64
- }
65
- function buildSessionStartEvent(params) {
66
- return {
67
- _type: "session_start",
68
- timestamp: Date.now() / 1e3,
69
- ...filterUndefined({
70
- utm_source: params.utmSource,
71
- utm_campaign: params.utmCampaign,
72
- browser: params.browser,
73
- language: params.language,
74
- screen_resolution: params.screenResolution,
75
- platform: params.platform,
76
- tg_platform: params.tgPlatform,
77
- tg_version: params.tgVersion,
78
- timezone: params.timezone,
79
- timezone_offset: params.timezoneOffset,
80
- color_depth: params.colorDepth,
81
- touch_support: params.touchSupport,
82
- country: params.country,
83
- user_id: params.userId
84
- })
85
- };
86
- }
87
-
88
- export { buildEngagementEvent, buildErrorEvent, buildInteractionEvent, buildSessionStartEvent };
@@ -1 +0,0 @@
1
- export declare function initializeAnalyticsContext(): void;
@@ -1,59 +0,0 @@
1
- import { setAnalyticsContext } from "../store/analytics-context-store.js";
2
- import { getOrCreateDeviceId } from "../store/analytics-device-store.js";
3
- import { resetSession } from "../store/analytics-session-store.js";
4
- import { user } from "@rixl/sdk";
5
-
6
- // src/lib/analytics-initialize.ts
7
- function getDeviceType() {
8
- const ua = typeof navigator !== "undefined" ? navigator.userAgent : "";
9
- if (!ua) return "desktop";
10
- if (/iPad|Tablet|PlayBook|Silk|Android(?!.*Mobile)/i.test(ua)) return "tablet";
11
- if (/Mobile|Android|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(ua)) return "mobile";
12
- return "desktop";
13
- }
14
- function getScreenResolution() {
15
- if (typeof screen === "undefined") return;
16
- return `${screen.width}x${screen.height}`;
17
- }
18
- function getTimezone() {
19
- if (typeof Intl === "undefined") return;
20
- try {
21
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
22
- } catch {
23
- return;
24
- }
25
- }
26
- function getTimezoneOffset() {
27
- return (/* @__PURE__ */ new Date()).getTimezoneOffset() * -1;
28
- }
29
- function getTouchSupport() {
30
- return typeof window !== "undefined" && "ontouchstart" in window;
31
- }
32
- function readEnvironment() {
33
- const nav = typeof navigator !== "undefined" ? navigator : void 0;
34
- return {
35
- device: getDeviceType(),
36
- os: nav?.platform,
37
- language: nav?.language,
38
- browser: nav?.userAgent,
39
- screen_resolution: getScreenResolution(),
40
- platform: nav?.platform,
41
- timezone: getTimezone(),
42
- timezone_offset: getTimezoneOffset(),
43
- color_depth: typeof screen !== "undefined" ? screen.colorDepth : void 0,
44
- touch_support: getTouchSupport()
45
- };
46
- }
47
- function updateFromUser(u) {
48
- const update = { user_id: u?.id };
49
- if (u?.language_code) update.language = u.language_code;
50
- setAnalyticsContext(update);
51
- }
52
- function initializeAnalyticsContext() {
53
- getOrCreateDeviceId();
54
- resetSession();
55
- setAnalyticsContext(readEnvironment());
56
- user.subscribe(updateFromUser);
57
- }
58
-
59
- export { initializeAnalyticsContext };
@@ -1,43 +0,0 @@
1
- import { ContentType, ContentViewEvent, Page, Segment, ViewType } from "../types/analytics.js";
2
- export interface BuildEventParams {
3
- contentId: string;
4
- contentType: ContentType;
5
- viewType: ViewType;
6
- watchDurationMs: number;
7
- page: Page;
8
- feedId?: string;
9
- postId?: string;
10
- videoPositionMs?: number;
11
- videoTotalDurationMs?: number;
12
- segments?: Segment[];
13
- }
14
- /**
15
- * Build a content view event for analytics
16
- * Pure function that constructs the event payload
17
- */
18
- export declare function buildContentViewEvent(params: BuildEventParams): ContentViewEvent;
19
- /**
20
- * Calculate watch duration from start time to now
21
- */
22
- export declare function calculateWatchDuration(startTimeMs: number | null): number;
23
- /**
24
- * Determine the effective page based on feedId presence
25
- */
26
- export declare function getEffectivePage(page: Page, feedId?: string): Page;
27
- /**
28
- * Check if segments should be included in the event
29
- * Only include for "watch" and "end" view types
30
- */
31
- export declare function shouldIncludeSegments(viewType: ViewType): boolean;
32
- /**
33
- * Round milliseconds for video position/duration
34
- */
35
- export declare function roundMs(ms: number): number;
36
- /**
37
- * Convert seconds to milliseconds
38
- */
39
- export declare function secondsToMs(seconds: number): number;
40
- /**
41
- * Convert milliseconds to seconds (for timestamp)
42
- */
43
- export declare function msToSeconds(ms: number): number;
@@ -1,85 +0,0 @@
1
- // src/lib/analytics-utils.ts
2
- function applyFeedContext(event, feedId, postId) {
3
- if (feedId) event.feed_id = feedId;
4
- if (postId) event.post_id = postId;
5
- }
6
- function applyVideoFields({ event, contentType, videoPositionMs, videoTotalDurationMs }) {
7
- if (contentType !== "video") return;
8
- if (videoPositionMs !== void 0) event.video_position_ms = Math.round(videoPositionMs);
9
- if (videoTotalDurationMs !== void 0) event.video_total_duration_ms = Math.round(videoTotalDurationMs);
10
- }
11
- function applySegments({ event, contentType, viewType, segments }) {
12
- if (contentType !== "video") return;
13
- if (!shouldIncludeSegments(viewType) || !segments || segments.length === 0) return;
14
- event.segments = segments;
15
- }
16
- /**
17
- * Build a content view event for analytics
18
- * Pure function that constructs the event payload
19
- */
20
- function buildContentViewEvent(params) {
21
- const { contentId, contentType, viewType, watchDurationMs, page, feedId, postId, videoPositionMs, videoTotalDurationMs, segments } = params;
22
- const event = {
23
- _type: "content_views",
24
- timestamp: Date.now() / 1e3,
25
- content_id: contentId,
26
- content_type: contentType,
27
- view_type: viewType,
28
- watch_duration_ms: watchDurationMs,
29
- page: feedId ? "feed" : page
30
- };
31
- applyFeedContext(event, feedId, postId);
32
- applyVideoFields({
33
- event,
34
- contentType,
35
- videoPositionMs,
36
- videoTotalDurationMs
37
- });
38
- applySegments({
39
- event,
40
- contentType,
41
- viewType,
42
- segments
43
- });
44
- return event;
45
- }
46
- /**
47
- * Calculate watch duration from start time to now
48
- */
49
- function calculateWatchDuration(startTimeMs) {
50
- if (startTimeMs === null) return 0;
51
- return Date.now() - startTimeMs;
52
- }
53
- /**
54
- * Determine the effective page based on feedId presence
55
- */
56
- function getEffectivePage(page, feedId) {
57
- return feedId ? "feed" : page;
58
- }
59
- /**
60
- * Check if segments should be included in the event
61
- * Only include for "watch" and "end" view types
62
- */
63
- function shouldIncludeSegments(viewType) {
64
- return viewType === "watch" || viewType === "end";
65
- }
66
- /**
67
- * Round milliseconds for video position/duration
68
- */
69
- function roundMs(ms) {
70
- return Math.round(ms);
71
- }
72
- /**
73
- * Convert seconds to milliseconds
74
- */
75
- function secondsToMs(seconds) {
76
- return seconds * 1e3;
77
- }
78
- /**
79
- * Convert milliseconds to seconds (for timestamp)
80
- */
81
- function msToSeconds(ms) {
82
- return ms / 1e3;
83
- }
84
-
85
- export { buildContentViewEvent, calculateWatchDuration, getEffectivePage, msToSeconds, roundMs, secondsToMs, shouldIncludeSegments };