Improved Intel AMT KVM rendering speed.

Ylian Saint-Hilaire committed May 28, 2020 at 03:14 UTC 40abf105abdf6b5d7a3132f71ac7374908902fd4
2 files changed +199 -272
public/scripts/amt-desktop-0.0.2.js
+105 -123
@@ -10,10 +10,10 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
10 obj.canvasid = divid;
11 obj.CanvasId = Q(divid);
12 obj.scrolldiv = scrolldiv;
13 - obj.canvas = Q(divid).getContext("2d");
13 + obj.canvas = Q(divid).getContext('2d');
14 obj.protocol = 2; // KVM
15 obj.state = 0;
16 - obj.acc = "";
16 + obj.acc = null;
17 obj.ScreenWidth = 960;
18 obj.ScreenHeight = 700;
19 obj.width = 0;
@@ -25,8 +25,6 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
25 obj.showmouse = true;
26 obj.buttonmask = 0;
27 obj.localKeyMap = true;
28 - //obj.inbytes = 0;
29 - //obj.outbytes = 0;
28 obj.spare = null;
29 obj.sparew = 0;
30 obj.spareh = 0;
@@ -61,9 +59,6 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
59 obj.inflate = ZLIB.inflateInit(-15);
60 // ###END###{Inflate}
61
64 - // Private method
65 - obj.Debug = function (msg) { console.log(msg); }
66 -
62 obj.xxStateChange = function (newstate) {
63 if (newstate == 0) {
64 obj.canvas.fillStyle = '#000000';
@@ -76,70 +71,78 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
71 }
72 }
73
79 - obj.ProcessData = function (data) {
80 - if (!data) return;
81 - //obj.Debug("KRecv(" + data.length + "): " + rstr2hex(data));
82 - //obj.inbytes += data.length;
83 - //obj.Debug("KRecv(" + obj.inbytes + ")");
84 - obj.acc += data;
85 - while (obj.acc.length > 0) {
86 - //obj.Debug("KAcc(" + obj.acc.length + "): " + rstr2hex(obj.acc));
87 - var cmdsize = 0;
88 - if (obj.state == 0 && obj.acc.length >= 12) {
74 + function arrToStr(arr) { return String.fromCharCode.apply(null, arr); }
75 + function strToArr(str) { var arr = new Uint8Array(str.length); for (var i = 0, j = str.length; i < j; ++i) { arr[i] = str.charCodeAt(i); } return arr }
76 +
77 + obj.ProcessBinaryData = function (data) {
78 + // Append to accumulator
79 + if (obj.acc == null) {
80 + obj.acc = new Uint8Array(data);
81 + } else {
82 + var tmp = new Uint8Array(obj.acc.byteLength + data.byteLength);
83 + tmp.set(obj.acc, 0);
84 + tmp.set(new Uint8Array(data), obj.acc.byteLength);
85 + obj.acc = tmp;
86 + }
87 +
88 + while ((obj.acc != null) && (obj.acc.byteLength > 0)) {
89 + //console.log('KAcc', obj.state, obj.acc);
90 + var cmdsize = 0, accview = new DataView(obj.acc.buffer);
91 + if ((obj.state == 0) && (obj.acc.byteLength >= 12)) {
92 // Getting handshake & version
93 cmdsize = 12;
94 //if (obj.acc.substring(0, 4) != "RFB ") { return obj.Stop(); }
95 //var version = parseFloat(obj.acc.substring(4, 11));
93 - //obj.Debug("KVersion: " + version);
96 + //console.log("KVersion: " + version);
97 obj.state = 1;
95 - obj.send("RFB 003.008\n");
98 + obj.send('RFB 003.008\n');
99 }
97 - else if (obj.state == 1 && obj.acc.length >= 1) {
100 + else if ((obj.state == 1) && (obj.acc.byteLength >= 1)) {
101 // Getting security options
99 - cmdsize = obj.acc.charCodeAt(0) + 1;
102 + cmdsize = obj.acc[0] + 1;
103 obj.send(String.fromCharCode(1)); // Send the "None" security type. Since we already authenticated using redirection digest auth, we don't need to do this again.
104 obj.state = 2;
105 }
103 - else if (obj.state == 2 && obj.acc.length >= 4) {
106 + else if ((obj.state == 2) && (obj.acc.byteLength >= 4)) {
107 // Getting security response
108 cmdsize = 4;
106 - if (ReadInt(obj.acc, 0) != 0) { return obj.Stop(); }
109 + if (accview.getUint32(0) != 0) { return obj.Stop(); }
110 obj.send(String.fromCharCode(1)); // Send share desktop flag
111 obj.state = 3;
112 }
110 - else if (obj.state == 3 && obj.acc.length >= 24) {
113 + else if ((obj.state == 3) && (obj.acc.byteLength >= 24)) {
114 // Getting server init
115 // ###BEGIN###{DesktopRotation}
116 obj.rotation = 0; // We don't currently support screen init while rotated.
117 // ###END###{DesktopRotation}
115 - var namelen = ReadInt(obj.acc, 20);
116 - if (obj.acc.length < 24 + namelen) return;
118 + var namelen = accview.getUint32(20);
119 + if (obj.acc.byteLength < 24 + namelen) return;
120 cmdsize = 24 + namelen;
118 - obj.canvas.canvas.width = obj.rwidth = obj.width = obj.ScreenWidth = ReadShort(obj.acc, 0);
119 - obj.canvas.canvas.height = obj.rheight = obj.height = obj.ScreenHeight = ReadShort(obj.acc, 2);
121 + obj.canvas.canvas.width = obj.rwidth = obj.width = obj.ScreenWidth = accview.getUint16(0);
122 + obj.canvas.canvas.height = obj.rheight = obj.height = obj.ScreenHeight = accview.getUint16(2);
123
124 // These are all values we don't really need, we are going to only run in RGB565 or RGB332 and not use the flexibility provided by these settings.
125 // Makes the javascript code smaller and maybe a bit faster.
126 /*
124 - obj.xbpp = obj.acc.charCodeAt(4);
125 - obj.depth = obj.acc.charCodeAt(5);
126 - obj.bigend = obj.acc.charCodeAt(6);
127 - obj.truecolor = obj.acc.charCodeAt(7);
127 + obj.xbpp = obj.acc[4];
128 + obj.depth = obj.acc[5];
129 + obj.bigend = obj.acc[6];
130 + obj.truecolor = obj.acc[7];
131 obj.rmax = ReadShort(obj.acc, 8);
132 obj.gmax = ReadShort(obj.acc, 10);
133 obj.bmax = ReadShort(obj.acc, 12);
131 - obj.rsh = obj.acc.charCodeAt(14);
132 - obj.gsh = obj.acc.charCodeAt(15);
133 - obj.bsh = obj.acc.charCodeAt(16);
134 + obj.rsh = obj.acc[14];
135 + obj.gsh = obj.acc[15];
136 + obj.bsh = obj.acc[16];
137 var name = obj.acc.substring(24, 24 + namelen);
135 - obj.Debug("name: " + name);
136 - obj.Debug("width: " + obj.width + ", height: " + obj.height);
137 - obj.Debug("bits-per-pixel: " + obj.xbpp);
138 - obj.Debug("depth: " + obj.depth);
139 - obj.Debug("big-endian-flag: " + obj.bigend);
140 - obj.Debug("true-colour-flag: " + obj.truecolor);
141 - obj.Debug("rgb max: " + obj.rmax + "," + obj.gmax + "," + obj.bmax);
142 - obj.Debug("rgb shift: " + obj.rsh + "," + obj.gsh + "," + obj.bsh);
138 + console.log("name: " + name);
139 + console.log("width: " + obj.width + ", height: " + obj.height);
140 + console.log("bits-per-pixel: " + obj.xbpp);
141 + console.log("depth: " + obj.depth);
142 + console.log("big-endian-flag: " + obj.bigend);
143 + console.log("true-colour-flag: " + obj.truecolor);
144 + console.log("rgb max: " + obj.rmax + "," + obj.gmax + "," + obj.bmax);
145 + console.log("rgb shift: " + obj.rsh + "," + obj.gsh + "," + obj.bsh);
146 */
147
148 // SetEncodings, with AMT we can't omit RAW, must be specified.
@@ -170,36 +173,36 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
173 if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); }
174 }
175 else if (obj.state == 4) {
173 - switch (obj.acc.charCodeAt(0)) {
176 + switch (obj.acc[0]) {
177 case 0: // FramebufferUpdate
175 - if (obj.acc.length < 4) return;
176 - obj.state = 100 + ReadShort(obj.acc, 2); // Read the number of tiles that are going to be sent, add 100 and use that as our protocol state.
178 + if (obj.acc.byteLength < 4) return;
179 + obj.state = 100 + accview.getUint16(2); // Read the number of tiles that are going to be sent, add 100 and use that as our protocol state.
180 cmdsize = 4;
181 break;
182 case 2: // This is the bell, do nothing.
183 cmdsize = 1;
184 break;
185 case 3: // This is ServerCutText
183 - if (obj.acc.length < 8) return;
184 - var len = ReadInt(obj.acc, 4) + 8;
185 - if (obj.acc.length < len) return;
186 - cmdsize = handleServerCutText(obj.acc);
186 + if (obj.acc.byteLength < 8) return;
187 + var len = accview.getUint32(4) + 8;
188 + if (obj.acc.byteLength < len) return;
189 + cmdsize = handleServerCutText(obj.acc, accview);
190 break;
191 }
192 }
190 - else if (obj.state > 100 && obj.acc.length >= 12) {
191 - var x = ReadShort(obj.acc, 0),
192 - y = ReadShort(obj.acc, 2),
193 - width = ReadShort(obj.acc, 4),
194 - height = ReadShort(obj.acc, 6),
193 + else if ((obj.state > 100) && (obj.acc.byteLength >= 12)) {
194 + var x = accview.getUint16(0),
195 + y = accview.getUint16(2),
196 + width = accview.getUint16(4),
197 + height = accview.getUint16(6),
198 s = width * height,
196 - encoding = ReadInt(obj.acc, 8);
199 + encoding = accview.getUint32(8);
200
201 if (encoding < 17) {
199 - if (width < 1 || width > 64 || height < 1 || height > 64) { console.log("Invalid tile size (" + width + "," + height + "), disconnecting."); return obj.Stop(); }
202 + if ((width < 1) || (width > 64) || (height < 1) || (height > 64)) { console.log("Invalid tile size (" + width + "," + height + "), disconnecting."); return obj.Stop(); }
203
201 - // Set the spare bitmap to the rigth size if it's not already. This allows us to recycle the spare most if not all the time.
202 - if (obj.sparew != width || obj.spareh != height) {
204 + // Set the spare bitmap to the right size if it's not already. This allows us to recycle the spare most if not all the time.
205 + if ((obj.sparew != width) || (obj.spareh != height)) {
206 obj.sparew = obj.sparew2 = width;
207 obj.spareh = obj.spareh2 = height;
208 // ###BEGIN###{DesktopRotation}
@@ -222,51 +225,43 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
225 obj.send(String.fromCharCode(3, 0, 0, 0, 0, 0) + ShortToStr(obj.width) + ShortToStr(obj.height)); // FramebufferUpdateRequest
226 cmdsize = 12;
227 if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); }
225 - // obj.Debug("New desktop width: " + obj.width + ", height: " + obj.height);
226 - }
227 - else if (encoding == 0) {
228 + //console.log("New desktop width: " + obj.width + ", height: " + obj.height);
229 + } else if (encoding == 0) {
230 // RAW encoding
231 var ptr = 12, cs = 12 + (s * obj.bpp);
230 - if (obj.acc.length < cs) return; // Check we have all the data needed and we can only draw 64x64 tiles.
232 + if (obj.acc.byteLength < cs) return; // Check we have all the data needed and we can only draw 64x64 tiles.
233 cmdsize = cs;
234
235 // CRITICAL LOOP, optimize this as much as possible
236 if (obj.bpp == 2) {
235 - for (var i = 0; i < s; i++) { _setPixel16(obj.acc.charCodeAt(ptr++) + (obj.acc.charCodeAt(ptr++) << 8), i); }
237 + for (var i = 0; i < s; i++) { _setPixel16(accview.getUint16(ptr, true), i); ptr += 2; }
238 } else {
237 - for (var i = 0; i < s; i++) { _setPixel8(obj.acc.charCodeAt(ptr++), i); }
239 + for (var i = 0; i < s; i++) { _setPixel8(obj.acc[ptr++], i); }
240 }
241 _putImage(obj.spare, x, y);
240 - }
241 - else if (encoding == 16) {
242 + } else if (encoding == 16) {
243 // ZRLE encoding
243 - if (obj.acc.length < 16) return;
244 - var datalen = ReadInt(obj.acc, 12);
245 - if (obj.acc.length < (16 + datalen)) return;
246 - //obj.Debug("RECT ZRLE (" + x + "," + y + "," + width + "," + height + ") LEN = " + datalen);
247 - //obj.Debug("RECT ZRLE LEN: " + ReadShortX(obj.acc, 17) + ", DATA: " + rstr2hex(obj.acc.substring(16)));
244 + if (obj.acc.byteLength < 16) return;
245 + var datalen = accview.getUint32(12);
246 + if (obj.acc.byteLength < (16 + datalen)) return;
247
248 // Process the ZLib header if this is the first block
249 var ptr = 16, delta = 5, dx = 0;
250
252 - if (datalen > 5 && obj.acc.charCodeAt(ptr) == 0 && ReadShortX(obj.acc, ptr + 1) == (datalen - delta)) {
251 + if ((datalen > 5) && (obj.acc[ptr] == 0) && (accview.getUint16(ptr + 1, true) == (datalen - delta))) {
252 // This is an uncompressed ZLib data block
253 _decodeLRE(obj.acc, ptr + 5, x, y, width, height, s, datalen);
254 }
255 // ###BEGIN###{Inflate}
256 else {
258 - // This is compressed ZLib data, decompress and process it.
259 - var arr = obj.inflate.inflate(obj.acc.substring(ptr, ptr + datalen - dx));
260 - if (arr.length > 0) { _decodeLRE(arr, 0, x, y, width, height, s, arr.length); } else { obj.Debug("Invalid deflate data"); }
257 + // This is compressed ZLib data, decompress and process it. (TODO: This need to be optimized, remove str/arr conversions)
258 + var str = obj.inflate.inflate(arrToStr(obj.acc.slice(ptr, ptr + datalen - dx)));
259 + if (str.length > 0) { _decodeLRE(strToArr(str), 0, x, y, width, height, s, str.length); } else { console.log("Invalid deflate data"); }
260 }
261 // ###END###{Inflate}
262
263 cmdsize = 16 + datalen;
265 - }
266 - else {
267 - obj.Debug("Unknown Encoding: " + encoding);
268 - return obj.Stop();
269 - }
264 + } else { return obj.Stop(); }
265 if (--obj.state == 100) {
266 obj.state = 4;
267 if (obj.frameRateDelay == 0) {
@@ -277,26 +272,26 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
272 }
273 }
274
275 + //console.log('cmdsize', cmdsize);
276 if (cmdsize == 0) return;
281 - obj.acc = obj.acc.substring(cmdsize);
277 + if (cmdsize != obj.acc.byteLength) { obj.acc = obj.acc.slice(cmdsize); } else { obj.acc = null; }
278 }
279 }
280
281 function _decodeLRE(data, ptr, x, y, width, height, s, datalen) {
286 - var subencoding = data.charCodeAt(ptr++), index, v, runlengthdecode, palette = {}, rlecount = 0, runlength = 0, i;
287 - // obj.Debug("RECT RLE (" + (datalen - 5) + ", " + subencoding + "):" + rstr2hex(data.substring(21, 21 + (datalen - 5))));
282 + var subencoding = data[ptr++], index, v, runlengthdecode, palette = {}, rlecount = 0, runlength = 0, i;
283 if (subencoding == 0) {
284 // RAW encoding
285 if (obj.bpp == 2) {
291 - for (i = 0; i < s; i++) { _setPixel16(data.charCodeAt(ptr++) + (data.charCodeAt(ptr++) << 8), i); }
286 + for (i = 0; i < s; i++) { _setPixel16(data[ptr++] + (data[ptr++] << 8), i); }
287 } else {
293 - for (i = 0; i < s; i++) { _setPixel8(data.charCodeAt(ptr++), i); }
288 + for (i = 0; i < s; i++) { _setPixel8(data[ptr++], i); }
289 }
290 _putImage(obj.spare, x, y);
291 }
292 else if (subencoding == 1) {
293 // Solid color tile
299 - v = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0);
294 + v = data[ptr++] + ((obj.bpp == 2) ? (data[ptr++] << 8) : 0);
295 obj.canvas.fillStyle = 'rgb(' + ((obj.bpp == 1) ? ((v & 224) + ',' + ((v & 28) << 3) + ',' + _fixColor((v & 3) << 6)) : (((v >> 8) & 248) + ',' + ((v >> 3) & 252) + ',' + ((v & 31) << 3))) + ')';
296
297 // ###BEGIN###{DesktopRotation}
@@ -311,24 +306,24 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
306 // Read the palette
307 var br = 4, bm = 15; // br is BitRead and bm is BitMask. By adjusting these two we can support all the variations in this encoding.
308 if (obj.bpp == 2) {
314 - for (i = 0; i < subencoding; i++) { palette[i] = data.charCodeAt(ptr++) + (data.charCodeAt(ptr++) << 8); }
309 + for (i = 0; i < subencoding; i++) { palette[i] = data[ptr++] + (data[ptr++] << 8); }
310 if (subencoding == 2) { br = 1; bm = 1; } else if (subencoding <= 4) { br = 2; bm = 3; } // Compute bits to read & bit mark
316 - while (rlecount < s && ptr < data.length) { v = data.charCodeAt(ptr++); for (i = (8 - br) ; i >= 0; i -= br) { _setPixel16(palette[(v >> i) & bm], rlecount++); } } // Display all the bits
311 + while (rlecount < s && ptr < data.byteLength) { v = data[ptr++]; for (i = (8 - br); i >= 0; i -= br) { _setPixel16(palette[(v >> i) & bm], rlecount++); } } // Display all the bits
312 } else {
318 - for (i = 0; i < subencoding; i++) { palette[i] = data.charCodeAt(ptr++); }
313 + for (i = 0; i < subencoding; i++) { palette[i] = data[ptr++]; }
314 if (subencoding == 2) { br = 1; bm = 1; } else if (subencoding <= 4) { br = 2; bm = 3; } // Compute bits to read & bit mark
320 - while (rlecount < s && ptr < data.length) { v = data.charCodeAt(ptr++); for (i = (8 - br) ; i >= 0; i -= br) { _setPixel8(palette[(v >> i) & bm], rlecount++); } } // Display all the bits
315 + while (rlecount < s && ptr < data.byteLength) { v = data[ptr++]; for (i = (8 - br) ; i >= 0; i -= br) { _setPixel8(palette[(v >> i) & bm], rlecount++); } } // Display all the bits
316 }
317 _putImage(obj.spare, x, y);
318 }
319 else if (subencoding == 128) { // RLE encoded tile
320 if (obj.bpp == 2) {
326 - while (rlecount < s && ptr < data.length) {
321 + while (rlecount < s && ptr < data.byteLength) {
322 // Get the run color
328 - v = data.charCodeAt(ptr++) + (data.charCodeAt(ptr++) << 8);
323 + v = data[ptr++] + (data[ptr++] << 8);
324
325 // Decode the run length. This is the fastest and most compact way I found to do this.
331 - runlength = 1; do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255);
326 + runlength = 1; do { runlength += (runlengthdecode = data[ptr++]); } while (runlengthdecode == 255);
327
328 // Draw a run
329 if (obj.rotation == 0) {
@@ -338,12 +333,12 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
333 }
334 }
335 } else {
341 - while (rlecount < s && ptr < data.length) {
336 + while (rlecount < s && ptr < data.byteLength) {
337 // Get the run color
343 - v = data.charCodeAt(ptr++);
338 + v = data[ptr++];
339
340 // Decode the run length. This is the fastest and most compact way I found to do this.
346 - runlength = 1; do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255);
341 + runlength = 1; do { runlength += (runlengthdecode = data[ptr++]); } while (runlengthdecode == 255);
342
343 // Draw a run
344 if (obj.rotation == 0) {
@@ -358,18 +353,18 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
353 else if (subencoding > 129) { // Palette RLE encoded tile
354 // Read the palette
355 if (obj.bpp == 2) {
361 - for (i = 0; i < (subencoding - 128) ; i++) { palette[i] = data.charCodeAt(ptr++) + (data.charCodeAt(ptr++) << 8); }
356 + for (i = 0; i < (subencoding - 128) ; i++) { palette[i] = data[ptr++] + (data[ptr++] << 8); }
357 } else {
363 - for (i = 0; i < (subencoding - 128) ; i++) { palette[i] = data.charCodeAt(ptr++); }
358 + for (i = 0; i < (subencoding - 128) ; i++) { palette[i] = data[ptr++]; }
359 }
360
361 // Decode RLE on palette
367 - while (rlecount < s && ptr < data.length) {
362 + while (rlecount < s && ptr < data.byteLength) {
363 // Setup the run, get the color index and get the color from the palette.
369 - runlength = 1; index = data.charCodeAt(ptr++); v = palette[index % 128];
364 + runlength = 1; index = data[ptr++]; v = palette[index % 128];
365
366 // If the index starts with high order bit 1, this is a run and decode the run length.
372 - if (index > 127) { do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255); }
367 + if (index > 127) { do { runlength += (runlengthdecode = data[ptr++]); } while (runlengthdecode == 255); }
368
369 // Draw a run
370 if (obj.rotation == 0) {
@@ -582,12 +577,9 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
577 }
578
579 obj.Start = function () {
585 - //obj.Debug("KVM-Start");
580 obj.state = 0;
587 - obj.acc = "";
581 + obj.acc = null;
582 obj.ZRLEfirst = 1;
589 - //obj.inbytes = 0;
590 - //obj.outbytes = 0;
583 // ###BEGIN###{Inflate}
584 obj.inflate.inflateReset();
585 // ###END###{Inflate}
@@ -599,17 +591,8 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
591 for (var i in obj.sparecache) { delete obj.sparecache[i]; }
592 }
593
602 - obj.Stop = function () {
603 - obj.UnGrabMouseInput();
604 - obj.UnGrabKeyInput();
605 - if (obj.parent) { obj.parent.Stop(); }
606 - }
607 -
608 - obj.send = function (x) {
609 - //obj.Debug("KSend(" + x.length + "): " + rstr2hex(x));
610 - //obj.outbytes += x.length;
611 - if (obj.parent) { obj.parent.send(x); }
612 - }
594 + obj.Stop = function () { obj.UnGrabMouseInput(); obj.UnGrabKeyInput(); if (obj.parent) { obj.parent.Stop(); } }
595 + obj.send = function (x) { if (obj.parent) { obj.parent.send(x); } }
596
597 var convertAmtKeyCodeTable = {
598 "Pause": 19,
@@ -748,20 +731,19 @@ var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
731
732 obj.sendkey = function (k, d) {
733 if (typeof k == 'object') {
751 - //for (var i in k) { obj.sendkey(k[i][0], k[i][1]); }
734 var buf = ''; for (var i in k) { buf += (String.fromCharCode(4, k[i][1], 0, 0) + IntToStr(k[i][0])); } obj.send(buf);
735 } else {
736 obj.send(String.fromCharCode(4, d, 0, 0) + IntToStr(k));
737 }
738 }
739
758 - function handleServerCutText(acc) {
759 - if (acc.length < 8) return 0;
760 - var len = ReadInt(obj.acc, 4) + 8;
761 - if (acc.length < len) return 0;
740 + function handleServerCutText(acc, accview) {
741 + if (acc.byteLength < 8) return 0;
742 + var len = accview.getUint32(4) + 8;
743 + if (acc.byteLength < len) return 0;
744 // ###BEGIN###{DesktopInband}
745 if (obj.onKvmData != null) {
764 - var d = acc.substring(8, len);
746 + var d = arrToStr(acc.slice(8, len));
747 if ((d.length >= 16) && (d.substring(0, 15) == '\0KvmDataChannel')) {
748 if (obj.kvmDataSupported == false) { obj.kvmDataSupported = true; console.log('KVM Data Channel Supported.'); }
749 if (((obj.onKvmDataAck == -1) && (d.length == 16)) || (d.charCodeAt(15) != 0)) { obj.onKvmDataAck = true; }
public/scripts/amt-redir-ws-0.1.0.js
+94 -149
@@ -1,7 +1,7 @@
1 /**
2 * @description Intel AMT Redirection Transport Module - using websocket relay
3 * @author Ylian Saint-Hilaire
4 -* @version v0.0.1f
4 +* @version v2.0.0
5 */
6
7 // Construct a MeshServer object
@@ -17,22 +17,19 @@ var CreateAmtRedirect = function (module, authCookie) {
17 obj.port = 0;
18 obj.user = null;
19 obj.pass = null;
20 - obj.authuri = "/RedirectionService";
20 + obj.authuri = '/RedirectionService';
21 obj.tlsv1only = 0;
22 obj.inDataCount = 0;
23 // ###END###{!Mode-Firmware}
24 obj.connectstate = 0;
25 obj.protocol = module.protocol; // 1 = SOL, 2 = KVM, 3 = IDER
26 - obj.debugmode = 0;
27 -
28 - obj.amtaccumulator = "";
26 + obj.acc = null;
27 obj.amtsequence = 1;
28 obj.amtkeepalivetimer = null;
31 -
29 obj.onStateChanged = null;
30
34 - // Private method
35 - //obj.Debug = function (msg) { console.log(msg); }
31 + function arrToStr(arr) { return String.fromCharCode.apply(null, arr); }
32 + function randomHex(length) { var r = ''; for (var i = 0; i < length; i++) { r += 'abcdef0123456789'.charAt(Math.floor(Math.random() * 16)); } return r; }
33
34 obj.Start = function (host, port, user, pass, tls) {
35 obj.host = host;
@@ -41,9 +38,10 @@ var CreateAmtRedirect = function (module, authCookie) {
38 obj.pass = pass;
39 obj.connectstate = 0;
40 obj.inDataCount = 0;
44 - var url = window.location.protocol.replace("http", "ws") + "//" + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/webrelay.ashx?p=2&host=" + host + "&port=" + port + "&tls=" + tls + ((user == '*') ? "&serverauth=1" : "") + ((typeof pass === "undefined") ? ("&serverauth=1&user=" + user) : ""); // The "p=2" indicates to the relay that this is a REDIRECTION session
41 + var url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/webrelay.ashx?p=2&host=' + host + '&port=' + port + '&tls=' + tls + ((user == '*') ? '&serverauth=1' : '') + ((typeof pass === 'undefined') ? ('&serverauth=1&user=' + user) : ''); // The 'p=2' indicates to the relay that this is a REDIRECTION session
42 if ((authCookie != null) && (authCookie != '')) { url += '&auth=' + authCookie; }
43 obj.socket = new WebSocket(url);
44 + obj.socket.binaryType = 'arraybuffer';
45 obj.socket.onopen = obj.xxOnSocketConnected;
46 obj.socket.onmessage = obj.xxOnMessage;
47 obj.socket.onclose = obj.xxOnSocketClosed;
@@ -51,80 +49,44 @@ var CreateAmtRedirect = function (module, authCookie) {
49 }
50
51 obj.xxOnSocketConnected = function () {
54 - //obj.Debug("Redir Socket Connected");
55 - if (obj.debugmode == 1) { console.log('onSocketConnected'); }
52 obj.xxStateChange(2);
57 - if (obj.protocol == 1) obj.xxSend(obj.RedirectStartSol); // TODO: Put these strings in higher level module to tighten code
58 - if (obj.protocol == 2) obj.xxSend(obj.RedirectStartKvm); // Don't need these is the feature is not compiled-in.
59 - if (obj.protocol == 3) obj.xxSend(obj.RedirectStartIder);
60 - }
61 -
62 - // Setup the file reader
63 - var fileReader = new FileReader();
64 - var fileReaderInuse = false, fileReaderAcc = [];
65 - if (fileReader.readAsBinaryString) {
66 - // Chrome & Firefox (Draft)
67 - fileReader.onload = function (e) { obj.xxOnSocketData(e.target.result); if (fileReaderAcc.length == 0) { fileReaderInuse = false; } else { fileReader.readAsBinaryString(new Blob([fileReaderAcc.shift()])); } }
68 - } else if (fileReader.readAsArrayBuffer) {
69 - // Chrome & Firefox (Spec)
70 - fileReader.onloadend = function (e) { obj.xxOnSocketData(e.target.result); if (fileReaderAcc.length == 0) { fileReaderInuse = false; } else { fileReader.readAsArrayBuffer(fileReaderAcc.shift()); } }
53 + if (obj.protocol == 1) obj.directSend(new Uint8Array([0x10, 0x00, 0x00, 0x00, 0x53, 0x4F, 0x4C, 0x20])); // SOL
54 + if (obj.protocol == 2) obj.directSend(new Uint8Array([0x10, 0x01, 0x00, 0x00, 0x4b, 0x56, 0x4d, 0x52])); // KVM
55 + if (obj.protocol == 3) obj.directSend(new Uint8Array([0x10, 0x00, 0x00, 0x00, 0x49, 0x44, 0x45, 0x52])); // IDER
56 }
57
58 obj.xxOnMessage = function (e) {
74 - //if (obj.debugmode == 1) { console.log('Recv', e.data); }
59 + if (!e.data || obj.connectstate == -1) return;
60 obj.inDataCount++;
76 - if (typeof e.data == 'object') {
77 - if (fileReaderInuse == true) { fileReaderAcc.push(e.data); return; }
78 - if (fileReader.readAsBinaryString) {
79 - // Chrome & Firefox (Draft)
80 - fileReaderInuse = true;
81 - fileReader.readAsBinaryString(new Blob([e.data]));
82 - } else if (fileReader.readAsArrayBuffer) {
83 - // Chrome & Firefox (Spec)
84 - fileReaderInuse = true;
85 - fileReader.readAsArrayBuffer(e.data);
86 - } else {
87 - // IE10, readAsBinaryString does not exist, use an alternative.
88 - var binary = "", bytes = new Uint8Array(e.data), length = bytes.byteLength;
89 - for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
90 - obj.xxOnSocketData(binary);
91 - }
92 - } else {
93 - // If we get a string object, it maybe the WebRTC confirm. Ignore it.
94 - // obj.debug("MeshDataChannel - OnData - " + typeof e.data + " - " + e.data.length);
95 - obj.xxOnSocketData(e.data);
61 +
62 + // KVM traffic, forward it directly.
63 + if ((obj.connectstate == 1) && ((obj.protocol == 2) || (obj.protocol == 3))) {
64 + return obj.m.ProcessBinaryData ? obj.m.ProcessBinaryData(e.data) : obj.m.ProcessData(arrToStr(e.data));
65 }
97 - };
98 -
99 - obj.xxOnSocketData = function (data) {
100 - if (!data || obj.connectstate == -1) return;
66
102 - if (typeof data === 'object') {
103 - // This is an ArrayBuffer, convert it to a string array (used in IE)
104 - var binary = "";
105 - var bytes = new Uint8Array(data);
106 - var length = bytes.byteLength;
107 - for (var i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); }
108 - data = binary;
67 + // Append to accumulator
68 + if (obj.acc == null) {
69 + obj.acc = e.data;
70 + } else {
71 + var tmp = new Uint8Array(obj.acc.byteLength + e.data.byteLength);
72 + tmp.set(new Uint8Array(obj.acc), 0);
73 + tmp.set(new Uint8Array(e.data), obj.acc.byteLength);
74 + obj.acc = tmp.buffer;
75 }
110 - else if (typeof data !== 'string') { return; }
76
112 - if ((obj.protocol == 2 || obj.protocol == 3) && obj.connectstate == 1) { return obj.m.ProcessData(data); } // KVM traffic, forward it directly.
113 - obj.amtaccumulator += data;
114 - //obj.Debug("Redir Recv(" + obj.amtaccumulator.length + "): " + rstr2hex(obj.amtaccumulator));
115 - while (obj.amtaccumulator.length >= 1) {
116 - var cmdsize = 0;
117 - switch (obj.amtaccumulator.charCodeAt(0)) {
77 + //console.log('Redir Recv', obj.acc);
78 + while ((obj.acc != null) && (obj.acc.byteLength >= 1)) {
79 + var cmdsize = 0, accArray = new Uint8Array(obj.acc);
80 + switch (accArray[0]) {
81 case 0x11: // StartRedirectionSessionReply (17)
119 - if (obj.amtaccumulator.length < 4) return;
120 - var statuscode = obj.amtaccumulator.charCodeAt(1);
82 + if (accArray.byteLength < 4) return;
83 + var statuscode = accArray[1];
84 switch (statuscode) {
85 case 0: // STATUS_SUCCESS
123 - if (obj.amtaccumulator.length < 13) return;
124 - var oemlen = obj.amtaccumulator.charCodeAt(12);
125 - if (obj.amtaccumulator.length < 13 + oemlen) return;
126 - // Query for available authentication
127 - obj.xxSend(String.fromCharCode(0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)); // Query authentication support
86 + if (accArray.byteLength < 13) return;
87 + var oemlen = accArray[12];
88 + if (accArray.byteLength < 13 + oemlen) return;
89 + obj.directSend(new Uint8Array([0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])); // Query for available authentication
90 cmdsize = (13 + oemlen);
91 break;
92 default:
@@ -133,14 +95,12 @@ var CreateAmtRedirect = function (module, authCookie) {
95 }
96 break;
97 case 0x14: // AuthenticateSessionReply (20)
136 - if (obj.amtaccumulator.length < 9) return;
137 - var authDataLen = ReadIntX(obj.amtaccumulator, 5);
138 - if (obj.amtaccumulator.length < 9 + authDataLen) return;
139 - var status = obj.amtaccumulator.charCodeAt(1);
140 - var authType = obj.amtaccumulator.charCodeAt(4);
141 - var authData = [];
142 - for (i = 0; i < authDataLen; i++) { authData.push(obj.amtaccumulator.charCodeAt(9 + i)); }
143 - var authDataBuf = obj.amtaccumulator.substring(9, 9 + authDataLen);
98 + if (accArray.byteLength < 9) return;
99 + var authDataLen = new DataView(obj.acc).getUint32(5, true);
100 + if (accArray.byteLength < 9 + authDataLen) return;
101 + var status = accArray[1], authType = accArray[4], authData = [];
102 + for (i = 0; i < authDataLen; i++) { authData.push(accArray[9 + i]); }
103 + var authDataBuf = accArray.slice(9, 9 + authDataLen);
104 cmdsize = 9 + authDataLen;
105 if (authType == 0) {
106 // Query
@@ -157,65 +117,67 @@ var CreateAmtRedirect = function (module, authCookie) {
117 obj.xxSend(String.fromCharCode(0x13, 0x00, 0x00, 0x00, 0x01) + IntToStrX(obj.user.length + obj.pass.length + 2) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(obj.pass.length) + obj.pass);
118 }
119 else obj.Stop(2);
160 - }
161 - else if ((authType == 3 || authType == 4) && status == 1) {
120 + } else if (((authType == 3) || (authType == 4)) && (status == 1)) {
121 var curptr = 0;
122
123 // Realm
165 - var realmlen = authDataBuf.charCodeAt(curptr);
166 - var realm = authDataBuf.substring(curptr + 1, curptr + 1 + realmlen);
124 + var realmlen = authDataBuf[curptr];
125 + var realm = arrToStr(authDataBuf.slice(curptr + 1, curptr + 1 + realmlen));
126 curptr += (realmlen + 1);
127
128 // Nonce
170 - var noncelen = authDataBuf.charCodeAt(curptr);
171 - var nonce = authDataBuf.substring(curptr + 1, curptr + 1 + noncelen);
129 + var noncelen = authDataBuf[curptr];
130 + var nonce = arrToStr(authDataBuf.slice(curptr + 1, curptr + 1 + noncelen));
131 curptr += (noncelen + 1);
132
133 // QOP
134 var qoplen = 0;
135 var qop = null;
177 - var cnonce = obj.xxRandomNonce(32);
136 + var cnonce = randomHex(32);
137 var snc = '00000002';
138 var extra = '';
139 if (authType == 4) {
181 - qoplen = authDataBuf.charCodeAt(curptr);
182 - qop = authDataBuf.substring(curptr + 1, curptr + 1 + qoplen);
140 + qoplen = authDataBuf[curptr];
141 + qop = arrToStr(authDataBuf.slice(curptr + 1, curptr + 1 + qoplen));
142 curptr += (qoplen + 1);
184 - extra = snc + ":" + cnonce + ":" + qop + ":";
143 + extra = snc + ':' + cnonce + ':' + qop + ':';
144 }
145
187 - var digest = hex_md5(hex_md5(obj.user + ":" + realm + ":" + obj.pass) + ":" + nonce + ":" + extra + hex_md5("POST:" + obj.authuri));
146 + var digest = hex_md5(hex_md5(obj.user + ':' + realm + ':' + obj.pass) + ':' + nonce + ':' + extra + hex_md5('POST:' + obj.authuri));
147 var totallen = obj.user.length + realm.length + nonce.length + obj.authuri.length + cnonce.length + snc.length + digest.length + 7;
148 if (authType == 4) totallen += (qop.length + 1);
149 var buf = String.fromCharCode(0x13, 0x00, 0x00, 0x00, authType) + IntToStrX(totallen) + String.fromCharCode(obj.user.length) + obj.user + String.fromCharCode(realm.length) + realm + String.fromCharCode(nonce.length) + nonce + String.fromCharCode(obj.authuri.length) + obj.authuri + String.fromCharCode(cnonce.length) + cnonce + String.fromCharCode(snc.length) + snc + String.fromCharCode(digest.length) + digest;
150 if (authType == 4) buf += (String.fromCharCode(qop.length) + qop);
151 obj.xxSend(buf);
193 - }
194 - else
195 - if (status == 0) { // Success
196 - if (obj.protocol == 1) {
197 - // Serial-over-LAN: Send Intel AMT serial settings...
198 - var MaxTxBuffer = 10000;
199 - var TxTimeout = 100;
200 - var TxOverflowTimeout = 0;
201 - var RxTimeout = 10000;
202 - var RxFlushTimeout = 100;
203 - var Heartbeat = 0;//5000;
204 - obj.xxSend(String.fromCharCode(0x20, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + ShortToStrX(MaxTxBuffer) + ShortToStrX(TxTimeout) + ShortToStrX(TxOverflowTimeout) + ShortToStrX(RxTimeout) + ShortToStrX(RxFlushTimeout) + ShortToStrX(Heartbeat) + IntToStrX(0));
205 - }
206 - if (obj.protocol == 2) {
207 - // Remote Desktop: Send traffic directly...
208 - obj.xxSend(String.fromCharCode(0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
209 - }
210 - if (obj.protocol == 3) {
211 - // Remote IDER: Send traffic directly...
212 - obj.connectstate = 1;
213 - obj.xxStateChange(3);
152 + } else if (status == 0) { // Success
153 + switch (obj.protocol) {
154 + case 1: {
155 + // Serial-over-LAN: Send Intel AMT serial settings...
156 + var MaxTxBuffer = 10000;
157 + var TxTimeout = 100;
158 + var TxOverflowTimeout = 0;
159 + var RxTimeout = 10000;
160 + var RxFlushTimeout = 100;
161 + var Heartbeat = 0;//5000;
162 + obj.xxSend(String.fromCharCode(0x20, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + ShortToStrX(MaxTxBuffer) + ShortToStrX(TxTimeout) + ShortToStrX(TxOverflowTimeout) + ShortToStrX(RxTimeout) + ShortToStrX(RxFlushTimeout) + ShortToStrX(Heartbeat) + IntToStrX(0));
163 + break;
164 + }
165 + case 2: {
166 + // Remote Desktop: Send traffic directly...
167 + obj.directSend(new Uint8Array([0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]));
168 + break;
169 + }
170 + case 3: {
171 + // Remote IDER: Send traffic directly...
172 + obj.connectstate = 1;
173 + obj.xxStateChange(3);
174 + break;
175 + }
176 }
177 } else obj.Stop(3);
178 break;
179 case 0x21: // Response to settings (33)
218 - if (obj.amtaccumulator.length < 23) break;
180 + if (accArray.byteLength < 23) break;
181 cmdsize = 23;
182 obj.xxSend(String.fromCharCode(0x27, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + String.fromCharCode(0x00, 0x00, 0x1B, 0x00, 0x00, 0x00));
183 if (obj.protocol == 1) { obj.amtkeepalivetimer = setInterval(obj.xxSendAmtKeepAlive, 2000); }
@@ -223,27 +185,27 @@ var CreateAmtRedirect = function (module, authCookie) {
185 obj.xxStateChange(3);
186 break;
187 case 0x29: // Serial Settings (41)
226 - if (obj.amtaccumulator.length < 10) break;
188 + if (accArray.byteLength < 10) break;
189 cmdsize = 10;
190 break;
191 case 0x2A: // Incoming display data (42)
230 - if (obj.amtaccumulator.length < 10) break;
231 - var cs = (10 + ((obj.amtaccumulator.charCodeAt(9) & 0xFF) << 8) + (obj.amtaccumulator.charCodeAt(8) & 0xFF));
232 - if (obj.amtaccumulator.length < cs) break;
233 - obj.m.ProcessData(obj.amtaccumulator.substring(10, cs));
192 + if (accArray.byteLength < 10) break;
193 + var cs = (10 + (accArray[9] << 8) + accArray[8]);
194 + if (accArray.byteLength < cs) break;
195 + if (obj.m.ProcessBinaryData) { obj.m.ProcessBinaryData(accArray.slice(10, cs)); } else { obj.m.ProcessData(arrToStr(accArray.slice(10, cs))); }
196 cmdsize = cs;
197 break;
198 case 0x2B: // Keep alive message (43)
237 - if (obj.amtaccumulator.length < 8) break;
199 + if (accArray.byteLength < 8) break;
200 cmdsize = 8;
201 break;
202 case 0x41:
241 - if (obj.amtaccumulator.length < 8) break;
203 + if (accArray.byteLength < 8) break;
204 obj.connectstate = 1;
205 obj.m.Start();
206 // KVM traffic, forward rest of accumulator directly.
245 - if (obj.amtaccumulator.length > 8) { obj.m.ProcessData(obj.amtaccumulator.substring(8)); }
246 - cmdsize = obj.amtaccumulator.length;
207 + if (accArray.byteLength > 8) { obj.m.ProcessData(accArray.slice(8)); }
208 + cmdsize = accArray.byteLength;
209 break;
210 case 0xF0:
211 // console.log('Session is being recorded');
@@ -251,19 +213,19 @@ var CreateAmtRedirect = function (module, authCookie) {
213 cmdsize = 1;
214 break;
215 default:
254 - console.log("Unknown Intel AMT command: " + obj.amtaccumulator.charCodeAt(0) + " acclen=" + obj.amtaccumulator.length);
216 + console.log('Unknown Intel AMT command: ' + accArray[0] + ' acclen=' + accArray.byteLength);
217 obj.Stop(4);
218 return;
219 }
220 if (cmdsize == 0) return;
259 - obj.amtaccumulator = obj.amtaccumulator.substring(cmdsize);
221 + if (cmdsize != obj.acc.byteLength) { obj.acc = obj.acc.slice(cmdsize); } else { obj.acc = null; }
222 }
223 }
262 -
224 +
225 + obj.directSend = function (arr) { try { obj.socket.send(arr.buffer); } catch (ex) { } }
226 +
227 obj.xxSend = function (x) {
264 - //obj.Debug("Redir Send(" + x.length + "): " + rstr2hex(x));
265 - if (obj.socket != null && obj.socket.readyState == WebSocket.OPEN) {
266 - if (obj.debugmode == 1) { console.log('Send', x); }
228 + if ((obj.socket != null) && (obj.socket.readyState == WebSocket.OPEN)) {
229 var b = new Uint8Array(x.length);
230 for (var i = 0; i < x.length; ++i) { b[i] = x.charCodeAt(i); }
231 try { obj.socket.send(b.buffer); } catch (ex) { }
@@ -275,24 +237,13 @@ var CreateAmtRedirect = function (module, authCookie) {
237 if (obj.protocol == 1) { obj.xxSend(String.fromCharCode(0x28, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++) + ShortToStrX(x.length) + x); } else { obj.xxSend(x); }
238 }
239
278 - obj.xxSendAmtKeepAlive = function () {
279 - if (obj.socket == null) return;
280 - obj.xxSend(String.fromCharCode(0x2B, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++));
281 - }
282 -
283 - obj.xxRandomNonceX = "abcdef0123456789";
284 - obj.xxRandomNonce = function (length) {
285 - var r = "";
286 - for (var i = 0; i < length; i++) { r += obj.xxRandomNonceX.charAt(Math.floor(Math.random() * obj.xxRandomNonceX.length)); }
287 - return r;
288 - }
240 + obj.xxSendAmtKeepAlive = function () { if (obj.socket != null) { obj.xxSend(String.fromCharCode(0x2B, 0x00, 0x00, 0x00) + IntToStrX(obj.amtsequence++)); } }
241
242 obj.xxOnSocketClosed = function () {
291 - if (obj.debugmode == 1) { console.log('onSocketClosed'); }
292 - //obj.Debug("Redir Socket Closed");
243 if ((obj.inDataCount == 0) && (obj.tlsv1only == 0)) {
244 obj.tlsv1only = 1;
295 - obj.socket = new WebSocket(window.location.protocol.replace("http", "ws") + "//" + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/webrelay.ashx?p=2&host=" + obj.host + "&port=" + obj.port + "&tls=" + obj.tls + "&tls1only=1" + ((obj.user == '*') ? "&serverauth=1" : "") + ((typeof pass === "undefined") ? ("&serverauth=1&user=" + obj.user) : "")); // The "p=2" indicates to the relay that this is a REDIRECTION session
245 + obj.socket = new WebSocket(window.location.protocol.replace('http', 'ws') + '//' + window.location.host + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/webrelay.ashx?p=2&host=' + obj.host + '&port=' + obj.port + '&tls=' + obj.tls + '&tls1only=1' + ((obj.user == '*') ? '&serverauth=1' : '') + ((typeof pass === 'undefined') ? ('&serverauth=1&user=' + obj.user) : '')); // The 'p=2' indicates to the relay that this is a REDIRECTION session
246 + obj.socket.binaryType = 'arraybuffer';
247 obj.socket.onopen = obj.xxOnSocketConnected;
248 obj.socket.onmessage = obj.xxOnMessage;
249 obj.socket.onclose = obj.xxOnSocketClosed;
@@ -301,7 +252,7 @@ var CreateAmtRedirect = function (module, authCookie) {
252 }
253 }
254
304 - obj.xxStateChange = function(newstate) {
255 + obj.xxStateChange = function (newstate) {
256 if (obj.State == newstate) return;
257 obj.State = newstate;
258 obj.m.xxStateChange(obj.State);
@@ -309,18 +260,12 @@ var CreateAmtRedirect = function (module, authCookie) {
260 }
261
262 obj.Stop = function (x) {
312 - if (obj.debugmode == 1) { console.log('onSocketStop', x); }
313 - //obj.Debug("Redir Socket Stopped");
263 obj.xxStateChange(0);
264 obj.connectstate = -1;
316 - obj.amtaccumulator = "";
265 + obj.acc = null;
266 if (obj.socket != null) { obj.socket.close(); obj.socket = null; }
267 if (obj.amtkeepalivetimer != null) { clearInterval(obj.amtkeepalivetimer); obj.amtkeepalivetimer = null; }
268 }
269
321 - obj.RedirectStartSol = String.fromCharCode(0x10, 0x00, 0x00, 0x00, 0x53, 0x4F, 0x4C, 0x20);
322 - obj.RedirectStartKvm = String.fromCharCode(0x10, 0x01, 0x00, 0x00, 0x4b, 0x56, 0x4d, 0x52);
323 - obj.RedirectStartIder = String.fromCharCode(0x10, 0x00, 0x00, 0x00, 0x49, 0x44, 0x45, 0x52);
324 -
270 return obj;
271 }