-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from Sunbird-ALL/all-1.3-tn-staging-hotfix
All 1.3 tn staging hotfix
- Loading branch information
Showing
4 changed files
with
141 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters