-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathably.php
92 lines (77 loc) · 2.95 KB
/
ably.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html>
<head>
<title>Publishing Emergency Response</title>
</head>
<body>
<h1>Publishing Emergency Response</h1>
<p>As Soon as an emergency occurs this website will immediately push messages to the channels using ably realtime api.</p>
<p>Nearby Ambulances,PCR Vans and Fire Bridages will be notified About the Situation.</p>
</body>
<!-- Include the latest Ably Library -->
<script src="https://cdn.ably.io/lib/ably.min-1.js"></script>
<!-- Instance the Ably library -->
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.2.1/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyC3ti-4Ha53a52-G5hOOdyjWLkZzCFSqME",
authDomain: "quik-response.firebaseapp.com",
databaseURL: "https://quik-response.firebaseio.com",
projectId: "quik-response",
storageBucket: "quik-response.appspot.com",
messagingSenderId: "3922924606",
appId: "1:3922924606:web:6baedfd6f193bec2e2ed6f",
measurementId: "G-SSD5K11KXD"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
</script>
<script >
var realtime = new Ably.Realtime("SSRsXA.SgO-gA:8st5DRQ52bcE_-OY");
var channel = realtime.channels.get("Accident");
const preobject= document.getElementById('DATA');
const db=firebase.firestore();
db.collection("DATA").onSnapshot(function (querySnapshot){
querySnapshot.docChanges().forEach(function (change)
{
if(change.type==="added")
{
var lati=change.doc.data().LAT;
var longi=change.doc.data().LON;
var status=change.doc.data().STATUS;
var pos = status.lastIndexOf("Accident");
if(pos!=-1)
{
locate={lat:lati,lng:longi,sts:status};
console.log(locate);
channel.publish("update", { "lati": lati,"longi":longi });
}
}
if (change.type === "modified") {
var lati=change.doc.data().LAT;
var longi=change.doc.data().LON;
var status=change.doc.data().STATUS;
var pos = status.lastIndexOf("Accident");
if(pos!=-1)
{
locate={lat:lati,lng:longi,sts:status};
console.log(locate);
channel.publish("update", { "lati": lati,"longi":longi });
}
}
if (change.type === "removed") {
var lati=change.doc.data().LAT;
var longi=change.doc.data().LON;
locate={lat:lati,lng:longi};
console.log(locate);
}
});
});
</script>
</html>