Skip to content

Commit

Permalink
Merge pull request #103 from signalwire/joao/userVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsantosbh authored Aug 20, 2024
2 parents 5919937 + de39708 commit 31c4b6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions public/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ window.playbackEnded = () => {
})
}

const parser = new UAParser(window.navigator.userAgent)
const {
ua: userAgent,
browser: { name: browserName, version: browserVersion },
os: { name: osName, version: osVersion },
device: { type: deviceType },
}= parser.getResult()

window._userVariables = {
fullBrowserVersion: browserVersion || '',
gmtOffset: (-1.0 * new Date().getTimezoneOffset()) / 60,
hostname: window.location.hostname,
isAndroid: osName === 'Android',
isChrome: browserName === 'Chrome',
isChromium: browserName === 'Chromium',
isEdge: browserName === 'Edge',
isFirefox: browserName === 'Firefox',
isIE: browserName === 'IE',
isIOS: osName === 'iOS',
isMobile: deviceType === 'mobile',
isOpera: browserName === 'Opera',
isSafari: browserName === 'Safari',
isTablet: deviceType === 'tablet',
isWinPhone: osName === 'Windows Mobile',
isYandex: browserName === 'Yandex',
osName: osName || '',
osVersion: osVersion || '',
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
tzString: new Date().toTimeString().split(' ').splice(1).join(' '),
userAgent: userAgent,
}

async function enablePushNotifications() {
btnRegister.disabled = true

Expand Down Expand Up @@ -426,6 +458,7 @@ window.connect = async () => {
debug: { logWsTraffic: true },
nodeId: steeringId(),
rootElement: document.getElementById('rootElement'),
userVariables: window._userVariables
})

window.__call = call
Expand Down
1 change: 1 addition & 0 deletions views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://unpkg.com/@signalwire/js@dev"></script>
<script type="text/javascript" src="https://unpkg.com/ua-parser-js"></script>
<script type="text/javascript" src="full.js"></script>
</body>

Expand Down

0 comments on commit 31c4b6d

Please sign in to comment.