Nextrek
Diff Revisions
1128
vs
1129
for /socketIO/public/customer.html
|
@@ -12,16 +12,94 @@ |
12 |
12 |
|
// create user |
13 |
13 |
|
socket.emit('CONNECTION:OPEN', {name: 'Customer ' + Date.now(), role: 'CUSTOMER'}); |
14 |
14 |
|
|
|
15 |
+ |
// room created |
|
16 |
+ |
socket.on('ROOM:CREATED', (user) => { |
|
17 |
+ |
const $room = uiRoom(user, |
|
18 |
+ |
$form => { |
|
19 |
+ |
$form.submit(e => { |
|
20 |
+ |
e.preventDefault(); |
|
21 |
+ |
|
|
22 |
+ |
const $input = $form.find('input'); |
|
23 |
+ |
const room = user.room; |
|
24 |
+ |
|
|
25 |
+ |
if ($input.val().trim() !== "") { |
|
26 |
+ |
const msg = $input.val(); |
|
27 |
+ |
const json = { |
|
28 |
+ |
content: msg, |
|
29 |
+ |
contentType: 'TEXT', |
|
30 |
+ |
room |
|
31 |
+ |
}; |
|
32 |
+ |
|
|
33 |
+ |
console.log('send_message'); |
|
34 |
+ |
|
|
35 |
+ |
socket.emit('SEND:MESSAGE', json); |
|
36 |
+ |
$input.val(''); |
|
37 |
+ |
} |
|
38 |
+ |
return false; |
|
39 |
+ |
}); |
|
40 |
+ |
}, |
|
41 |
+ |
$formImg => { |
|
42 |
+ |
$formImg.submit(e => { |
|
43 |
+ |
e.preventDefault(); |
|
44 |
+ |
|
|
45 |
+ |
const $input = $formImg.find('input'); |
|
46 |
+ |
const room = user.room; |
|
47 |
+ |
|
|
48 |
+ |
const filesSelected = $input[0].files; |
|
49 |
+ |
if (filesSelected.length > 0) { |
|
50 |
+ |
const fileToLoad = filesSelected[0]; |
|
51 |
+ |
|
|
52 |
+ |
const fileReader = new FileReader(); |
|
53 |
+ |
|
|
54 |
+ |
fileReader.onload = (fileLoadedEvent) => { |
|
55 |
+ |
const json = { |
|
56 |
+ |
content: fileLoadedEvent.target.result, |
|
57 |
+ |
contentType: 'IMAGE', |
|
58 |
+ |
room |
|
59 |
+ |
}; |
|
60 |
+ |
console.log('send_image'); |
|
61 |
+ |
|
|
62 |
+ |
socket.emit('SEND:MESSAGE', json); |
|
63 |
+ |
$input.val(''); |
|
64 |
+ |
}; |
|
65 |
+ |
|
|
66 |
+ |
fileReader.readAsDataURL(fileToLoad); |
|
67 |
+ |
} |
|
68 |
+ |
}) |
|
69 |
+ |
} |
|
70 |
+ |
); |
|
71 |
+ |
|
|
72 |
+ |
$('#customers-rooms').append($room); |
|
73 |
+ |
}); |
|
74 |
+ |
|
15 |
75 |
|
// receive messages |
16 |
76 |
|
socket.on('SEND:MESSAGE', (data) => { |
17 |
77 |
|
uiDisplayMessage(data); |
18 |
78 |
|
}); |
|
79 |
+ |
|
|
80 |
+ |
// user left |
|
81 |
+ |
socket.on('ROOM:LEAVE', (user) => { |
|
82 |
+ |
const content = { |
|
83 |
+ |
content: user.name + ' left the room.', |
|
84 |
+ |
contentType: 'TEXT', |
|
85 |
+ |
room: user.room, |
|
86 |
+ |
from: user |
|
87 |
+ |
} |
|
88 |
+ |
uiDisplayMessage(content); |
|
89 |
+ |
}); |
|
90 |
+ |
|
|
91 |
+ |
|
|
92 |
+ |
$(document).ready(() => { |
|
93 |
+ |
$('#leave').click(() => { |
|
94 |
+ |
socket.emit('ROOM:LEAVE'); |
|
95 |
+ |
}); |
|
96 |
+ |
}); |
19 |
97 |
|
</script> |
20 |
98 |
|
</head> |
21 |
99 |
|
<body> |
22 |
100 |
|
<h1>CUSTOMER</h1> |
23 |
|
- |
<div id="page"> |
24 |
|
- |
<form action=""></form> |
|
101 |
+ |
<button id="leave">Leave</button> |
|
102 |
+ |
<div id="customers-rooms"> |
25 |
103 |
|
</div> |
26 |
104 |
|
</body> |
27 |
105 |
|
</html> |