-
-
Save rupesh2017/9590be8621b2899caed70a534a00b1f1 to your computer and use it in GitHub Desktop.
chat(1 to 1) not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code running on user machine | |
document.addEventListener('DOMContentLoaded',()=>{ | |
//connect to web socket | |
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port); | |
//once connected,connect event is emitted | |
socket.on('connect',()=>{ | |
document.querySelector('#submit').onclick= ()=>{ | |
const selection = document.querySelector('#task').value; | |
const user = document.querySelector('#user').value; | |
console.log(socket.id); | |
//emit new event | |
socket.emit('submit text',{'selection':selection,'user':user,'socketid':socket.id}); | |
return false; | |
}; | |
}); | |
socket.on('announce text',(data)=>{ | |
const li = document.createElement('li'); | |
//mistake was here | |
li.innerHTML=`text is here from ${data.user}:${data.selection}`; | |
//mistake was here | |
document.querySelector('#tasks').append(li); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment