This repository was archived by the owner on Jan 15, 2026. It is now read-only.
forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentities.ts
More file actions
56 lines (54 loc) · 2.16 KB
/
Copy pathentities.ts
File metadata and controls
56 lines (54 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { NETWORK_STATE, READY_STATE } from './constants';
import { MediaElement, VideoElement } from './types';
import {
dataUrlHandler,
getUriFileExtension,
isFullScreen,
textTrackListToJson,
timeRangesToObjectArray,
} from './helperFunctions';
import { SelfDescribingJson } from '@snowplow/tracker-core';
export function buildHTMLMediaElementEntity(el: HTMLAudioElement | HTMLVideoElement): SelfDescribingJson {
const data: MediaElement = {
// htmlId is a required property in the schema, but may not be present if
// the user provided the element themselves
htmlId: el.id || '',
mediaType: el.tagName as MediaElement['mediaType'],
autoPlay: el.autoplay,
buffered: timeRangesToObjectArray(el.buffered),
controls: el.controls,
currentSrc: el.currentSrc || el.src,
defaultMuted: el.defaultMuted || false,
defaultPlaybackRate: el.defaultPlaybackRate,
error: el.error ? { code: el.error?.code, message: el.error?.message } : null,
networkState: NETWORK_STATE[el.networkState] as MediaElement['networkState'],
preload: el.preload,
readyState: READY_STATE[el.readyState] as MediaElement['readyState'],
seekable: timeRangesToObjectArray(el.seekable),
seeking: el.seeking,
src: dataUrlHandler(el.src || el.currentSrc),
textTracks: textTrackListToJson(el.textTracks),
fileExtension: getUriFileExtension(el.currentSrc),
fullscreen: isFullScreen(el),
pictureInPicture: document.pictureInPictureElement === el,
};
if (el.disableRemotePlayback) data.disableRemotePlayback = el.disableRemotePlayback;
if (el.crossOrigin) data.crossOrigin = el.crossOrigin;
return {
schema: 'iglu:org.whatwg/media_element/jsonschema/1-0-0',
data,
};
}
export function buildHTMLVideoElementEntity(el: HTMLVideoElement): SelfDescribingJson {
const data: VideoElement = {
poster: el.poster,
videoHeight: el.videoHeight,
videoWidth: el.videoWidth,
};
if (el.hasAttribute('autopictureinpicture')) data.autoPictureInPicture = true;
if (el.disablePictureInPicture) data.disablePictureInPicture = el.disablePictureInPicture;
return {
schema: 'iglu:org.whatwg/video_element/jsonschema/1-0-0',
data,
};
}