-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhiteBoardApp.js
More file actions
72 lines (48 loc) · 1.28 KB
/
WhiteBoardApp.js
File metadata and controls
72 lines (48 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var clientSocket;
var io;
exports.initWhiteBoard=function(socket,sio)
{
clientSocket=socket;
io=sio;
//All events on the server side go here
clientSocket.on('createRoom',createRoom);
clientSocket.on('joinRoom',joinRoom);
clientSocket.on('new-message',displayNewMessage);
clientSocket.on('disconnect',disconnected);
clientSocket.on('drawing',draw);
}
//For teacher (create Room)
function createRoom(roomID)
{
this.join(roomID);
this.emit('createRoom','You have successfully created the room');
}
//For teacher or student join Room
function joinRoom(roomID,username)
{
console.log(roomID+ username+"from white board app event handler join room");
this.join(roomID);
var data=
{
username1:username
}
// io.sockets.in(roomID).emit('joinRoom',data);
clientSocket.in(roomID).broadcast.emit('joinRoom',data);
}
function displayNewMessage(data)
{
var message=data.message;
var roomid=data.roomid;
console.log(data);
clientSocket.in(roomid).broadcast.emit('new-message',message);
}
function disconnected()
{
console.log("user is disconnected");
}
function draw(data)
{
var mydata=data.content;
var roomid=data.roomid;
clientSocket.in(roomid).broadcast.emit('drawing', mydata);
}