I made a simple chat program like this. When I tried accessing the same page URL from another computer, there was no response. Is there a way to solve this problem?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>P2P chat</title>
<style>
#peer-id {
margin-bottom: 10px;
}
#peers {
margin-bottom: 10px;
}
#messages div {
margin-bottom: 5px;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://unpkg.com/peerjs@1.4.7/dist/peerjs.min.js"></script>
<script>
const peer = new Peer();
peer.on('open', (id) => {
$('#peer-id').text(`Your ID: ${id}`);
});
peer.on('connection', (conn) => {
$('#peers').append(`<div id="${conn.peer}">${conn.peer}</div>`);
conn.on('data', (data) => {
$('#messages').append(`<div>${conn.peer}: ${data}</div>`);
});
});
$('#send').click(() => {
peer.connections.forEach((conn) => {
conn.send($('#message').val());
});
$('#message').val('');
});
</script>
</head>
<body>
<div id="peer-id"></div>
<div id="peers"></div>
<div id="messages"></div>
<input type="text" id="message">
<button id="send">Send</button>
</body>
</html>
I am a programming beginner, so I am having trouble finding a solution. I want to create a chat room that can accommodate three or more people using PeerJS. I am curious if it is possible to create a chat room that can accommodate three or more people using PeerJS.