-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
52 lines (51 loc) · 1.95 KB
/
test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">
var socket = io.connect('http://localhost:5000');
socket.on('connect', function() {
socket.emit('test', {data: 'I\'m connected!'});
socket.emit('join', { mentor: 'test1', mentee: 'test' })
socket.emit('join', { mentor: 'test2', mentee: 'test3' })
socket.on('joined', function(data){
console.log(data)
})
});
function handleInput(){
var input = document.getElementById("m").value
var h4 = document.getElementById("ms")
h4.innerText = ""
socket.emit('send_msg', { data: input, mentor: 'test1', mentee: 'test', _id: 'test1', lang: 'es' })
socket.on('msg_sent', function(data) {
if (data['_id'] === 'test1')
h4.innerText = data['data']
})
input.value = ""
}
function handleInput1(){
var input = document.getElementById("m1").value
var h4 = document.getElementById("ms1")
h4.innerText = ""
socket.emit('send_msg', { data: input, mentor: 'test2', mentee: 'test3', _id: 'test3', lang: 'en' })
socket.on('msg_sent', function(data) {
if (data['_id'] === 'test3')
h4.innerText = data['data']
})
input.value = ""
}
</script>
<body>
<h5>Mentee</h5>
<input id="m" type="text" autocomplete="off" /><button onclick="handleInput()">Send</button>
<h4 id="ms"></h4>
<h5>Mentor</h5>
<input id="m1" type="text" autocomplete="off" /><button onclick="handleInput1()">Send</button>
<h4 id="ms1"></h4>
</body>
</html>