example.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. <!doctype HTML>
  2. <html>
  3. <head>
  4. <title>Example</title>
  5. <script type='text/javascript'>
  6. var CONNECTION;
  7. var wantsToClose;
  8. var isConnected;
  9. var messageid = 1;
  10. var chatrooms = [];
  11. var chatclientid = 0;
  12. function ShowConnected()
  13. {
  14. var divConnected = document.getElementById('divConnected');
  15. divConnected.innerHTML = isConnected ? "Connected" : "Not connected";
  16. }
  17. function ProcessMessage(message) {
  18. if (message.substr(0,15)=="privatemessage(") {
  19. privatemessage(message.substr(15,message.length-16));
  20. return;
  21. }
  22. if (message.substr(0,16)=="chatroomcreated(") {
  23. chatroomcreated(message.substr(16,message.length-17));
  24. return;
  25. }
  26. if (message.substr(0,13)=="chatroomlist(") {
  27. chatroomlist(message.substr(13,message.length-14));
  28. return;
  29. }
  30. if (message.substr(0,6)=="error(") {
  31. error(message.substr(6,message.length-7));
  32. return;
  33. }
  34. if (message.substr(0,17)=="yourchatclientid(") {
  35. yourchatclientid(message.substr(17,message.length-18));
  36. return;
  37. }
  38. if (message.substr(0,19)=="userjoinedchatroom(") {
  39. userjoinedchatroom(message.substr(19,message.length-20));
  40. return;
  41. }
  42. if (message.substr(0,17)=="userleftchatroom(") {
  43. userleftchatroom(message.substr(17,message.length-18));
  44. return;
  45. }
  46. if (message.substr(0,19)=="chatroomwasdeleted(") {
  47. chatroomwasdeleted(message.substr(19,message.length-20));
  48. return;
  49. }
  50. if (message.substr(0,5)=="chat(") {
  51. chat(message.substr(5,message.length-6));
  52. return;
  53. }
  54. if (message.substr(0,16)=="usersinchatroom(") {
  55. usersinchatroom(message.substr(16,message.length-17));
  56. return;
  57. }
  58. if (message.substr(0,4)=="msg(") {
  59. msg(message.substr(4,message.length-5));
  60. return;
  61. }
  62. if (message.substr(0,6)=="users(") {
  63. users(message.substr(6,message.length-7));
  64. return;
  65. }
  66. DisplayMessage(message);
  67. }
  68. function error(message) {
  69. var parameters = getparameters(message,"si");
  70. DisplayMessage("Error: " + parameters[0]);
  71. return;
  72. }
  73. function chat(message) {
  74. // chat(messageid,chatroomid,chatclientid,userid,message)
  75. var parameters = getparameters(message,"iiiis");
  76. var text;
  77. if (parameters[3] == 0) {
  78. text = "chatclientid "+parameters[2] + ":"+parameters[4];
  79. } else {
  80. text = "user "+parameters[3] + ":"+parameters[4];
  81. }
  82. DisplayMessage(text);
  83. return;
  84. }
  85. function yourchatclientid(message) {
  86. var parameters = getparameters(message,"i");
  87. chatclientid = parameters[0];
  88. return;
  89. }
  90. function msg(message) {
  91. // msg(messageid,chatclientid,userid,message)
  92. var parameters = getparameters(message,"iiis");
  93. var text = "ChatClientID "+chatclientid + ":"+message;
  94. DisplayMessage(text);
  95. return;
  96. }
  97. function users(message) {
  98. // users(messageid,[userid,username,status]) List of users. status is 1 for logged in, 2 for logged out.
  99. var parameters = getparameters(message,"i[isi]");
  100. var divAllUsers = document.getElementById("divAllUsers");
  101. var output = [];
  102. var count;
  103. var loop;
  104. count = parameters.length;
  105. for(loop=1;loop<count;loop+=3) {
  106. output.push(parameters[loop] + " " + parameters[loop+1]);
  107. if (parameters[loop+2] == 1) {
  108. output.push("<input type='button' value='Say Hi' onclick='SayHi(0,"+parameters[loop]+")' />");
  109. } else {
  110. output.push("<input type='button' value='Delete User' onclick='removeuser("+parameters[loop]+")' />");
  111. }
  112. output.push("<br />");
  113. }
  114. divAllUsers.innerHTML = output.join("");
  115. }
  116. function usersinchatroom(message) {
  117. // usersinchatroom(messageid,chatroomid,[chatclientid,userid,username])
  118. var parameters = getparameters(message,"ii[iis]");
  119. var users = [];
  120. var count;
  121. var loop;
  122. var chatroomid;
  123. var newuser;
  124. var chatroom;
  125. chatroomid = parameters[1];
  126. count = parameters.length;
  127. for(loop=2;loop<count;loop+=3) {
  128. newuser = {
  129. chatclientid:parameters[loop],
  130. userid:parameters[loop+1],
  131. username:parameters[loop+2]
  132. };
  133. users.push(newuser);
  134. }
  135. chatroom = 0;
  136. count = chatrooms.length;
  137. for(loop=0;loop<count;loop++) {
  138. if (chatrooms[loop].chatroomid == chatroomid) {
  139. chatroom = chatrooms[loop];
  140. chatroom.users = users;
  141. break;
  142. }
  143. }
  144. // Display the users in a nicer way.
  145. ShowChatUsers(chatroom);
  146. return;
  147. }
  148. function chatroomwasdeleted(message) {
  149. // chatroomwasdeleted(messageid,chatroomid)
  150. var parameters = getparameters(message,"ii");
  151. var count;
  152. var loop;
  153. var chatroomid = parameters[1];
  154. var refresh = false;
  155. count = chatrooms.length;
  156. for(loop=0;loop<count;loop++) {
  157. if (chatrooms[loop].chatroomid == chatroomid) {
  158. chatrooms.splice(loop,1);
  159. refresh = true;
  160. break;
  161. }
  162. }
  163. if (refresh) {
  164. DisplayChatrooms();
  165. ShowOrHideChatroomBox();
  166. }
  167. }
  168. function userleftchatroom(message) {
  169. // userleftchatroom(messageid,chatroomid,chatclientid,userid,username)
  170. var parameters = getparameters(message,"iiiis");
  171. var count;
  172. var loop;
  173. var output;
  174. var affected_me = false;
  175. if (chatclientid == parameters[2]) {
  176. // Mark me as not being in this chatroom any more.
  177. count = chatrooms.length;
  178. for(loop=0;loop<count;loop++) {
  179. if (chatrooms[loop].chatroomid == parameters[1]) {
  180. affected_me = true;
  181. chatrooms[loop].info = chatrooms[loop].info & 254;
  182. break;
  183. }
  184. }
  185. }
  186. if (affected_me) {
  187. ShowOrHideChatroomBox();
  188. DisplayChatrooms();
  189. } else {
  190. if (parameters[3]==0) {
  191. output = "ClientID " + parameters[2];
  192. } else {
  193. output = "User " + parameters[4];
  194. }
  195. output += " left the chatroom.";
  196. DisplayMessage(output);
  197. }
  198. return;
  199. }
  200. function userjoinedchatroom(message) {
  201. // userjoinedchatroom(messageid,chatroomid,chatclientid,userid,username)
  202. var parameters = getparameters(message,"iiiis");
  203. var count = chatrooms.length;
  204. var loop;
  205. var chatroom = 0;
  206. var chatroom_name = "";
  207. for(loop=0;loop<count;loop++) {
  208. if (chatrooms[loop].chatroomid == parameters[1]) {
  209. chatroom = chatrooms[loop];
  210. chatroom_name = chatroom.name;
  211. break;
  212. }
  213. }
  214. if (parameters[2]==chatclientid) {
  215. // I joined this chatroom.
  216. chatroom.info = chatroom.info | 1;
  217. DisplayChatrooms();
  218. ShowOrHideChatroomBox();
  219. getusersinchatroom(chatroom.chatroomid);
  220. } else {
  221. if (parameters[3] == 0) {
  222. DisplayMessage("Clientid " + parameters[2] + " joined.");
  223. } else {
  224. DisplayMessage("User " + parameters[4] + "joined.");
  225. }
  226. }
  227. }
  228. function adduserdialog() {
  229. document.getElementById('divAddUser').style.display='';
  230. }
  231. function logindialog() {
  232. document.getElementById('divLogin').style.display='';
  233. }
  234. function getusers()
  235. {
  236. var divAllUsers = document.getElementById("divAllUsers");
  237. divAllUsers.innerHTML = "Loading . . .";
  238. var message = "getusers("+(messageid++)+",3,4,test)";
  239. if (isConnected) {
  240. CONNECTION.send(message);
  241. }
  242. }
  243. function removeuser(userid)
  244. {
  245. //removeuser(messageid,userid,server_password)
  246. var message = "removeuser("+(messageid++)+","+userid+",4,test)";
  247. if (isConnected) {
  248. CONNECTION.send(message);
  249. }
  250. getusers();
  251. }
  252. function ShowChatUsers(chatroom)
  253. {
  254. var count;
  255. var loop;
  256. var divChatUsers = document.getElementById("divChatUsers");
  257. var output = [];
  258. var user;
  259. if ((chatroom) && (chatroom.users)) {
  260. count = chatroom.users.length;
  261. for(loop=0;loop<count;loop++) {
  262. user = chatroom.users[loop];
  263. if (user.userid == 0) {
  264. output.push("ChatClientID:" + user.chatclientid);
  265. } else {
  266. output.push("UserName:" + user.username);
  267. }
  268. output.push("<input type='button' value='Say Hi' onclick='SayHi("+user.chatclientid+","+user.userid+")' />");
  269. output.push("<br />");
  270. }
  271. }
  272. divChatUsers.innerHTML = output.join("");
  273. return;
  274. }
  275. function ShowOrHideChatroomBox()
  276. {
  277. // Update the chatroom box when a new chatroom is created or deleted.
  278. var divChat = document.getElementById("divChat");
  279. var ChatroomID;
  280. var loop;
  281. var option;
  282. var selectedIndex;
  283. var selectedChatRoomID;
  284. var foundChatroom;
  285. var index;
  286. var chatroom;
  287. foundChatroom = false;
  288. for(loop=0;loop<chatrooms.length;loop++) {
  289. if ((chatrooms[loop].info & 1) != 0) {
  290. foundChatroom = true;
  291. break;
  292. }
  293. }
  294. if (!foundChatroom) {
  295. divChat.style.display = "none";
  296. } else {
  297. divChat.style.display = "";
  298. ChatroomID = document.getElementById("ChatroomID");
  299. selectedIndex = ChatroomID.selectedIndex;
  300. selectedChatRoomID = 0;
  301. if ((selectedIndex >= 0) && (ChatRoomID.options.length > 0)) {
  302. selectedChatRoomID = ChatroomID.options[selectedIndex].value;
  303. }
  304. while (ChatroomID.options.length > 0) {
  305. ChatroomID.remove(0);
  306. }
  307. selectedIndex = -1;
  308. index = 0;
  309. chatroom = 0;
  310. for(loop=0;loop<chatrooms.length;loop++) {
  311. if ((chatrooms[loop].info & 1) != 0) {
  312. option = document.createElement("option");
  313. option.text = chatrooms[loop].name;
  314. option.value = chatrooms[loop].chatroomid;
  315. ChatroomID.options[index] = option;
  316. if (chatrooms[loop].chatroomid == selectedChatRoomID) {
  317. chatroom = chatrooms[loop];
  318. selectedIndex = index;
  319. }
  320. index++;
  321. }
  322. }
  323. if (selectedIndex >=0) {
  324. ChatroomID.selectedIndex = selectedIndex;
  325. }
  326. ShowChatUsers(chatroom);
  327. }
  328. }
  329. function chatroomcreated(message) {
  330. // chatroomcreated(messageid,chatroomid,room_name,info)
  331. var parameters = getparameters(message,"iisi");
  332. var chatroom = { chatroomid:parameters[1],name:parameters[2],info:parameters[3]};
  333. var count = chatrooms.length;
  334. var loop;
  335. for(loop=0;loop<count;loop++) {
  336. if (chatrooms[loop].chatroomid == chatroom.chatroomid) {
  337. return;
  338. }
  339. }
  340. chatrooms.push(chatroom);
  341. DisplayChatrooms();
  342. ShowOrHideChatroomBox();
  343. }
  344. function chatroomlist(message)
  345. {
  346. var parameters = getparameters(message,"i[isi]")
  347. var count1;
  348. var loop1;
  349. var count2;
  350. var loop2;
  351. var chatroom;
  352. var rooms_to_delete = [];
  353. var found;
  354. count1 = parameters.length;
  355. count2 = chatrooms.length;
  356. for(loop2=0;loop2<count2;loop2++) {
  357. rooms_to_delete[loop2] = true;
  358. }
  359. for(loop1=1;loop1<count1;loop1+=3) {
  360. chatroom = {
  361. chatroomid:parameters[loop1],
  362. name:parameters[loop1+1],
  363. info:parameters[loop1+2]
  364. };
  365. found = false;
  366. for(loop2=0;loop2<count2;loop2++) {
  367. if (chatrooms[loop2].chatroomid == chatroom.chatroomid) {
  368. // This chatroom is already here. Don't mess with it.
  369. rooms_to_delete[loop2] = false;
  370. found = true;
  371. break;
  372. }
  373. }
  374. // Add this chatroom.
  375. if (!found) {
  376. chatrooms.push(chatroom);
  377. count2++;
  378. }
  379. }
  380. // Remove chatrooms not listed.
  381. for(loop2=count2-1;loop2>=0;loop2--) {
  382. if (rooms_to_delete[loop2]) {
  383. chatrooms.splice(loop2,1);
  384. }
  385. }
  386. document.getElementById('divChatrooms').innerHTML="Loading...";
  387. setTimeout(DisplayChatrooms,2000);
  388. ShowOrHideChatroomBox();
  389. }
  390. function privatemessage(message) {
  391. // clientid,userid,username,message
  392. var parameters = getparameters(message,"iiss");
  393. if (parameters[1]==0) {
  394. DisplayMessage("clientid "+parameters[0]+":"+parameters[3]);
  395. } else {
  396. DisplayMessage("user "+parameters[2]+":"+parameters[3]);
  397. }
  398. }
  399. function getparameters(parameters,types) {
  400. var output = [];
  401. var count = types.length;
  402. var start = 0;
  403. var next;
  404. var loop;
  405. var len;
  406. var parenstart = -1;
  407. for(loop=0;loop<count;loop++) {
  408. if (start >= parameters.length) {
  409. // Ran out of data.
  410. break;
  411. }
  412. switch (types.substr(loop,1)) {
  413. case "i":
  414. {
  415. next = parameters.indexOf(",",start);
  416. if (next < 0) {
  417. next = parameters.length;
  418. }
  419. len = parseInt(parameters.substr(start,next-start));
  420. output.push(len);
  421. start = next + 1;
  422. break;
  423. }
  424. case "s":
  425. {
  426. next = parameters.indexOf(",",start);
  427. if (next >= 0) {
  428. len = parseInt(parameters.substr(start,next-start));
  429. output.push(parameters.substr(next+1,len));
  430. start = next + 1 + len;
  431. }
  432. break;
  433. }
  434. case "[":
  435. {
  436. parenstart = loop;
  437. break;
  438. }
  439. case "]":
  440. {
  441. loop = parenstart;
  442. break;
  443. };
  444. }
  445. }
  446. return output;
  447. }
  448. function DisplayChatrooms() {
  449. var count = chatrooms.length;
  450. var loop;
  451. var info;
  452. var output = [];
  453. var chatroom;
  454. for(loop=0;loop<count;loop++) {
  455. info = chatrooms[loop].info;
  456. /*info is a number:
  457. bit 1 = Are you in this chatroom.
  458. bit 2 = Can everybody join this chatroom.
  459. bit 3 = Does this chatroom require a password.
  460. bit 4 = Will this chatroom be deleted when everybody leaves.*/
  461. chatroom = "Chatroom: "+chatrooms[loop].name;
  462. if ((info & 1) == 0)
  463. {
  464. chatroom += "<input type='button' value='join' onclick='joinchatroom(" + chatrooms[loop].chatroomid + ")' />";
  465. } else {
  466. chatroom += "<input type='button' value='leave' onclick='leavechatroom(" + chatrooms[loop].chatroomid + ")' />";
  467. }
  468. chatroom += "<input type='button' value='delete' onclick='removechatroom(" + chatrooms[loop].chatroomid + ")' />";
  469. if ((info & 2) == 0) {
  470. chatroom += "secure password required,";
  471. } else {
  472. chatroom += "everybody can join,";
  473. }
  474. if ((info & 4) != 0) {
  475. chatroom += "requires password,";
  476. }
  477. output.push(chatroom+"<br />");
  478. }
  479. document.getElementById('divChatrooms').innerHTML = output.join("");
  480. }
  481. function DisplayMessage(message) {
  482. var divMessages = [];
  483. var loop;
  484. for(loop=1;loop<=5;loop++) {
  485. divMessages.push(document.getElementById("divMessage" + loop));
  486. }
  487. for(loop=0;loop<4;loop++) {
  488. divMessages[loop].innerHTML = divMessages[loop+1].innerHTML;
  489. }
  490. divMessages[4].innerHTML = message;
  491. }
  492. function SayHi(chatclientid,userid)
  493. {
  494. var message = "sendto("+(messageid++)+","+chatclientid+","+userid+","+"2,Hi)";
  495. if (isConnected) {
  496. CONNECTION.send(message);
  497. }
  498. }
  499. function SendToChatroom() {
  500. var ChatroomID = document.getElementById("ChatroomID");
  501. var chatroomID = ChatroomID.options[ChatroomID.selectedIndex].value;
  502. var text = document.getElementById("ChatMessage").value;
  503. var message = "send("+(messageid++)+","+chatroomID+","+text.length+","+text+")";
  504. if (isConnected) {
  505. CONNECTION.send(message);
  506. }
  507. }
  508. function addchatroom(secure)
  509. {
  510. // addchatroom(messageid,room_name,question,answer,answer_hashed,server_password)
  511. var roomname = "abcdefghijklmnopqrstuvwxyz";
  512. roomname = roomname.substr(Math.floor(Math.random()*26),1)
  513. + roomname.substr(Math.floor(Math.random()*26),1)
  514. + roomname.substr(Math.floor(Math.random()*26),1)
  515. + roomname.substr(Math.floor(Math.random()*26),1)
  516. + roomname.substr(Math.floor(Math.random()*26),1);
  517. message = "addchatroom("+(messageid++)+",5,"+roomname+"5,Test25,Test35,Test44,"+(secure?"test":"abcd")+")"
  518. if (isConnected) {
  519. CONNECTION.send(message);
  520. }
  521. }
  522. function getusersinchatroom(chatroomid)
  523. {
  524. message = "getusersinchatroom("+(messageid++)+","+chatroomid+")";
  525. if (isConnected) {
  526. CONNECTION.send(message);
  527. }
  528. }
  529. function joinchatroom(chatroomid)
  530. {
  531. // joinchatroom(messageid,chatroomid,leave_other_chatrooms,answerhashed,server_password)
  532. var message = "joinchatroom("+(messageid++)+","+chatroomid+",0,5,Test44,test)";
  533. if (isConnected) {
  534. CONNECTION.send(message);
  535. }
  536. }
  537. function leavechatroom(chatroomid)
  538. {
  539. // leavechatroom(messageid,chatroomid)
  540. var message = "leavechatroom("+(messageid++)+","+chatroomid+")";
  541. if (isConnected) {
  542. CONNECTION.send(message);
  543. }
  544. }
  545. function removechatroom(chatroomid)
  546. {
  547. // removechatroom(messageid,chatroomid)
  548. var message = "removechatroom("+(messageid++)+","+chatroomid+",4,test)";
  549. if (isConnected) {
  550. CONNECTION.send(message);
  551. }
  552. }
  553. function getchatroomlist()
  554. {
  555. var message = "getchatroomlist("+(messageid++)+")";
  556. if (isConnected) {
  557. CONNECTION.send(message);
  558. }
  559. }
  560. function adduser()
  561. {
  562. var userid = Math.floor(document.getElementById("NewUserID").value);
  563. var username = document.getElementById("NewUserName").value;
  564. var password = document.getElementById("NewPassword").value;
  565. var message = "adduser("+(messageid++)+","+userid+","+username.length+","+username+password.length+","+password+"4,test)";
  566. if (isConnected) {
  567. CONNECTION.send(message);
  568. document.getElementById('divAddUser').style.display='none';
  569. }
  570. }
  571. function login()
  572. {
  573. var username = document.getElementById("UserName").value;
  574. var password = document.getElementById("Password").value;
  575. var message = "login("+(messageid++)+","+username.length+","+username+password.length+","+password+")";
  576. if (isConnected) {
  577. CONNECTION.send(message);
  578. document.getElementById('divLogin').style.display='none';
  579. }
  580. }
  581. function logout()
  582. {
  583. var message="logout("+(messageid++)+",0)";
  584. if (isConnected) {
  585. CONNECTION.send(message);
  586. }
  587. }
  588. function disconnect()
  589. {
  590. var message="logout("+(messageid++)+",1)";
  591. if (isConnected) {
  592. CONNECTION.send(message);
  593. }
  594. }
  595. function sendmessage()
  596. {
  597. var message = document.getElementById('Message');
  598. var messagetosend = message.value;
  599. messagetosend = "sendtoall(4,test"+(messageid++)+","+messagetosend.length+","+messagetosend+")";
  600. message.value = "";
  601. if (isConnected) {
  602. CONNECTION.send(messagetosend);
  603. }
  604. }
  605. function InitializeWebSocket() {
  606. // open the connection to the Web Socket server
  607. try
  608. {
  609. CONNECTION = new WebSocket('ws://' + document.domain + ':' + location.port + "/websocket", 'chatroom-protocol');
  610. // open a SECURE connection to the Web Socket server
  611. // CONNECTION = new WebSocket('wss://' + location.host + '/chat');
  612. // When the connection is open
  613. CONNECTION.onopen = function () {
  614. //alert('Connection opened');
  615. isConnected = true;
  616. setTimeout(ShowConnected,1);
  617. };
  618. // when the connection is closed by the server
  619. CONNECTION.onclose = function () {
  620. //alert('Connection closed');
  621. isConnected = false;
  622. setTimeout(ShowConnected,1);
  623. if (!wantsToClose) {
  624. // Try to reconnect in 1/100 of a second.
  625. setTimeout(InitializeWebSocket,500);
  626. }
  627. };
  628. // Log errors
  629. CONNECTION.onerror = function (e) {
  630. //alert('An error occured');
  631. isConnected = false;
  632. setTimeout(ShowConnected,1);
  633. // Try to reconnect 1 time per second.
  634. setTimeout(InitializeWebSocket,1000);
  635. };
  636. // Log messages from the server
  637. CONNECTION.onmessage = function (e) {
  638. ProcessMessage(e.data);
  639. //$('#messages').append($('<li>').text(e.data));
  640. };
  641. } catch(err) {
  642. // Try to reconnect 1 time per second.
  643. setTimeout(InitializeWebSocket,1000);
  644. }
  645. setTimeout(Ping,90000);
  646. }
  647. function Ping()
  648. {
  649. // Keep the connection open.
  650. if (isConnected) {
  651. CONNECTION.send("nop()");
  652. }
  653. setTimeout(Ping,90000); // 90 seconds.
  654. }
  655. </script>
  656. </head>
  657. <body onload='InitializeWebSocket()'>
  658. <center><h1>example.html</center>
  659. <div id='divConnected'>Not connected</div>
  660. <div id='divMessage1'></div>
  661. <div id='divMessage2'></div>
  662. <div id='divMessage3'></div>
  663. <div id='divMessage4'></div>
  664. <div id='divMessage5'></div>
  665. Message: <input type='text' name='Message' id="Message" style='width:400px' />
  666. <input type='button' value='send' onclick='sendmessage()' /><br />
  667. <input type='button' value='test create secure chat room' onclick='addchatroom(true)' />
  668. <input type='button' value='test create public chat room' onclick='addchatroom(false)' />
  669. <input type='button' value='get chatroom list' onclick='getchatroomlist()' />
  670. <input type='button' value='add user' onclick='adduserdialog()' />
  671. <input type='button' value='login' onclick='logindialog()' />
  672. <input type='button' value='logout' onclick='logout()' />
  673. <input type='button' value='disconnect' onclick='disconnect()' />
  674. <input type='button' value='list all users' onclick='getusers()' />
  675. <br />
  676. <div id='divAddUser' style='display:none'>
  677. <table border='1'>
  678. <tr><td conspan='2'>Add User</td></tr>
  679. <tr><td>UserID:</td><td><input type='text' name='NewUserID' id='NewUserID' /></td></tr>
  680. <tr><td>User Name:</td><td><input type='text' name='NewUserName' id='NewUserName' /></td></tr>
  681. <tr><td>Password:</td><td><input type='text' name='NewPassword' id='NewPassword' /></td></tr>
  682. <tr><td colspan='2'><input type='button' value='Save User' onclick='adduser()' /></td></tr>
  683. </table>
  684. </div>
  685. <div id='divLogin' style='display:none'>
  686. <table border='1'>
  687. <tr><td conspan='2'>Login</td></tr>
  688. <tr><td>User Name:</td><td><input type='text' name='UserName' id='UserName' /></td></tr>
  689. <tr><td>Password:</td><td><input type='text' name='Password' id='Password' /></td></tr>
  690. <tr><td colspan='2'><input type='button' value='Login' onclick='login()' /></td></tr>
  691. </table>
  692. </div>
  693. <div id='divChatrooms'></div>
  694. <div id='divChat' style='display:none'><select name='ChatroomID' id='ChatroomID'></select><input type='text' name='ChatMessage' id='ChatMessage' maxlength='100' /><input type='button' value='Send Message To Chatroom' onclick='SendToChatroom()' /></div>
  695. <div id='divChatUsers'></div>
  696. <div id='divAllUsers'></div>
  697. </body>
  698. </html>