-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
379 lines (327 loc) · 17.5 KB
/
index.html
File metadata and controls
379 lines (327 loc) · 17.5 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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!doctype html>
<html lang="en-us">
<head>
<title>SoundSend. - Share your Files using sound</title>
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
<meta charset="UTF-8">
<meta name="description"
content="SoundSend is a web based application that allows you to send and receive files to and from nearby devices through the help of sound waves.">
<meta name="keywords" content="SoundSend, sound,send,wave,soundid,audioqr,AudioQR,ggwave,ggwave,">
<meta name="author" content="Sudip Ghosh">
<meta property="og:title" content="SoundSend." />
<meta property="og:description"
content="SoundSend is a web based application that allows you to send and receive files to and from nearby devices through the help of sound waves." />
<meta property="og:image"
content="https://raw.githubusercontent.com/imsudip/sound_send_web/main/images/meta-min.png" />
<meta property="og:url" content="https://soundsend.ml" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="SoundSend." />
<meta property="og:locale" content="en_US" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=PT Mono' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
<link href='style.css' rel='stylesheet'>
</head>
<body class="lg:px-24 md:px-8 px-2">
<header class="text-gray-600 body-font">
<div class="container mx-auto flex flex-wrap p-5 flex-col flex-row items-center">
<a
class="flex order-first title-font font-medium items-center text-gray-900 lg:items-center mb-4 md:mb-0">
<span class="ml-3 text-xl"
style="font-family: Inconsolata; color: #0429FA; font-weight: bolder; font-size: 52px;">SoundSend.</span>
</a>
<div class="py-2"></div>
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400">Share your Files using sound</p>
</div>
</header>
<div class="infoButton " onclick="window.location.href='/info.html'">
<img src="/images/info.png" alt="info" class="infoButtonImage">
</div>
<div class=" flex flex-wrap ">
<div class="flex-auto ">
<div class="py-8"></div>
<!-- FILE PICKER -->
<div class="flex justify-center items-center w-full ">
<label for="dropzone-file" id="drop-area"
class="flex flex-col justify-center items-center w-full h-64 bg-gray-50 rounded-lg border-2 border-gray-300 border-dashed cursor-pointer hover:bg-gray-100 ">
<div class="flex flex-col justify-center items-center pt-5 pb-6">
<svg aria-hidden="true" class="mb-3 w-10 h-10 text-gray-400" fill="none" stroke="currentColor"
viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12">
</path>
</svg>
<p class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">Click to
upload</span> or drag and drop</p>
<p id="info-title" class="text-xs text-gray-500 dark:text-gray-400">Small files upto few MBs</p>
<p id='file-status' class="text-xs text-gray-500 dark:text-gray-400"></p>
</div>
<input id="dropzone-file" type="file" class="hidden" />
</label>
</div>
<div class="py-4"></div>
<!-- END FILE PICKER -->
<div class="">
<div class="flex items-center mb-4">
<input id="ultrasonic" type="checkbox" value=""
class="w-4 h-4 text-blue-600 bg-gray-100 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
<label for="ultrasonic" class="ml-2 text-base font-medium text-gray-900 dark:text-gray-300">Use
UltraSonic</label>
<div class="px-12"></div>
<input id="fastmode" type="checkbox" value=""
class="w-4 h-4 text-blue-600 bg-gray-100 rounded border-gray-300 focus:ring-blue-500 dark:focus:ring-blue-600 dark:ring-offset-gray-800 focus:ring-2 dark:bg-gray-700 dark:border-gray-600">
<label for="fastmode" class="ml-2 text-base font-medium text-gray-900 dark:text-gray-300">Use Fast
Mode</label>
</div>
</div>
<div class="py-4"></div>
<!-- Send file button-->
<button type="button" id="send-button"
class="text-white bg-gradient-to-r from-blue-500 via-blue-600 to-blue-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800 font-medium rounded-lg text-base px-5 py-2.5 text-center mr-2 mb-2 w-full">Send
Files</button>
<!-- Receive File Button -->
<button type="button" id="receive-button"
class="text-white bg-gradient-to-r from-blue-500 via-blue-600 to-blue-700 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800 font-medium rounded-lg text-base px-5 py-2.5 text-center mr-2 mb-2 w-full">Receive
Files</button>
<button type="button" id="stop-receive-button" hidden
class="text-white bg-gradient-to-r from-red-400 via-red-500 to-red-600 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-red-300 dark:focus:ring-red-800 font-medium rounded-lg text-base px-5 py-2.5 text-center mr-2 mb-2 w-full">Stop
Capturing</button>
<div class="py-4"></div>
<div class="flex flex-row justify-center">
<div class="flex flex-col flex-initial" id='downloadBox'>
<div style=" font-size: 16px; font-family: Inconsolata ; text-align: center;">Download Files from
here</div>
</div>
</div>
</div>
<div class="">
<div style="margin-left: 20px; font-size: 32px; font-family: Inconsolata ;">Console</div>
<div class="consoleContainer " id="ccn">
<div id="log"></div>
</div>
</div>
</div>
<!-- <div id="main-container">
Minimal <b>ggwave</b> example using Javascript bindings
<br><br>
<div>Tx Data:</div> <textarea name="textarea" id="txData"
style="width:300px;height:100px;">Hello javascript</textarea><br>
<button onclick="onSend();">Send</button>
<br><br>
<div>Rx data:</div> <textarea name="textarea" id="rxData" style="width:300px;height:100px;"
disabled></textarea><br>
<!-- <button id="captureStart">Start capturing</button>
<button id="captureStop" hidden>Stop capturing</button> -->
<!-- <br><br>
<div class="cell-version">
<span>
|
Build time: <span class="nav-link">@GIT_DATE@</span> |
Commit hash: <a class="nav-link"
href="https://github.com/ggerganov/ggwave/commit/@GIT_SHA1@">@GIT_SHA1@</a> |
Commit subject: <span class="nav-link">@GIT_COMMIT_SUBJECT@</span> |
<a class="nav-link" href="https://github.com/ggerganov/ggwave/tree/master/examples/ggwave-js">Source
Code</a> |
</span>
</div>
</div> -->
<div id="txData"></div>
<div id="rxData"></div>
<script src="console_c.js"></script>
<script type="text/javascript" src="ggwave.js"></script>
<script type='text/javascript'>
window.AudioContext = window.AudioContext || window.webkitAudioContext;
window.OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
var context = null;
var recorder = null;
// the ggwave module instance
var ggwave = null;
var parameters = null;
var instance = null;
// instantiate the ggwave instance
// ggwave_factory comes from the ggwave.js module
ggwave_factory().then(function (obj) {
ggwave = obj;
});
var txData = document.getElementById("txData");
var rxData = document.getElementById("rxData");
var captureStart = document.getElementById("receive-button");
var captureStop = document.getElementById("stop-receive-button");
var isUltraSonic = false;
var isFastMode = false;
var ultrasonicCheckbox = document.getElementById("ultrasonic");
var fastModeCheckbox = document.getElementById("fastmode");
// event handlers
ultrasonicCheckbox.addEventListener("change", function () {
isUltraSonic = ultrasonicCheckbox.checked;
console.log("UltraSonic: " + isUltraSonic);
});
fastModeCheckbox.addEventListener("change", function () {
isFastMode = fastModeCheckbox.checked;
console.log("FastMode: " + isFastMode);
});
// helper function
function convertTypedArray(src, type) {
var buffer = new ArrayBuffer(src.byteLength);
var baseView = new src.constructor(buffer).set(src);
return new type(buffer);
}
// initialize audio context and ggwave
function init() {
if (!context) {
context = new AudioContext({ sampleRate: 48000 });
parameters = ggwave.getDefaultParameters();
parameters.sampleRateInp = context.sampleRate;
parameters.sampleRateOut = context.sampleRate;
instance = ggwave.init(parameters);
}
}
//
// Tx
//
function onSend(message) {
init();
// pause audio capture during transmission
captureStop.click();
var protocol;
if (isFastMode) {
if (isUltraSonic) {
protocol = ggwave.ProtocolId.GGWAVE_PROTOCOL_ULTRASOUND_FASTEST
} else {
protocol = ggwave.ProtocolId.GGWAVE_PROTOCOL_AUDIBLE_FASTEST
}
} else {
if (isUltraSonic) {
protocol = ggwave.ProtocolId.GGWAVE_PROTOCOL_ULTRASOUND_FAST
} else {
protocol = ggwave.ProtocolId.GGWAVE_PROTOCOL_AUDIBLE_FAST
}
}
// generate audio waveform
var waveform = ggwave.encode(instance, message, protocol, 10)
// play audio
var buf = convertTypedArray(waveform, Float32Array);
var buffer = context.createBuffer(1, buf.length, context.sampleRate);
buffer.getChannelData(0).set(buf);
var source = context.createBufferSource();
source.buffer = buffer;
source.connect(context.destination);
source.start(0);
}
//
// Rx
//
captureStart.addEventListener("click", function () {
init();
let constraints = {
audio: {
// not sure if these are necessary to have
echoCancellation: false,
autoGainControl: false,
noiseSuppression: false
}
};
console.log("Starting capture....");
navigator.mediaDevices.getUserMedia(constraints).then(function (e) {
mediaStream = context.createMediaStreamSource(e);
var bufferSize = 1024;
var numberOfInputChannels = 1;
var numberOfOutputChannels = 1;
if (context.createScriptProcessor) {
recorder = context.createScriptProcessor(
bufferSize,
numberOfInputChannels,
numberOfOutputChannels);
} else {
recorder = context.createJavaScriptNode(
bufferSize,
numberOfInputChannels,
numberOfOutputChannels);
}
recorder.onaudioprocess = function (e) {
var source = e.inputBuffer;
var res = ggwave.decode(instance, convertTypedArray(new Float32Array(source.getChannelData(0)), Int8Array));
if (res && res.length > 0) {
res = new TextDecoder("utf-8").decode(res);
rxData.value = res;
console.log("Data Captured...");
console.log("Decoding Data...");
function getDownloadLink(fid, fileName) {
// https://trixtj.deta.dev/api/v1/getlink
var request = new XMLHttpRequest();
var l = "https://anonfiles.com/" + fid;
request.open("GET", "https://trixtj.deta.dev/api/v1/getlink?link=" + l + "&name=" + fileName);
request.send();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
var jsonResponse = JSON.parse(request.responseText);
console.log("Data processsing complete...");
var link = jsonResponse["link"]
console.log("File link: " + link);
var dBox = document.getElementById("downloadBox");
// add download button to the box
var dButton = document.createElement("button");
// add class to the button
dButton.className = "flex-shrink text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center items-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 my-1 ";
// add text to the button
dButton.innerHTML = "Download - " + fileName;
// add the button to the box
dBox.appendChild(dButton);
// download the file when the button is clicked
dButton.addEventListener("click", function () {
window.open(link, "_blank");
});
}
else {
// console.log(request.status);
}
}
};
var fid = rxData.value.split(",")[0];
var fileName = rxData.value.split(",")[1];
getDownloadLink(fid, fileName);
}
// obsolete javascript resampling
// since ggwave v0.2.0 the resampling is built-in ggwave
//var offlineCtx = new OfflineAudioContext(source.numberOfChannels, 48000*source.duration, 48000);
//var offlineSource = offlineCtx.createBufferSource();
//offlineSource.buffer = source;
//offlineSource.connect(offlineCtx.destination);
//offlineSource.start();
//offlineCtx.startRendering();
//offlineCtx.oncomplete = function(e) {
// var resampled = e.renderedBuffer.getChannelData(0);
// var res = ggwave.decode(instance, convertTypedArray(new Float32Array(resampled), Int8Array));
// if (res) {
// rxData.value = res;
// }
//};
}
mediaStream.connect(recorder);
recorder.connect(context.destination);
}).catch(function (e) {
console.error(e);
});
rxData.value = 'Listening ...';
captureStart.hidden = true;
captureStop.hidden = false;
});
captureStop.addEventListener("click", function () {
if (recorder) {
recorder.disconnect(context.destination);
mediaStream.disconnect(recorder);
recorder = null;
}
console.log('Audio capture is paused! Press the "Start capturing" button to analyze audio from the microphone');
rxData.value = 'Audio capture is paused! Press the "Start capturing" button to analyze audio from the microphone';
captureStart.hidden = false;
captureStop.hidden = true;
});
captureStop.click();
</script>
<script src="service.js"></script>
<script src="drag_drop.js"></script>
</body>
</html>