From ae19de6b73f94d878c21691ba65384c87b3f12e5 Mon Sep 17 00:00:00 2001 From: SARVASVA KHARE <64934816+sarvasvaKhare@users.noreply.github.com> Date: Thu, 13 Aug 2020 10:37:58 +0530 Subject: [PATCH 1/3] client side socket code --- client/js/socket-client.js | 42 +++++++++++++++++ client/test.ejs | 94 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 client/js/socket-client.js create mode 100644 client/test.ejs diff --git a/client/js/socket-client.js b/client/js/socket-client.js new file mode 100644 index 0000000..2d1d38b --- /dev/null +++ b/client/js/socket-client.js @@ -0,0 +1,42 @@ +var roomname = prompt('Please enter your roomname') +var username = prompt('please enter your username') +const io = require('socket.io-client') +var socket = io() +console.log('work1') +socket.emit('join', roomname) +console.log('work3') +socket.on('connectToRoom', function (data) { + document.body.innerHTML = '' + document.write(data) +}) +socket.on('joinplayer', (data) => { + console.log(data) +}) +socket.emit('setUsername', { username: username, roomname: roomname }) + +socket.on('userSet', function (data) { + var user = data.username + document.body.innerHTML = '' + console.log(user) + document.write(user) +}) +socket.on('userExists', function (data) { + document.body.innerHTML = '' + document.write(data) +}) +socket.on('newPrompt', () => { + username = prompt('username taken please enter new username') + socket.emit('setUsername', { username: username, roomname: roomname }) +}) +socket.emit('gameStart', { roomname: roomname }) + +socket.emit('cardHandToDeck', { /* cards: cards */roomname: roomname }) + +socket.on('usersList', (data) => { + data.forEach(name => { + console.log(name) + }) +}) +socket.on('disconnect', () => { + console.log('user disconnected client') +}) diff --git a/client/test.ejs b/client/test.ejs new file mode 100644 index 0000000..6b7c8fc --- /dev/null +++ b/client/test.ejs @@ -0,0 +1,94 @@ + + + +
+