websocket-server 1.0.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +185 -0
  4. data/Rakefile +56 -0
  5. data/exe/websocket +41 -0
  6. data/lib/log.rb +244 -0
  7. data/lib/server/mime_types.rb +38 -0
  8. data/lib/websocket/arguments_parser.rb +142 -0
  9. data/lib/websocket/channel_initializer.rb +73 -0
  10. data/lib/websocket/config.rb +59 -0
  11. data/lib/websocket/encoding.rb +21 -0
  12. data/lib/websocket/file_server_channel_progressive_future_listener.rb +32 -0
  13. data/lib/websocket/frame_handler.rb +71 -0
  14. data/lib/websocket/header_helpers.rb +70 -0
  15. data/lib/websocket/http_static_file_server_handler.rb +50 -0
  16. data/lib/websocket/http_static_file_server_handler_instance_methods.rb +160 -0
  17. data/lib/websocket/idle_handler.rb +41 -0
  18. data/lib/websocket/idle_state_user_event_handler.rb +47 -0
  19. data/lib/websocket/instance_methods.rb +127 -0
  20. data/lib/websocket/listenable.rb +41 -0
  21. data/lib/websocket/message_handler.rb +47 -0
  22. data/lib/websocket/response_helpers.rb +83 -0
  23. data/lib/websocket/server.rb +26 -0
  24. data/lib/websocket/shutdown_hook.rb +36 -0
  25. data/lib/websocket/ssl_cipher_inspector.rb +44 -0
  26. data/lib/websocket/ssl_context_initialization.rb +106 -0
  27. data/lib/websocket/telnet_proxy.rb +22 -0
  28. data/lib/websocket/validation_helpers.rb +51 -0
  29. data/lib/websocket/version.rb +16 -0
  30. data/lib/websocket-server.rb +13 -0
  31. data/lib/websocket_client.rb +478 -0
  32. data/lib/websocket_server.rb +50 -0
  33. data/web/client.html +43 -0
  34. data/web/css/client/console.css +167 -0
  35. data/web/css/client/parchment.css +112 -0
  36. data/web/favicon.ico +0 -0
  37. data/web/fonts/droidsansmono.v4.woff +0 -0
  38. data/web/js/client/ansispan.js +103 -0
  39. data/web/js/client/client.js +144 -0
  40. data/web/js/client/console.js +393 -0
  41. data/web/js/client/websocket.js +76 -0
  42. data/web/js/jquery.min.js +2 -0
  43. metadata +145 -0
