Skip to content

Commit

Permalink
Merge pull request #208 from ajinkyapandetekdi/new-all-1.3-tn-dev
Browse files Browse the repository at this point in the history
Issueid #230114 feat: accessing data from morigal to cloudfrontIssuei…
  • Loading branch information
gouravmore authored Nov 8, 2024
2 parents 7206c54 + 56d12e8 commit e54bc54
Showing 1 changed file with 93 additions and 74 deletions.
167 changes: 93 additions & 74 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,104 @@
import React, { useEffect, useRef } from 'react';
import { ThemeProvider } from '@mui/material';
import { BrowserRouter as Router } from 'react-router-dom';
import { StyledEngineProvider } from '@mui/material/styles';
import FingerprintJS from '@fingerprintjs/fingerprintjs';
import routes from './routes';
import { AppContent } from './views';
import theme from './assets/styles/theme';
import { initialize } from './services/telementryService';
import { startEvent } from './services/callTelemetryIntract';
import '@project-sunbird/telemetry-sdk/index.js';
import React, { useEffect, useRef } from "react";
import { ThemeProvider } from "@mui/material";
import { BrowserRouter as Router } from "react-router-dom";
import { StyledEngineProvider } from "@mui/material/styles";
import FingerprintJS from "@fingerprintjs/fingerprintjs";
import routes from "./routes";
import { AppContent } from "./views";
import theme from "./assets/styles/theme";
import { initialize } from "./services/telementryService";
import { startEvent } from "./services/callTelemetryIntract";
import "@project-sunbird/telemetry-sdk/index.js";

const App = () => {
const ranonce = useRef(false);
useEffect(() => {
const initService = async () => {
var did;
if (localStorage.getItem('fpDetails_v2') !== null) {
let fpDetails_v2 = localStorage.getItem('fpDetails_v2');
did = fpDetails_v2.result;
} else {
did = localStorage.getItem('did');
}
const ranonce = useRef(false);
useEffect(() => {
const initService = async () => {
var did;
if (localStorage.getItem("fpDetails_v2") !== null) {
let fpDetails_v2 = localStorage.getItem("fpDetails_v2");
did = fpDetails_v2.result;
} else {
did = localStorage.getItem("did");
}

await initialize({
context: {
mode: process.env.REACT_APP_MODE, // To identify preview used by the user to play/edit/preview
authToken: '', // Auth key to make api calls
did: did, // Unique id to identify the device or browser
uid: 'anonymous',
channel: process.env.REACT_APP_CHANNEL, // Unique id of the channel(Channel ID)
env: process.env.REACT_APP_ENV,
await initialize({
context: {
mode: process.env.REACT_APP_MODE, // To identify preview used by the user to play/edit/preview
authToken: "", // Auth key to make api calls
did: did, // Unique id to identify the device or browser
uid: "anonymous",
channel: process.env.REACT_APP_CHANNEL, // Unique id of the channel(Channel ID)
env: process.env.REACT_APP_ENV,

pdata: {
// optional
id: process.env.REACT_APP_ID, // Producer ID. For ex: For sunbird it would be "portal" or "genie"
ver: process.env.REACT_APP_VER, // Version of the App
pid: process.env.REACT_APP_PID, // Optional. In case the component is distributed, then which instance of that component
},
tags: [
// Defines the tags data
'',
],
timeDiff: 0, // Defines the time difference// Defines the object roll up data
host: process.env.REACT_APP_HOST, // Defines the from which domain content should be load
endpoint: process.env.REACT_APP_ENDPOINT,
apislug: process.env.REACT_APP_APISLUG,
},
config: {},
// tslint:disable-next-line:max-line-length
metadata: {},
});
if (!ranonce.current) {
if (localStorage.getItem('contentSessionId') === null) {
startEvent();
}
ranonce.current = true;
}
};
pdata: {
// optional
id: process.env.REACT_APP_ID, // Producer ID. For ex: For sunbird it would be "portal" or "genie"
ver: process.env.REACT_APP_VER, // Version of the App
pid: process.env.REACT_APP_PID, // Optional. In case the component is distributed, then which instance of that component
},
tags: [
// Defines the tags data
"",
],
timeDiff: 0, // Defines the time difference// Defines the object roll up data
host: process.env.REACT_APP_HOST, // Defines the from which domain content should be load
endpoint: process.env.REACT_APP_ENDPOINT,
apislug: process.env.REACT_APP_APISLUG,
},
config: {},
// tslint:disable-next-line:max-line-length
metadata: {},
});
if (!ranonce.current) {
if (localStorage.getItem("contentSessionId") === null) {
startEvent();
}
ranonce.current = true;
}
};

const setFp = async () => {
const fp = await FingerprintJS.load();
const setFp = async () => {
const fp = await FingerprintJS.load();

const { visitorId } = await fp.get();
if (!localStorage.getItem('did')) {
localStorage.setItem('did', visitorId);
}
initService();
};
const { visitorId } = await fp.get();
if (!localStorage.getItem("did")) {
localStorage.setItem("did", visitorId);
}
initService();
};

setFp();
}, []);
setFp();
}, []);

return (
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<Router>
<AppContent routes={routes} />
</Router>
</ThemeProvider>
</StyledEngineProvider>
);
useEffect(() => {
const handleMessage = (event) => {
// Destructure the message data
const { messageType, localStorageKeyValue } = event.data;
if (messageType === "customData") {
for (const item of localStorageKeyValue) {
const key = item.key;
const value = item.value;

localStorage.setItem(key, value);
}
}
};
window.addEventListener("message", handleMessage);
return () => {
window.removeEventListener("message", handleMessage);
};
}, []);

return (
<StyledEngineProvider injectFirst>
<ThemeProvider theme={theme}>
<Router>
<AppContent routes={routes} />
</Router>
</ThemeProvider>
</StyledEngineProvider>
);
};

export default App;

0 comments on commit e54bc54

Please sign in to comment.