-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
118 lines (93 loc) Β· 4.73 KB
/
script.js
File metadata and controls
118 lines (93 loc) Β· 4.73 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
document.addEventListener("DOMContentLoaded", function () {
const emergencyButton = document.getElementById("emergencyButton");
let mediaRecorder;
let recordedChunks = [];
// π Function to Start Camera & Video Recording Automatically
async function startRecording() {
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
document.getElementById("videoElement").srcObject = stream;
mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = event => recordedChunks.push(event.data);
mediaRecorder.onstop = saveRecording;
mediaRecorder.start();
} catch (error) {
alert("Error accessing camera or microphone: " + error);
}
}
// π Function to Save Video Recording Locally
function saveRecording() {
const blob = new Blob(recordedChunks, { type: "video/webm" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = "emergency_recording.webm";
document.body.appendChild(a);
a.click();
URL.revokeObjectURL(url);
}
// π Function to Send Emergency Alert via WhatsApp
function sendEmergencyMessage(location) {
const trustedContact = "+91 8793634325"; // Replace with actual contact number
const message = `π¨ EMERGENCY ALERT! π¨\nLocation: ${location}\nPlease help immediately!`;
// Open WhatsApp with a pre-filled emergency message
const whatsappURL = `https://api.whatsapp.com/send?phone=${trustedContact}&text=${encodeURIComponent(message)}`;
window.open(whatsappURL, "_blank");
}
// π Function to Start a Video Call Automatically
function startVideoCall() {
const trustedContact = "+91 879363435"; // Replace with actual contact number
// β
WhatsApp Video Call (Works only on mobile)
const whatsappCallURL = `https://wa.me/${trustedContact}`;
window.open(whatsappCallURL, "_blank");
// β
Google Meet (User needs a predefined meeting link)
//window.open("https://meet.google.com/rkj-nzrf-ftf", "_blank");
//window.open("https://meet.google.com/your-meeting-link", "_blank");
// β
Zoom Call (User needs Zoom installed)
window.open("https://us05web.zoom.us/j/82852340094?pwd=BDXYTt2pmrRjmGqRZbynMUJz7koSBe.1", "_blank");
//window.open("https://us04web.zoom.us/j/your-meeting-id", "_blank");
//Stops the Emergency Button
document.getElementById("stopRecordingButton").addEventListener("click", function () {
if (mediaRecorder && mediaRecorder.state === "recording") {
mediaRecorder.stop(); // Stops recording & triggers download
Β Β Β Β }
});
}
// π Function to Get User's Live Location Automatically
function getLocationAndSendAlert() {
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(position => {
const location = `Latitude: ${position.coords.latitude}, Longitude: ${position.coords.longitude}`;
sendEmergencyMessage(location);
startVideoCall(); // Auto-start video call after sending the alert
}, error => {
alert("Unable to access location: " + error.message);
});
} else {
alert("Geolocation is not supported in this browser.");
}
}
// π Click Event: Trigger All Features
emergencyButton.addEventListener("click", function () {
//alert("β Emergency Activated! Recording, Sending Alert, and Starting Video Call...");
startRecording(); // Start video recording
getLocationAndSendAlert(); // Get location & send alert
// π Function to Stop All Emergency Features
function stopRecordingButton() {
alert("β Emergency Stopped! Turning off camera & stopping recording...");
// β
Stop Video Recording
if (mediaRecorder && mediaRecorder.state === "recording") {
mediaRecorder.stop();
}
// β
Turn Off Camera
if (mediaStream) {
mediaStream.getTracks().forEach(track => track.stop());
document.getElementById("videoElement").srcObject = null;
}
// β
Stop Location Tracking
navigator.geolocation.clearWatch();
// β
Close Open WhatsApp & Call Tabs (User must close manually)
alert("Please close any open WhatsApp or video call tabs manually.");
}
});
});