Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
MajesticWafer committed May 24, 2024
1 parent 6ece4ec commit c83f4b1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions localchat/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ document.addEventListener('DOMContentLoaded', () => {
consoleDiv.scrollTop = consoleDiv.scrollHeight;
}

function setupConnection() {
function setupConnection(connection) {
logToConsole('Setting up connection');

conn.on('data', (data) => {
connection.on('data', (data) => {
logToConsole('Received data: ' + data);
displayMessage('Friend', data);
});

conn.on('open', () => {
connection.on('open', () => {
logToConsole('Connection opened');
enableChat();
});

conn.on('close', () => {
connection.on('close', () => {
logToConsole('Connection closed');
disableChat();
});

conn.on('error', (err) => {
connection.on('error', (err) => {
logToConsole('Connection error: ' + err);
disableChat();
});
Expand Down Expand Up @@ -59,7 +59,7 @@ document.addEventListener('DOMContentLoaded', () => {
peer.on('connection', (connection) => {
logToConsole('Received connection');
conn = connection;
setupConnection();
setupConnection(conn);
});

const menuContainer = document.getElementById('menu-container');
Expand Down Expand Up @@ -88,10 +88,6 @@ document.addEventListener('DOMContentLoaded', () => {
logToConsole('Friend ID: ' + friendId);
if (friendId) {
conn = peer.connect(friendId);
conn.on('open', () => {
logToConsole('Connection to host opened');
setupConnection();
});
}
menuContainer.style.display = 'none';
chatContainer.style.display = 'flex';
Expand Down

0 comments on commit c83f4b1

Please sign in to comment.