@@ -0,0 +1,167 @@
1
+ @font-face {
2
+ font-family: 'Droid Sans Mono';
3
+ font-style: normal;
4
+ font-weight: 400;
5
+ src: local('Droid Sans Mono'), local('DroidSansMono'), url(/fonts/droidsansmono.v4.woff) format('woff');
6
+ }
7
+ body {
8
+ background-color: #000000;
9
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
10
+ font-size: 16px;
11
+ font-weight: 200;
12
+ text-align: left;
13
+ color: #333333;
14
+ }
15
+ body.preload * {
16
+ -webkit-transition: none !important;
17
+ -moz-transition: none !important;
18
+ -ms-transition: none !important;
19
+ -o-transition: none !important;
20
+ }
21
+ a { text-decoration: none; color: inherit; }
22
+ div.nav {
23
+ position: fixed;
24
+ z-index: 9998;
25
+ top: 0px; left: 0px;
26
+ width: 100%;
27
+ height: 2em;
28
+ cursor: default;
29
+ background-color: rgba(0, 0, 0, 1);
30
+ }
31
+ div.nav a:hover { cursor: pointer; }
32
+ a.link:hover { background-color: rgba(35, 35, 35, 1); }
33
+ div.menu {
34
+ display: none;
35
+ position: fixed;
36
+ top: 2em; right: 0;
37
+ background-color: rgba(0, 0, 0, 1);
38
+ }
39
+ div.nav a {
40
+ color: #555555;
41
+ }
42
+ div.nav a:hover {
43
+ color: #aaaaaa;
44
+ }
45
+ div.nav ul {
46
+ list-style-type: none;
47
+ overflow: hidden;
48
+ margin-top: 0.5em;
49
+ }
50
+ div.nav ul li a {
51
+ cursor: pointer;
52
+ }
53
+ div.nav ul li.link {
54
+ float: left;
55
+ }
56
+ div.nav ul li.control {
57
+ float: right;
58
+ padding-right: 2em;
59
+ }
60
+ div.menu ul {
61
+ list-style-type: none;
62
+ overflow: hidden;
63
+ padding-inline-start: inherit;
64
+ }
65
+ div.menu ul li a {
66
+ display: block;
67
+ cursor: pointer;
68
+ padding: 1em;
69
+ }
70
+ div.menu ul li {
71
+ border-bottom: 1px solid #555555;
72
+ }
73
+ div.menu ul li:last-child {
74
+ border-bottom: none;
75
+ margin-bottom: 0px;
76
+ }
77
+ a.button {
78
+ font-weight: 400;
79
+ -moz-border-radius: 12px;
80
+ border-radius: 12px;
81
+ border-color: #555555;
82
+ line-height: 40px;
83
+ padding: 8px 16px;
84
+ color: #555555;
85
+ cursor: pointer;
86
+ }
87
+ a.button:hover {
88
+ text-decoration: none;
89
+ }
90
+ form.input {
91
+ width: 100%;
92
+ }
93
+ table {
94
+ border: 0px;
95
+ border-spacing: 0px;
96
+ margin-right: 1em;
97
+ }
98
+ td, th {
99
+ padding: 0px;
100
+ }
101
+ input,input[type=text],input[type=email],input[type=password] {
102
+ border: none;
103
+ float: right;
104
+ width: 100%;
105
+ outline-width: 0px;
106
+ outline-style: none;
107
+ font-family: 'Droid Sans Mono', sans-serif;
108
+ letter-spacing: normal;
109
+ font-size: 1em;
110
+ line-height: normal;
111
+ padding: 0px;
112
+ margin: 0px;
113
+ color: #22ff22;
114
+ background-color: rgba(0, 0, 0, 1);
115
+ overflow: hidden;
116
+ }
117
+ input.password {
118
+ display: none;
119
+ }
120
+ div.input label {
121
+ font-size: 1em;
122
+ font-weight: normal;
123
+ line-height: normal;
124
+ white-space: nowrap;
125
+ }
126
+ label.password {
127
+ display: none;
128
+ }
129
+ input[type=text]:hover,input[type=email]:hover,input[type=password]:hover {
130
+ background-color: inherit;
131
+ }
132
+ input[type=text]:focus,input[type=email]:focus,input[type=password]:focus {
133
+ background-color: inherit;
134
+ }
135
+ div.display {
136
+ display: block;
137
+ padding: 1em;
138
+ font-family: 'Droid Sans Mono', sans-serif;
139
+ font-size: 1em;
140
+ font-weight: normal;
141
+ letter-spacing: normal;
142
+ line-height: normal;
143
+ color: #22ff22;
144
+ white-space: pre-line;
145
+ word-wrap: break-word; /* IE 5+ */
146
+ overflow: hidden;
147
+ }
148
+ div.space {
149
+ padding-bottom: 5em;
150
+ }
151
+ a.direction { cursor: pointer; }
152
+ div.markdown {
153
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
154
+ }
155
+ div.markdown pre {
156
+ border: 1px solid #22ff22;
157
+ border-radius: 7px;
158
+ background-color: #444444;
159
+ padding: 1em;
160
+ white-space: pre-wrap;
161
+ word-wrap: break-word;
162
+ }
163
+ div.markdown a {
164
+ color: dodgerblue;
165
+ text-decoration: underline;
166
+ text-decoration-color: dodgerblue;
167
+ }
@@ -0,0 +1,112 @@
1
+ @font-face {
2
+ font-family: 'Droid Sans Mono';
3
+ font-style: normal;
4
+ font-weight: 400;
5
+ src: local('Droid Sans Mono'), local('DroidSansMono'), url(/fonts/droidsansmono.v4.woff) format('woff');
6
+ }
7
+ body {
8
+ background-color: #ffffff;
9
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
10
+ font-size: 16px;
11
+ font-weight: 200;
12
+ text-align: left;
13
+ color: #aaaaaa;
14
+ }
15
+ body.preload * {
16
+ -webkit-transition: none !important;
17
+ -moz-transition: none !important;
18
+ -ms-transition: none !important;
19
+ -o-transition: none !important;
20
+ }
21
+ a { text-decoration: none; color: #aaaaaa; }
22
+ div.nav {
23
+ position: fixed;
24
+ z-index: 9998;
25
+ top: 0px; left: 0px;
26
+ width: 100%;
27
+ height: 2em;
28
+ cursor: default;
29
+ background-color: rgba(255, 255, 255, 1);
30
+ }
31
+ div.nav a:hover { cursor: pointer; }
32
+ a.link:hover { background-color: rgba(240, 240, 240, 0.8); }
33
+ div.menu {
34
+ display: none;
35
+ position: fixed;
36
+ top: 2em; right: 0;
37
+ background-color: rgba(255, 255, 255, 1);
38
+ }
39
+ div.nav ul {
40
+ list-style-type: none;
41
+ overflow: hidden;
42
+ margin-top: 0.5em;
43
+ }
44
+ div.nav ul li a {
45
+ cursor: pointer;
46
+ }
47
+ div.nav ul li.link {
48
+ float: left;
49
+ }
50
+ div.nav ul li.control {
51
+ float: right;
52
+ padding-right: 2em;
53
+ }
54
+ div.menu ul {
55
+ list-style-type: none;
56
+ overflow: hidden;
57
+ padding-inline-start: inherit;
58
+ }
59
+ div.menu ul li a {
60
+ display: block;
61
+ cursor: pointer;
62
+ padding: 1em;
63
+ }
64
+ div.menu ul li {
65
+ border-bottom: 1px solid #555555;
66
+ }
67
+ div.menu ul li:last-child {
68
+ border-bottom: none;
69
+ margin-bottom: 0px;
70
+ }
71
+ a.button {
72
+ font-weight: 400;
73
+ -moz-border-radius: 12px;
74
+ border-radius: 12px;
75
+ border-color: #aaaaaa;
76
+ line-height: 40px;
77
+ padding: 8px 16px;
78
+ color: #aaaaaa;
79
+ cursor: pointer;
80
+ }
81
+ a.button:hover {
82
+ text-decoration: none;
83
+ }
84
+ input {
85
+ display: inline;
86
+ width: 50%;
87
+ border: none;
88
+ outline-width: 0px;
89
+ outline-style: none;
90
+ font-family: 'Palatino', 'Georgia', serif;
91
+ letter-spacing: 2px;
92
+ font-size: 1em;
93
+ line-height: 1.5em;
94
+ margin-top: -1px;
95
+ margin-left: -1px;
96
+ color: #333333;
97
+ background-color: rgba(255, 255, 255, 1);
98
+ }
99
+ div.display {
100
+ display: block;
101
+ padding: 1em;
102
+ font-family: 'Palatino', 'Georgia', serif;
103
+ font-size: 1em;
104
+ font-weight: 200;
105
+ letter-spacing: 2px;
106
+ line-height: 1.5em;
107
+ color: #333333;
108
+ }
109
+ div.space {
110
+ padding-bottom: 5em;
111
+ }
112
+ a.direction { cursor: pointer; }
data/web/favicon.ico ADDED
File without changes
Binary file
@@ -0,0 +1,103 @@
1
+ var ansispan = function (str) {
2
+ str = substituteColors(str, ansispan.foregroundColors, 'foreground');
3
+ str = substituteColors(str, ansispan.backgroundColors, 'background');
4
+
5
+ //
6
+ // `\033[1m` enables bold font, `\033[22m` disables it
7
+ //
8
+ str = str.replace(/\033\[1m/g, '<b>').replace(/\033\[22m/g, '</b>');
9
+
10
+ //
11
+ // `\033[3m` enables italics font, `\033[23m` disables it
12
+ //
13
+ str = str.replace(/\033\[3m/g, '<i>').replace(/\033\[23m/g, '</i>');
14
+
15
+ //
16
+ // `\033[4m` enables underline font, `\033[24m` disables it
17
+ //
18
+ str = str.replace(/\033\[4m/g, '<span class="underline">').replace(/\033\[24m/g, '</span>');
19
+
20
+ //
21
+ // NOT SUPPORTED
22
+ // `\033[5m` enables blinking font, `\033[25m` disables it
23
+ //
24
+ str = str.replace(/\033\[5m/g, '<span class="blink">').replace(/\033\[25m/g, '</span>');
25
+
26
+ //
27
+ // NOT SUPPORTED
28
+ // `\033[6m` enables flashing font, `\033[26m` disables it
29
+ //
30
+ str = str.replace(/\033\[6m/g, '<span class="flash">').replace(/\033\[26m/g, '</span>');
31
+
32
+ //
33
+ // NOT SUPPORTED
34
+ // `\033[7m` enables inverse font, `\033[27m` disables it
35
+ //
36
+ str = str.replace(/\033\[7m/g, '<span class="inverse">').replace(/\033\[27m/g, '</span>');
37
+
38
+ //
39
+ // `\033[8m` enables hidden font, `\033[28m` disables it
40
+ //
41
+ str = str.replace(/\033\[8m/g, '<span class="hidden">').replace(/\033\[28m/g, '</span>');
42
+
43
+ //
44
+ // `\033[9m` enables line-through font, `\033[29m` disables it
45
+ //
46
+ str = str.replace(/\033\[9m/g, '<span class="line-through">').replace(/\033\[29m/g, '</span>');
47
+
48
+ //
49
+ // `\033[51m` enables fixed-width font, `\033[56` disables it
50
+ //
51
+ str = str.replace(/\033\[51m/g, '<span class="monospace">').replace(/\033\[56m/g, '</span>');
52
+
53
+ str = str.replace(/\033\[m/g, '</span>');
54
+ str = str.replace(/\033\[39m/g, '</span>');
55
+ str = str.replace(/\033\[49m/g, '</span>');
56
+ return str;
57
+ };
58
+
59
+ var substituteColors = function(str, dictionary, styleKey) {
60
+ styleKey = styleKey ? styleKey : 'foreground'
61
+ Object.keys(dictionary).forEach(function (ansi) {
62
+ var span = '<span class="' + dictionary[ansi] + '-' + styleKey + '">';
63
+
64
+ //
65
+ // `\033[Xm` == `\033[0;Xm` sets color to `X`.
66
+ //
67
+
68
+ str = str.replace(
69
+ new RegExp('\033\\[' + ansi + 'm', 'g'),
70
+ span
71
+ ).replace(
72
+ new RegExp('\033\\[0;' + ansi + 'm', 'g'),
73
+ span
74
+ );
75
+ });
76
+ return str;
77
+ };
78
+
79
+ ansispan.foregroundColors = {
80
+ '30': 'black',
81
+ '31': 'red',
82
+ '32': 'green',
83
+ '33': 'yellow',
84
+ '34': 'dodgerblue',
85
+ '35': 'magenta',
86
+ '36': 'cyan',
87
+ '37': 'white'
88
+ };
89
+
90
+ ansispan.backgroundColors = {
91
+ '40': 'black',
92
+ '41': 'red',
93
+ '42': 'green',
94
+ '43': 'yellow',
95
+ '44': 'dodgerblue',
96
+ '45': 'magenta',
97
+ '46': 'cyan',
98
+ '47': 'white'
99
+ };
100
+
101
+ if (typeof module == "object" && typeof window == "undefined") {
102
+ module.exports = ansispan;
103
+ }
@@ -0,0 +1,144 @@
1
+
2
+ var client = null;
3
+
4
+ $(document).ready(init_client);
5
+
6
+ function init_client() {
7
+ setTheme();
8
+ $('body.preload').removeClass('preload');
9
+ $('input#input, input#password').keydown(input_keydown);
10
+ $('div.display').on('click', 'a.direction', go);
11
+ $(document).mouseup(select_input);
12
+ $(document).keydown(document_keypress);
13
+ $('a#nav-menu').click(menu);
14
+ $('a#nav-style').click(style);
15
+ $('a.menuitem').click(hidemenu);
16
+ $('a#nav-help').click(help);
17
+ $('a#nav-who').click(who);
18
+ client = new Client();
19
+ clearConsole();
20
+ openConnection();
21
+ }
22
+
23
+ var finalize = function() {
24
+ closeConnection();
25
+ };
26
+
27
+ var pageHidden = function() {
28
+ };
29
+
30
+ var document_keypress = function(e) {
31
+ var e = window.event ? window.event : e
32
+ if (e.keyCode == 75 && (e.metaKey || e.ctrlKey) && !e.altKey) {
33
+ clearConsole();
34
+ return false;
35
+ }
36
+ };
37
+
38
+ var input_keydown = function(e) {
39
+ var key = (e.keyCode ? e.keyCode : e.which);
40
+ // var source = e.target || e.srcElement;
41
+ // console.log($(source).attr('id') + ' received ' + key);
42
+
43
+ if (key == 13) { // The key-code for Enter
44
+ input(e.target);
45
+ return false;
46
+ } else if (key == 38) { // Up arrow
47
+ previous_command(e.target);
48
+ return false;
49
+ } else if (key == 40) { // Down arrow
50
+ next_command(e.target);
51
+ return false;
52
+ }
53
+ };
54
+
55
+ var resetConnection = function(event) {
56
+ closeConnection();
57
+ openConnection();
58
+ if (event) {
59
+ event.stopImmediatePropagation();
60
+ event.preventDefault();
61
+ }
62
+ return false;
63
+ };
64
+
65
+ var openConnection = function() {
66
+ if (client == null) return;
67
+ client.open();
68
+ client.socket.onmessage = function(event) {
69
+ receive_message(event.data);
70
+ };
71
+ client.socket.onopen = function(event) {
72
+ log('Connection established.');
73
+ reset();
74
+ client.send("\n");
75
+ focus();
76
+ };
77
+ client.socket.onclose = function(event) {
78
+ log('WebSocket closed.');
79
+ _write('Connection closed by foreign host.');
80
+ }
81
+ focus();
82
+ };
83
+
84
+ var closeConnection = function() {
85
+ if (client == null) return;
86
+ client.close();
87
+ clearConsole();
88
+ };
89
+
90
+ var clearConsole = function(e) {
91
+ clear();
92
+ focus();
93
+ };
94
+
95
+ var style = function(e) {
96
+ var theme = 'console';
97
+ if ($('link#theme').attr('href').match(/console\.css$/)) {
98
+ theme = 'parchment';
99
+ }
100
+ setTheme(theme);
101
+ event.stopImmediatePropagation();
102
+ event.preventDefault();
103
+ focus();
104
+ _scroll();
105
+ return false;
106
+ };
107
+
108
+ var setTheme = function(theme) {
109
+ theme = (theme == undefined) ? readCookie('theme', 'console') : theme;
110
+ if (iphone) $('link#theme').attr({href : 'css/client/' + theme + '.css'});
111
+ else $('link#theme').attr({href : 'css/client/' + theme + '.css'});
112
+ createCookie('theme', theme, 30);
113
+ };
114
+
115
+ var character = function(event) {
116
+ event.stopImmediatePropagation();
117
+ event.preventDefault();
118
+ return false;
119
+ };
120
+
121
+ var menu = function(event) {
122
+ $('div.menu').slideToggle();
123
+ event.stopImmediatePropagation();
124
+ event.preventDefault();
125
+ return false;
126
+ };
127
+
128
+ var hidemenu = function(event) {
129
+ $('div.menu').slideUp();
130
+ };
131
+
132
+ var who = function(event) {
133
+ $('div.menu').slideUp();
134
+ event.stopImmediatePropagation();
135
+ event.preventDefault();
136
+ return false;
137
+ };
138
+
139
+ var help = function(event) {
140
+ $('div.menu').slideUp();
141
+ event.stopImmediatePropagation();
142
+ event.preventDefault();
143
+ return false;
144
+ };