-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
113 lines (113 loc) · 2.74 KB
/
index.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<html>
<head>
<title>Bejesus IRC Channel</title>
<style type="text/css">
* {
margin: 0px;
}
body, html {
margin: 0px;
padding: 0px;
color: #000;
background:#a7a09a;
height: 98%;
}
div#top_section {
min-height: 100%;
height: auto !important;
height: 100%;
}
div#nick_list {
float: right;
width: 150px;
}
div#chat_body {
float: left;
}
div#chat_bar .push {
clear: both;
height: 2em;
}
</style>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var sock = null;
var rv = null;
var nickname = null;
var chatBody = null;
var textInput = null;
// var ts = null;
var body_loaded = function () {
sock = new io.Socket();
sock.on('message', handleMessage);
sock.connect();
chatBody = document.getElementById('chat_body');
textInput = document.getElementById('text_input');
};
var getNickname = function () {
var name = prompt("Please enter your nickname:", "");
switch (name) {
case "":
alert("You did not input a nickname, please reload if you wish to connect.");
sock.disconnect();
return null;
break;
case null:
alert("Login cancelled, please reload if you wish to connect.");
sock.disconnect();
return null;
break;
default:
return name;
break;
}
}
var handleMessage = function (data) {
var obj = JSON.parse(data);
if (nickname === null) {
alert("null nickname");
var tmp = getNickname();
if (tmp !== null) {
nickname = tmp;
rv = sock.send(JSON.stringify({ nickname: nickname }));
}
} else {
if (obj.hasOwnProperty('messagetype')) {
switch (obj.messagetype) {
case "message":
var p = document.createElement('p');
p.innerHtml = "<b>" + obj.from + "</b>: " + obj.message;
chatBody.appendChild(p);
break;
default:
alert(data);
break;
}
}
}
};
var sendMessage = function () {
sock.send(JSON.stringify({
messagetype: "message",
message: textInput.value
}));
textInput.value = "";
};
</script>
</head>
<body onload="body_loaded();">
<div id="top_section">
<div id="nick_list">
<ol id="nick_ol">
<li>dan</li>
</ol>
</div>
<div id="chat_body">
<span>Body</span>
</div>
</div>
<div id="chat_bar">
<input type="text" id="text_input"></input><button onClick="sendMessage();">Send</button>
</div>
</body>
</html>