PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/jWebSocket/jWebSocketClient/web/demos/events/events.htm

http://jwebsocket.googlecode.com/
HTML | 222 lines | 172 code | 27 blank | 23 comment | 0 complexity | c6b601810c1573d1577bb279b7053315 MD5 | raw file
Possible License(s): Apache-2.0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01//EN" "http://www.w3.org/TR/html4/transitional.dtd">
  2. <!-- saved from url=(0089)file:///home/kyberneees/Work/java/EventServer/jWebSocketClient-0.11/demos/events/auth.htm -->
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  6. <meta http-equiv="X-UA-Compatible" content="chrome=1">
  7. <!-- If Google's chrome frame installed, use it! -->
  8. <!-- Comment needs to be BELOW this meta tag! -->
  9. <!--
  10. // ****************************************************************************
  11. // jWebSocket EventsPlugIn Demo (uses jWebSocket Client and Server)
  12. // (C) 2010 jWebSocket.org, Innotrade GmbH, Herzogenrath
  13. // ****************************************************************************
  14. // This program is free software; you can redistribute it and/or modify it
  15. // under the terms of the GNU Lesser General Public License as published by the
  16. // Free Software Foundation; either version 3 of the License, or (at your
  17. // option) any later version.
  18. // This program is distributed in the hope that it will be useful, but WITHOUT
  19. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  20. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  21. // more details.
  22. // You should have received a copy of the GNU Lesser General Public License along
  23. // with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
  24. // ****************************************************************************
  25. -->
  26. <meta http-equiv="Content-Language" content="en">
  27. <title>Events Demo</title>
  28. <link rel="stylesheet" type="text/css" href="../../res/css/jwebsocket.css">
  29. <!-- load the jWebSocket JavaScript client library -->
  30. <script src="../../res/js/jWebSocket.js" type="text/javascript"></script>
  31. <!-- this one imports the client side streaming plug-in -->
  32. <script type="text/javascript" src="../../res/js/jwsEventsPlugIn.js"></script>
  33. <script type="text/javascript" src="../../res/js/jwsCache.js"></script>
  34. <script type="text/javascript" src="../../res/js/md5/md5.js"></script>
  35. <script type="text/javascript" language="JavaScript">
  36. var eLog = null;
  37. function log( aString ) {
  38. eLog.innerHTML += aString + "<br>";
  39. if( eLog.scrollHeight > eLog.clientHeight ) {
  40. eLog.scrollTop = eLog.scrollHeight - eLog.clientHeight;
  41. }
  42. }
  43. function clearLog() {
  44. eLog.innerHTML = "";
  45. eLog.scrollTop = 0;
  46. }
  47. function initPage() {
  48. eLog = jws.$( "sdivLog" );
  49. if(jws.browserSupportsWebSockets()){
  50. jws.myConn = new jws.jWebSocketJSONClient();
  51. jws.myConn.open(jws.JWS_SERVER_URL, {
  52. OnOpen: function (){
  53. log(">>> Connected successfully! <br/>")
  54. //Creating the filter chain
  55. securityFilter = new jws.SecurityFilter();
  56. securityFilter.user = {username: "", roles: []};
  57. securityFilter.OnNotAuthorized = function(aToken){
  58. log("<b><font color='red'>Failure: </font></b><br/>&nbsp;Invalid roles to notify an event with id '" + aToken.type + "'!");
  59. }
  60. cacheFilter = new jws.CacheFilter();
  61. cacheFilter.cache = new jws.cache.Cache();
  62. validatorFiler = new jws.ValidatorFilter();
  63. //Creating a event notifier
  64. notifier = new jws.EventsNotifier();
  65. notifier.jwsClient = jws.myConn;
  66. notifier.filterChain = [securityFilter, cacheFilter, validatorFiler];
  67. notifier.initialize();
  68. //Creating a plugin generator
  69. generator = new jws.EventsPlugInGenerator();
  70. //Generating the auth & test plug-ins.
  71. auth = generator.generate("auth", notifier, function(){});
  72. test = generator.generate("test", notifier, function(){
  73. test.setVisitorNumber = function(aToken){
  74. alert("Visitor's counter: " + aToken. counter);
  75. }
  76. });
  77. }
  78. });
  79. } else {
  80. var lMsg = jws.MSG_WS_NOT_SUPPORTED;
  81. alert( lMsg );
  82. log( lMsg );
  83. }
  84. }
  85. function logon(){
  86. auth.logon({
  87. args: {
  88. username: jws.$( "stxfUsername" ).value,
  89. password: jws.$( "spwfPassword" ).value
  90. },
  91. OnFailure: function(aResponseToken){
  92. log("<b><font color='red'>Failure: </font></b><br/>&nbsp;" + aResponseToken.msg);
  93. },
  94. OnSuccess: function(aResponseToken){
  95. log("<b>Logon response: </b><br/>&nbsp;Message: " + aResponseToken.msg + "<br/>&nbsp;Roles: " + aResponseToken.roles.toString());
  96. //Populating the user instance
  97. securityFilter.user.username = aResponseToken.username;
  98. securityFilter.user.roles = aResponseToken.roles;
  99. }
  100. });
  101. }
  102. function logoff() {
  103. auth.logoff({
  104. OnSuccess: function(aResponseToken){
  105. securityFilter.user = {username: "", roles: []};
  106. log("<b>Logoff response: </b><br/>&nbsp;Message: " + aResponseToken.msg);
  107. }
  108. });
  109. }
  110. function getAPI(){
  111. notifier.notify("plugin.getapi", {
  112. args: {
  113. plugin_id: jws.$( "stxfPlugInId" ).value
  114. },
  115. OnSuccess: function(aResponseToken){
  116. log("<b>GetAPI response: </b><br/>" + JSON.stringify(aResponseToken.api));
  117. },
  118. OnFailure: function(aResponseToken){
  119. log("<b><font color='red'>Failure: </font></b><br/>&nbsp;" + aResponseToken.msg);
  120. }
  121. })
  122. }
  123. function getHash(){
  124. test.getHashCode({
  125. args: {
  126. text: jws.$( "stxfText" ).value
  127. },
  128. OnSuccess: function(aResponseToken){
  129. log("<b>Get Hash response: </b><br/>&nbsp;" + aResponseToken.hash_code);
  130. },
  131. OnFailure: function(aResponseToken){
  132. log("<b><font color='red'>Failure: </font></b><br/>&nbsp;" + aResponseToken.msg);
  133. }
  134. })
  135. }
  136. function executeSE(){
  137. test.secureEvent();
  138. }
  139. function getInfo(){
  140. test.getEventsInfo({
  141. OnSuccess: function(aResponseToken){
  142. log("<b>Events Info response: </b><br/>&nbsp;Name: " + aResponseToken.table.name + "<br/>&nbsp;Version: " + aResponseToken.table.version);
  143. }
  144. })
  145. }
  146. function s2c(){
  147. test.s2cNotification();
  148. }
  149. function exitPage(){}
  150. </script>
  151. </head>
  152. <body
  153. onload="initPage();"
  154. onunload="exitPage();"
  155. >
  156. <h1>Events Demo</h1>
  157. <p>Simple demo to test the EventsPlugIn features.</p>
  158. <!-- <iframe id="sifrtwitterLogin" style="width:100%; height:200px"></iframe> -->
  159. <div class="sdivContainer">
  160. <table class="stlbDlg" border="0" cellpadding="3" cellspacing="0" width="100%">
  161. <tbody><tr class="strDlg">
  162. <td class="stdDlg" width="5">&nbsp;Username:</td>
  163. <td class="stdDlg" width="5"><input class="stxfDlg" id="stxfUsername" type="text" value="kyberneees" style="width:150px"></td>
  164. <td class="stdDlg" width="5"><input class="sbtnDlg" id="sbtnLogon" type="button" value="Logon" onclick="logon();"></td>
  165. </tr>
  166. <tr class="strDlg">
  167. <td class="stdDlg" width="5">&nbsp;Password:</td>
  168. <td class="stdDlg" width="5"><input class="spwfDlg" id="spwfPassword" type="password" value="123" style="width:150px"></td>
  169. <td class="stdDlg" width="5"><input title="The 'USER' role is required. Security enabled in server & client" class="sbtnDlg" id="sbtnLogoff" type="button" value="Logoff" onclick="logoff();"></td>
  170. </tr>
  171. <tr class="strDlg">
  172. <td class="stdDlg" width="5">&nbsp;Plug-in ID:</td>
  173. <td class="stdDlg" width="5"><input class="stxfDlg" id="stxfPlugInId" type="text" value="test" style="width:150px"></td>
  174. <td class="stdDlg" width="5"><input title="Cache aspect enabled in server" class="sbtnDlg" id="sbtnGetAPI" type="button" value="Get API" onclick="getAPI();"></td>
  175. </tr>
  176. <tr class="strDlg">
  177. <td class="stdDlg" width="5">&nbsp;Input text to get the hash code:</td>
  178. <td class="stdDlg" width="5"><input class="stxfDlg" id="stxfText" type="text" value="Hi World!" style="width:150px"></td>
  179. <td class="stdDlg" width="5"><input class="sbtnDlg" id="sbtnGetHash" type="button" value="Get Hash" onclick="getHash();"></td>
  180. </tr>
  181. <tr class="strDlg">
  182. <td class="stdDlg" width="5">
  183. <input class="sbtnDlg" title="Notify to all the connectors" id="sbtnClear" type="button" value="S2C Event" onclick="s2c();">
  184. <input title="Cache aspect enabled in server & client" class="sbtnDlg" id="sbtnClear" type="button" value="Events Info" onclick="getInfo();">
  185. <input title="The 'USER' role is required. Security enabled in server & client" class="sbtnDlg" id="sbtnClear" type="button" value="Secured Event" onclick="executeSE();">
  186. <input class="sbtnDlg" id="sbtnClear" type="button" value="Clear Log" onclick="clearLog();">
  187. </td>
  188. </tr>
  189. </tbody>
  190. </table>
  191. </div>
  192. <div id="sdivLog" class="sdivContainer" style="position:relative; height:300px; overflow:auto;">
  193. </div>
  194. </body>
  195. </html>