Skip to content

Commit

Permalink
add notifications + other small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
00magikarp committed Jan 7, 2025
1 parent a9ebce0 commit 348c047
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 142 deletions.
6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
{
"camera": "one",
"identifier": "rtsp://127.0.0.1:554/stream",
"x": "0.5",
"y": "0.5"
"x": "0.795",
"y": "0.90"
}
]
}
29 changes: 19 additions & 10 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
body {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
max-width: 1000px;
height: 100vh;
Expand Down Expand Up @@ -36,7 +35,7 @@ nav {

header {
overflow: hidden;
height: 25vh;
height: 30vh;
width: 100vw;
}

Expand All @@ -58,12 +57,17 @@ a {
text-decoration: none;
}

#location, .map-link {
#refresher {
font-size: 1.325em;
font-family: Lucida Sans Unicode, sans-serif Unicode;
}

#enabler, .map-link {
line-height: 1.7em;
font-weight: bold;
}

#location {
#enabler {
font-size: 1.5em;
color: var(--soteria-blue);
}
Expand All @@ -76,33 +80,38 @@ a {
color: lightgray;
}

#success {
.success {
color: limegreen;
}

#failure {
.failure {
color: red;
}

#floorplan-container {
display: flex;
justify-content: center;
align-items: center;
position: relative;
align-items: flex-start;
position: absolute;
left: 0;
z-index: -1;
top: 30vh;
max-width: 1000px;
width: 100%;
padding-top: 2vh;
padding-bottom: 2vh;
height: 70vh;
height: 65vh;
max-height: 75vh;
overflow: visible;
}

#map {
margin-top: 5vh;
display: flex;
justify-content: center;
position: relative;
width: 90%;
height: 70vh;
height: 65vh;
}

#floorplan {
Expand Down
Binary file added favicon.ico
Binary file not shown.
21 changes: 14 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@
<title>Soteria</title>
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="./css/style.css">
<script src="./js/location.js"></script>
<script src="./js/floorplan.js"></script>
<script src="./js/modal.js"></script>
<script src="main.js" type="module" defer></script>
<script src="./js/floorplan.js" defer></script>
<script src="./js/modal.js" defer></script>
</head>
<body>
<script>0</script>
<header>
<h1>Soteria</h1>
<a href="#" id="location">Checking if you're protected...</a>
<a href="#" id="enabler"><span id="refresher"></span><span id="location">Location... </span><span id="notification">Notification... </span></a>
<h2 style="margin: 0;">
<div class="map-link">
<a href="./map.html">View local map...</a>
<button id="infoBox"><img src="./assets/info.png" id="infoIcon" alt="Info Icon"></button>
<div id="popup" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<p>Floormap is recommended if you are nearby or familiar with the building. If not, it is highly encouraged to use a local map of the surrounding area.</p>
<div class="close">&times;</div><br>
Floormap is recommended if you are nearby or familiar with the building. If not, it is highly encouraged to use a local map of the surrounding area.<br><br>
Permissions key:<br>
❓ - Failed to retrieve<br>
⛔ - Access to service denied<br>
❌ - Not supported by your browser
</div>
</div>
</div>
Expand All @@ -32,7 +37,9 @@ <h2 style="margin: 0;">
</div>
<script type="module">
import { requestLocationPermission } from "./js/location.js";
// requestLocationPermission();
import { checkNotificationPermission } from "./main.js";
requestLocationPermission();
checkNotificationPermission();
</script>
</body>
</html>
74 changes: 40 additions & 34 deletions js/floorplan.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
const jsonPath = "https://www.soteria-security.us/PWA/assets/data.json";

