Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app/Http/Controllers/PWAController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public function manifest()
]
]);
}
}
}
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@
"lodash": "^4.16.2",
"vue": "^2.0.1",
"vue-resource": "^1.0.3"
},
"dependencies": {
"firebase": "^5.3.0"
}
}
6 changes: 6 additions & 0 deletions app/public/js/firebase-messaging-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
Copy link
Copy Markdown
Collaborator

@joshi1983 joshi1983 Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where this is coming from but there are some JavaScript errors when visiting the home page of the site. The errors lead to the Google Map not working.

I did not install firebase on app.accesslocator.com. Would that be the cause?

Here's a screenshot of them:
image

I'm going to undeploy the changes now since you ran the audit and made a screenshot.

importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
firebase.initializeApp({
messagingSenderId: "your messagingSenderId again"
});
const messaging = firebase.messaging();
10 changes: 10 additions & 0 deletions app/public/js/service_worker_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('./service-worker.js', { scope: './'})
.then((registration)=> {
firebase.messaging().useServiceWorker(registration);
})
.catch(function(err) {
console.log("Service Worker Failed to Register", err);
})
}
76 changes: 76 additions & 0 deletions app/public/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var cacheName = 'v1';

var cacheFiles = [];

self.addEventListener('install', function(e) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is "self" defined?

try {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(cacheFiles);
})
)
} catch(e) {
console.log(e);
}

})

self.addEventListener('activate', function(e) {
e.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(cacheNames.map(function(thisCacheName) {

if (thisCacheName !== cacheName) {
return caches.delete(thisCacheName);
}
}));
})
);
e.waitUntil(

caches.keys().then(function(cacheNames) {
return Promise.all(cacheNames.map(function(thisCacheName) {

if (thisCacheName !== cacheName) {
return caches.delete(thisCacheName);
}
}));
})
);
})

self.addEventListener('fetch',function(e) {
e.respondWith(

caches.match(e.request)


.then(function(response) {

if (response) {
return response;
}

var requestClone = e.request.clone();
return fetch(requestClone)
.then(function(response) {

if (!response) {
return response;
}

var responseClone = response.clone();
caches.open(cacheName).then(function(cache) {
cache.put(e.request, responseClone);
return response;
});

})
.catch(function(err) {
console.log('[ServiceWorker] Error Fetching & Caching New Data', err);
});


})
);
})
18 changes: 18 additions & 0 deletions app/resources/views/pages/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<script src="/js/utils.js" type="text/javascript"></script>
<script src="/js/home.js" type="text/javascript"></script>
<script src="/js/hover_text.js" type="text/javascript"></script>
<script src="/js/service_worker_script.js" type="text/javascript"></script>
<script type="text/javascript">
var default_location = {
'latitude': {{ $default_location['latitude'] }},
Expand All @@ -13,6 +14,23 @@
<script type="text/javascript" async defer
src="//maps.googleapis.com/maps/api/js?key={{ $google_map_api_key }}&amp;callback=initMap">
</script>

<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.3.0/firebase-messaging.js"></script>

<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBX6l4geba-CjXE_WlQwOX6pxCIrVl-tjk",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're still working on this but after you get everything working to your satisfaction, API keys like this one should be moved to .env and be taken from there like we do with the Google Maps API key.

authDomain: "wise-bongo-209220.firebaseapp.com",
databaseURL: "https://wise-bongo-209220.firebaseio.com",
projectId: "wise-bongo-209220",
storageBucket: "wise-bongo-209220.appspot.com",
messagingSenderId: "926874022337"
};
firebase.initializeApp(config);
</script>
@stop
@section('content')
<div class="home-page">
Expand Down