I'm creating a system that enables users to share files accross devices connected to the same wifi network. I would like to have a list of all connected devices so I can select which device to send to (Using simplepeer JS).
I have already created a small program that can share files using simplepeer JS
<p>Your id</p>
<div>
<textarea id="yourId"></textarea>
</div>
<div><button id="connect_bt">Connect</button></div>
<div style="margin-bottom:20px;">
<p>Other id</p>
<div>
<textarea id="otherId"></textarea>
</div>
<div></div>
</div>
<div>
<textarea id="message_input"></textarea>
<button id="send_message">Send message</button>
</div>
<pre id="messages"></pre>
<script src="simplepeer/simplepeer.min.js"></script>
var peer = new SimplePeer({
initiator: location.hash === '#init',
trickle: false
});
peer.on('signal', function(data) {
document.getElementById('yourId').value = JSON.stringify(data);
});
document.getElementById('connect_bt')
.addEventListener('click', function() {
var other_id = JSON.parse(document.getElementById('otherId').value);
peer.signal(other_id);
});
document.getElementById('send_message')
.addEventListener('click', function() {
var message = document.getElementById('message_input').value;
peer.send(message);
});
peer.on('data', function(data) {
document.getElementById('messages').textContent += data + '\n';
});
if (peer) {
//list all devices connected
var devices_list = //something that returns all devices connected to the same wifi network
console.log(devices_list)
}