document.addEventListener('DOMContentLoaded', () => {
fetch(jsonPath)
.then(response => response.json())
.then(data => {
const container = document.getElementById("floorplan-container");
const floorplan = document.getElementById("floorplan");

function positionDots() {
const containerBox = container.getBoundingClientRect();
const floorplanBox = floorplan.getBoundingClientRect();
const width = floorplanBox.width;
const height = floorplanBox.height;

const existingDots = document.querySelectorAll(".overlay");
existingDots.forEach(dot => dot.remove());

data.cameras.forEach(camera => {
const x = parseFloat(camera.x) * width + floorplanBox.x - containerBox.x;
const y = parseFloat(camera.y) * height + floorplanBox.y - containerBox.y;

const dot = document.createElement("img");
dot.src = "https://www.soteria-security.us/PWA/assets/reddot.svg";
dot.classList.add("overlay");
dot.style.left = `${x}px`;
dot.style.top = `${y}px`;
container.appendChild(dot);
});
}
const jsonPath = "assets/data.json";

fetch(jsonPath)
.then(response => response.json())
.then(data => {
const container = document.getElementById("floorplan-container");
const floorplan = document.getElementById("floorplan");

floorplan.onload = function() {
positionDots();
};

function positionDots() {
let containerBox = container.getBoundingClientRect();
let floorplanBox = floorplan.getBoundingClientRect();
let width = floorplanBox.width;
let height = floorplanBox.height;

const existingDots = document.querySelectorAll(".overlay");
existingDots.forEach(dot => dot.remove());

data.cameras.forEach(camera => {
const x = parseFloat(camera.x) * width + floorplanBox.x - containerBox.x;
const y = parseFloat(camera.y) * height + floorplanBox.y - containerBox.y;

const dot = document.createElement("img");
dot.src = "https://www.soteria-security.us/PWA/assets/reddot.svg";
dot.alt = "🔴";
dot.classList.add("overlay");
dot.style.left = `${x}px`;
dot.style.top = `${y}px`;
container.appendChild(dot);
});
}

if (floorplan.complete) {
positionDots();
window.addEventListener("resize", positionDots);
})
.catch(error => console.error("Error loading JSON:", error));
});
}

window.addEventListener("resize", positionDots);
})
.catch(error => console.error("Error loading JSON:", error));
37 changes: 13 additions & 24 deletions js/location.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
let latitude = null;
let longitude = null;

if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/service-worker.js')
.then(() => console.log('Service Worker registered'))
.catch(err => console.error('Service Worker registration failed:', err));
}

export function requestLocationPermission(callback) {
if (latitude !== null && longitude !== null) {
console.log('Location already available:', latitude, longitude);
console.log('Location already available');
if (callback) callback(latitude, longitude);
return;
}
Expand All @@ -27,37 +20,33 @@ export function requestLocationPermission(callback) {
error => {
if (error.code === error.PERMISSION_DENIED) {
console.warn('Location permission denied by the user.');
updateLocationDisplay(true, 'Location access denied.');
updateLocationDisplay(true, 'Location ');
} else {
console.error('Error requesting location permission:', error.message);
updateLocationDisplay(true, 'Failed to retrieve location.');
updateLocationDisplay(true, 'Location ❓');
}

if (callback) callback(null, null);
}
);
} else {
console.log('Geolocation is not supported by this browser.');
updateLocationDisplay(true, 'Geolocation is not supported by your browser.');
updateLocationDisplay(true, 'Location ❌');
if (callback) callback(null, null);
}
}

function updateLocationDisplay(failed = false, message = '') {
const locationBox = document.getElementById('location');
const locationText = document.getElementById('location');

if (locationBox) {
if (!failed) {
locationBox.innerHTML = `<span id="success">You're being protected!</span>`;
} else {
locationBox.innerHTML = `<span id="failure">${message || 'Location not shared!'}</span>`;
}
if (!failed) {
locationText.innerHTML = `<span class="success">Location ✅ </span>`;
} else {
locationText.innerHTML = `<span class="failure">${message || 'Location not shared!'} </span>`;
}
}

document.addEventListener("DOMContentLoaded", () => {
document.getElementById('location').addEventListener('click', (event) => {
event.preventDefault();
requestLocationPermission();
});
});
document.getElementById('enabler').addEventListener('click', (event) => {
event.preventDefault();
requestLocationPermission();
});
28 changes: 13 additions & 15 deletions js/modal.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
document.addEventListener("DOMContentLoaded", () => {
const btn = document.getElementById("infoBox");
const modal = document.getElementById("popup");
const span = document.getElementsByClassName("close")[0];
const btn = document.getElementById("infoBox");
const modal = document.getElementById("popup");
const span = document.getElementsByClassName("close")[0];

btn.onclick = function() {
modal.style.display = "block";
}
btn.onclick = function() {
modal.style.display = "block";
}

span.onclick = function() {
modal.style.display = "none";
}
span.onclick = function() {
modal.style.display = "none";
}

window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target === modal) {
modal.style.display = "none";
}
});
}
5 changes: 5 additions & 0 deletions keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const webPush = require('web-push');
// const vapidKeys = webPush.generateVAPIDKeys();
//
// console.log('VAPID Public Key:', vapidKeys.publicKey);
// console.log('VAPID Private Key:', vapidKeys.privateKey);
Loading

0 comments on commit 348c047

Please sign in to comment.