Skip to content

Instantly share code, notes, and snippets.

@rupesh2017 rupesh2017/index.js Secret
Created Aug 28, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.