sidorares / node-rfb2

rfb wire protocol client and server
MIT License
139 stars 27 forks source link

Add typescript bindings #15

Closed SerialVelocity closed 7 years ago

SerialVelocity commented 8 years ago

Hey,

Not sure if this is still maintained (works great for me!). Is it possible to add typescript bindings for this library? They need to be checked into https://github.com/DefinitelyTyped/DefinitelyTyped

Cheers, SerialVelocity

vtolstov commented 7 years ago
 function unpackLen(cb) {
    stream.unpack('c', function(lenBytes) {
      var byte1 = lenBytes[0];
      if (byte1 & 0x80) {
        stream.unpack('c', function(lenBytes) {
          var byte2 = lenBytes[0];
          len = byte1 | ( byte2 & 0x7f) << 7;
          if (len &  0x80) {
            stream.unpack('c', function(lenBytes) {
              var byte3 = lenBytes[0];
              len = len | ( byte3 & 0xff) << 14;
            });
          }
          cb(len);
        });
      } else {
        cb(byte1);
      }
    });
  }

  unpackLen(function(len) {
    stream.get(len, function(pngData) {
      rect.subEncoding = 'png'
      rect.pngData = pngData;
      cli.emit('rect', rect);
      cb(rect);
    });

  });
vtolstov commented 7 years ago

successfully connected and authorised remote screen name: QEMU (clodo-mon-x86_64) width:1024 height: 768 buffer.js:262 throw new TypeError(kFromErrorMsg); ^

sidorares commented 7 years ago
 function unpackLen(cb) {
    stream.unpack('c', function(lenBytes) {
      var byte1 = lenBytes[0];
      if (byte1 & 0x80) {
        stream.unpack('c', function(lenBytes) {
          var byte2 = lenBytes[0];
          var len = byte1 | ( byte2 & 0x7f) << 7;
          if (len &  0x80) {
            stream.unpack('c', function(lenBytes) {
              var byte3 = lenBytes[0];
              len = len | ( byte3 & 0xff) << 14;
              cb(len); // without this result is not 'returned' via callback in 3 bytes case
            });
          } else {
            // without "else" it is 'returned' twice
            cb(len);
          }
        });
      } else {
        cb(byte1);
      }
    });
  }
vtolstov commented 7 years ago

@sidorares thanks, but it undefined wit you code. why we use unpack('c') and not capital C ?

vtolstov commented 7 years ago

with C i get lenght and it not undefined..

vtolstov commented 7 years ago

and i check and first rect is the png image =)

vtolstov commented 7 years ago

but next frmae i don't know' wireshark can't determine encoding. i think that qemu send another frame with this encoding.... but i can't get spec about it.

vtolstov commented 7 years ago

hm but it have garbage from beggining..

vtolstov commented 7 years ago

ah.. we need to skip from stream needed bytes that contains len =)

vtolstov commented 7 years ago

i'm stuck to get propet png (from beginning) i need to skip from stream 8 bytes =(

vtolstov commented 7 years ago

@sidorares do you have some thinks about this?