-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
233 lines (167 loc) · 6.86 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!-- Kreative-Drop -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kreative-Drop</title>
<link href="https://fonts.googleapis.com/css2?family=Comfortaa&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
</head>
<body>
<script>
function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
var room_id;
if(getParameterByName("room_id")==undefined)
{
room_id= (Math.random() + 1).toString(36).substring(2);
window.location.href=window.location.href+"?room_id="+room_id;
}
else
room_id=getParameterByName("room_id")
</script>
<div class="container">
<div class="col-left">
<div class="left-box">
<div class="waiting-area">
<h2>Waiting for Peer</h2>
<img src="https://thumbs.gfycat.com/MadeupWillingKronosaurus-max-1mb.gif" />
</div>
<div class="drop-area" style="display: none;">
<p id="drop_zone_text">Drag one or more files to this <i>drop zone</i>.<br></p>
<div id="drop_zone" ondrop="dropHandler(event);" ondragover="dragOverHandler(event);">
<input type="file" id="fileinput">
</div>
<br>
<button id="sendFileBtn">send</button>
</div>
<div class="stats-area">
<div class="fileprogress-box">
<span id="filetransfer-text">Uploading</span> <span id="speed"></span> <br>
<span id="filename-text"></span><br>
<div class="progress" id="progress">0%</div>
<div class="progress-bar">
<div class="progress-bar-fill" style="height:24px;"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-right">
<div class="right-box">
<img src="logo.png" width="150px" height="150px"/>
<br>
Welcome to Kreative-Drop. <br>Share Large files Securly to Other Device
<br>
<div class="roomcode-box">
Room Link:<br><input type="text" id="room_id" />
</div>
<br>
<msglist></msglist>
<br>
<div class="info-box">
My Peer ID: <mypeerid></mypeerid>
<br>
<p class="speedlogs"></p>
PeerList
<list>
</list>
</div>
<br>
<div class="team">
<a href="team.html"> Meet Our Team!</a>
</div>
</div>
</div>
</div>
<script>
function dragOverHandler(ev) {
console.log('File(s) in drop zone');
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
}
function dropHandler(ev) {
console.log('File(s) dropped');
// Prevent default behavior (Prevent file from being opened)
ev.preventDefault();
document.body.style.backgroundColor = "lightgreen";
document.getElementById('fileinput').value = event.dataTransfer.getData('file');
var filename=ev.dataTransfer.files[0].name;
$('#drop_zone_text').html(filename+"<br>Start sending file now!")
$('#sendFileBtn').show()
$('#fileinput').hide()
}
$("document").ready(function(){
$("#fileinput").change(function() {
$('#drop_zone_text').html("File Dropped. Start sending file now!")
$('#sendFileBtn').show()
});
});
</script>
<script src="https://www.gstatic.com/firebasejs/5.0.1/firebase.js"></script>
<!-- Firebase App is always required and must be first -->
<script src="https://www.gstatic.com/firebasejs/5.0.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.0.1/firebase-database.js"></script>
<script >
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAE7inEQPaHGgsnMx2CUrrlGRTpbip7RE0",
authDomain: "webch-9ddf2.firebaseapp.com",
databaseURL: "https://webch-9ddf2.firebaseio.com",
projectId: "webch-9ddf2",
storageBucket: "webch-9ddf2.appspot.com",
messagingSenderId: "884619352461",
appId: "1:884619352461:web:736f9656b77169ea6105c4"
};
// Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);
// Initialize Realtime Database and get a reference to the service
const database = firebase.database();
// const database = getDatabase(app);
</script>
<script>
const peers_list = [];
var usersRef=database.ref('users/rooms/'+room_id+'/users');
usersRef.on('value',(snap)=>{
// console.log(snap.val());
snap.forEach(function(childSnapshot) {
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
console.log(childKey)
if(!peers_list.includes(childKey) && childKey!=mypeerid)
{
$('.waiting-area').hide();
$('.drop-area').show()
//new user
$('list').append('<p id="'+childKey+'">'+childKey+' </p>')
peers_list.push(childKey)
connectPeer(childKey)
} // database.ref('users/FBTest/'+childKey).onDisconnect().remove();
// ...
});
// database.ref('users/FBTest').child("-N8uxGTm-xHmaosCBMxq").onDisconnect().removeValue();
});
usersRef.on('child_removed', (data) => {
console.log("Removed:"+data.key)
$('#'+data.key).remove();
});
</script>
<script>
$('#room_id').val(location.origin + location.pathname+"?room_id="+room_id)
</script>
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
<script src="scripts.js"></script>
</body>
</html>