Skip to content

Instantly share code, notes, and snippets.

@rupesh2017
Created August 28, 2018 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupesh2017/9590be8621b2899caed70a534a00b1f1 to your computer and use it in GitHub Desktop.
Save rupesh2017/9590be8621b2899caed70a534a00b1f1 to your computer and use it in GitHub Desktop.
chat(1 to 1) not working
//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