WebSocket Chat for Paste Comments
25. WebSocket Chat for Paste Comments
====================================
const ws = new WebSocket('wss://pastetext.com:8080/comments');
ws.onopen = () => console.log('Connected to PasteText comments');
ws.onmessage = (event) => {
const comment = JSON.parse(event.data);
appendComment(comment.user, comment.text);
};
function sendComment(text) {
ws.send(JSON.stringify({
pasteId: 'abc123',
text: text,
timestamp: Date.now()
}));
}
Featured
Advertisement
Category
Action