raw ingredients done adding functionality
This commit is contained in:
parent
dcac5ebcc9
commit
1ce2462a93
4 changed files with 143 additions and 28 deletions
|
@ -109,3 +109,5 @@ ENABLE_UI_NOTIFICATIONS=false
|
|||
#IMAGES_ENABLED=true
|
||||
#FILES_ENABLED=true
|
||||
#MODELS_ENABLED=true
|
||||
|
||||
BRANDED_SITE=odysee
|
||||
|
|
137
ui/analytics.js
137
ui/analytics.js
|
@ -76,7 +76,114 @@ if (window.localStorage.getItem(SHARE_INTERNAL) === 'true') internalAnalyticsEna
|
|||
// if (window.localStorage.getItem(SHARE_THIRD_PARTY) === 'true') thirdPartyAnalyticsEnabled = true;
|
||||
// @endif
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
var bufferTime;
|
||||
|
||||
async function sendData(value){
|
||||
console.log(value)
|
||||
}
|
||||
|
||||
async function runSendingData(){
|
||||
await sendData('hello1234')
|
||||
await sleep(1000 * 30);
|
||||
runSendingData()
|
||||
}
|
||||
|
||||
runSendingData()
|
||||
|
||||
/**
|
||||
* Determine the mobile operating system.
|
||||
* This function returns one of 'iOS', 'Android', 'Windows Phone', or 'unknown'.
|
||||
*
|
||||
* @returns {String}
|
||||
*/
|
||||
function getMobileOperatingSystem() {
|
||||
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
|
||||
|
||||
if (/android/i.test(userAgent)) {
|
||||
return "and";
|
||||
}
|
||||
|
||||
// iOS detection from: http://stackoverflow.com/a/9039885/177710
|
||||
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
|
||||
return "ios";
|
||||
}
|
||||
|
||||
return "web";
|
||||
}
|
||||
|
||||
async function sendWatchmanData(body){
|
||||
const response = await fetch('https://watchman.na-backend.odysee.com/reports/playback', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
// fetch('https://watchman.na-backend.odysee.com/reports/playback', {
|
||||
// method: 'post',
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/json',
|
||||
// },
|
||||
// body: JSON.stringify({
|
||||
// "device": "web",
|
||||
// "protocol": "stb",
|
||||
// "duration": 1234,
|
||||
// "format": "hls",
|
||||
// "player": "sg-p2",
|
||||
// "position": 1156513664,
|
||||
// "rate": 1633176499,
|
||||
// "rebuf_count": 64944106,
|
||||
// "rebuf_duration": 32061,
|
||||
// "rel_position": 43,
|
||||
// "url": "fred",
|
||||
// "user_id": 2068464011
|
||||
// }),
|
||||
// });
|
||||
|
||||
console.log('ANALYTICS RELOADED');
|
||||
|
||||
var duration = 0;
|
||||
var amountOfBufferEvents = 0;
|
||||
var amountOfBufferTimeInMS = 0;
|
||||
var videoIsPlaying = false;
|
||||
|
||||
|
||||
// function getTimeSinceLastEvent(function(){
|
||||
//
|
||||
// })
|
||||
|
||||
|
||||
|
||||
const analytics: Analytics = {
|
||||
videoBufferEvent: async (claim, data) => {
|
||||
console.log('data here');
|
||||
console.log(data);
|
||||
console.log(claim)
|
||||
bufferTime = data.bufferDuration;
|
||||
|
||||
const dataForWatchman = {
|
||||
device : getMobileOperatingSystem()
|
||||
}
|
||||
|
||||
const response = await sendWatchmanData(dataForWatchman);
|
||||
console.log(response);
|
||||
|
||||
},
|
||||
onDispose : () => {
|
||||
|
||||
},
|
||||
videoIsPlaying: (contentIsPlaying) => {
|
||||
videoIsPlaying = contentIsPlaying;
|
||||
},
|
||||
error: (message) => {
|
||||
return new Promise((resolve) => {
|
||||
if (internalAnalyticsEnabled && isProduction) {
|
||||
|
@ -197,37 +304,10 @@ const analytics: Analytics = {
|
|||
},
|
||||
|
||||
videoStartEvent: (claimId, duration) => {
|
||||
// TODO: hook into here
|
||||
sendPromMetric('time_to_start', duration);
|
||||
sendMatomoEvent('Media', 'TimeToStart', claimId, duration);
|
||||
},
|
||||
|
||||
videoBufferEvent: (claim, data) => {
|
||||
sendMatomoEvent('Media', 'BufferTimestamp', claim.claim_id, data.timeAtBuffer);
|
||||
|
||||
if (LBRY_WEB_BUFFER_API) {
|
||||
fetch(LBRY_WEB_BUFFER_API, {
|
||||
method: 'post',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
device: 'web',
|
||||
type: 'buffering',
|
||||
client: data.userId,
|
||||
data: {
|
||||
url: claim.canonical_url,
|
||||
position: data.timeAtBuffer,
|
||||
duration: data.bufferDuration,
|
||||
player: data.playerPoweredBy,
|
||||
readyState: data.readyState,
|
||||
stream_duration: data.duration,
|
||||
stream_bitrate: data.bitRate,
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
},
|
||||
adsFetchedEvent: () => {
|
||||
sendMatomoEvent('Media', 'AdsFetched');
|
||||
},
|
||||
|
@ -241,6 +321,7 @@ const analytics: Analytics = {
|
|||
sendMatomoEvent('Player', 'Loaded', embedded ? 'embedded' : 'onsite');
|
||||
},
|
||||
playerStartedEvent: (embedded) => {
|
||||
videoPlaying = true;
|
||||
sendMatomoEvent('Player', 'Started', embedded ? 'embedded' : 'onsite');
|
||||
},
|
||||
tagFollowEvent: (tag, following) => {
|
||||
|
|
|
@ -15,6 +15,8 @@ const select = (state, props) => {
|
|||
const { search } = props.location;
|
||||
const urlParams = new URLSearchParams(search);
|
||||
const autoplay = urlParams.get('autoplay');
|
||||
// get the position that will be used to start the video at, if t variable or saved in state
|
||||
// TODO: save and load this position from the db so can be used in display and
|
||||
const position = urlParams.get('t') !== null ? urlParams.get('t') : makeSelectContentPositionForUri(props.uri)(state);
|
||||
const userId = selectUser(state) && selectUser(state).id;
|
||||
|
||||
|
|
|
@ -127,6 +127,13 @@ function VideoViewer(props: Props) {
|
|||
}, [embedded, videoPlaybackRate]);
|
||||
|
||||
function doTrackingBuffered(e: Event, data: any) {
|
||||
console.log('BUFFER');
|
||||
console.log(this);
|
||||
console.log('BUFFER');
|
||||
this.pause()
|
||||
|
||||
// doAnalyticsBuffer(uri, data);
|
||||
|
||||
fetch(source, { method: 'HEAD' }).then((response) => {
|
||||
data.playerPoweredBy = response.headers.get('x-powered-by');
|
||||
doAnalyticsBuffer(uri, data);
|
||||
|
@ -148,6 +155,8 @@ function VideoViewer(props: Props) {
|
|||
}
|
||||
|
||||
const onEnded = React.useCallback(() => {
|
||||
analytics.videoIsPlaying(false);
|
||||
|
||||
if (adUrl) {
|
||||
setAdUrl(null);
|
||||
return;
|
||||
|
@ -167,15 +176,18 @@ function VideoViewer(props: Props) {
|
|||
setIsPlaying(true);
|
||||
setShowAutoplayCountdown(false);
|
||||
setIsEndededEmbed(false);
|
||||
analytics.videoIsPlaying(true);
|
||||
}
|
||||
|
||||
function onPause(event, player) {
|
||||
setIsPlaying(false);
|
||||
handlePosition(player);
|
||||
analytics.videoIsPlaying(false);
|
||||
}
|
||||
|
||||
function onDispose(event, player) {
|
||||
handlePosition(player);
|
||||
analytics.videoIsPlaying(false);
|
||||
}
|
||||
|
||||
function handlePosition(player) {
|
||||
|
@ -228,6 +240,15 @@ function VideoViewer(props: Props) {
|
|||
// delay from the header-fetch. This is a temp change until the next
|
||||
// re-factoring.
|
||||
player.on('loadedmetadata', () => restorePlaybackRate(player));
|
||||
player.on('seeking', function(e, data){
|
||||
console.log('here3')
|
||||
console.log(this)
|
||||
console.log(e)
|
||||
console.log(data)
|
||||
console.log(player)
|
||||
console.log('here4')
|
||||
/*this.pause()*/
|
||||
});
|
||||
|
||||
player.on('tracking:buffered', doTrackingBuffered);
|
||||
player.on('tracking:firstplay', doTrackingFirstPlay);
|
||||
|
@ -235,6 +256,15 @@ function VideoViewer(props: Props) {
|
|||
player.on('play', onPlay);
|
||||
player.on('pause', (event) => onPause(event, player));
|
||||
player.on('dispose', (event) => onDispose(event, player));
|
||||
|
||||
player.on('dispose', function(event){
|
||||
|
||||
|
||||
|
||||
console.log('PLAYER DISPOSED OF');
|
||||
console.log(event);
|
||||
});
|
||||
|
||||
player.on('error', () => {
|
||||
const error = player.error();
|
||||
if (error) {
|
||||
|
|
Loading…
Add table
Reference in a new issue