Skip to content

Commit

Permalink
factored out constants into lib/constants.js
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Apr 28, 2011
1 parent 791cd1b commit 58491ba
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
21 changes: 5 additions & 16 deletions index.js
Expand Up @@ -2,22 +2,11 @@
// http://www.realvnc.com/docs/rfbproto.pdf

var EventEmitter = require('events').EventEmitter;

var net = require('net');
var des = require('des');

var Put = require('put');

var Parser = require('./lib/parser');

var clientMsgTypes = {
setPixelFormat : 0,
setEncodings : 2,
fbUpdate : 3,
keyEvent : 4,
pointerEvent : 5,
cutText : 6
};
var constants = require('./lib/constants');

module.exports = function (opts) {
var self = new EventEmitter;
Expand Down Expand Up @@ -63,7 +52,7 @@ module.exports = function (opts) {
};
});

var parser = new Parser(self, stream);
var parser = new Parser(self, opts);

self.write = function (buf) {
if (Buffer.isBuffer(buf)) {
Expand All @@ -84,7 +73,7 @@ module.exports = function (opts) {

self.sendKey = function (key, down) {
Put()
.word8(clientMsgTypes.keyEvent)
.word8(constants.clientMsgTypes.keyEvent)
.word8(!!down)
.pad(2)
.word32be(key)
Expand All @@ -103,7 +92,7 @@ module.exports = function (opts) {

self.sendPointer = function (x, y, mask) {
Put()
.word8(clientMsgTypes.pointerEvent)
.word8(constants.clientMsgTypes.pointerEvent)
.word8(mask)
.word16be(x)
.word16be(y)
Expand All @@ -114,7 +103,7 @@ module.exports = function (opts) {

self.requestUpdate = function (params) {
Put()
.word8(clientMsgTypes.fbUpdate)
.word8(constants.clientMsgTypes.fbUpdate)
.word8(params.subscribe)
.word16be(params.x)
.word16be(params.y)
Expand Down
25 changes: 25 additions & 0 deletions lib/constants.js
@@ -0,0 +1,25 @@
exports.clientMsgTypes = {
setPixelFormat : 0,
setEncodings : 2,
fbUpdate : 3,
keyEvent : 4,
pointerEvent : 5,
cutText : 6,
};

exports.serverMsgTypes = {
fbUpdate : 0,
setColorMap : 1,
bell: 2,
cutText: 3,
};

exports.encodings = {
raw : 0,
copyRect : 1,
rre : 2,
hextile : 5,
zrle : 16,
pseudoCursor : -239,
pseudoDesktopSize : -223,
};
7 changes: 7 additions & 0 deletions lib/handshake.js
@@ -1,3 +1,10 @@
var Put = require('put');
var des = require('des');

var constants = require('./constants');
var clientMsgTypes = constants.clientMsgTypes;
var encodings = constants.encodings;

var exports = module.exports = function (rfb, opts) {
[ 'version', 'security', 'init' ].forEach((function (x) {
exports[x].call(this, rfb, opts);
Expand Down
19 changes: 3 additions & 16 deletions lib/messages.js
Expand Up @@ -6,22 +6,9 @@ var exports = module.exports = function (rfb, opts) {
});
};

var serverMsgTypes = {
fbUpdate : 0,
setColorMap : 1,
bell: 2,
cutText: 3
};

var encodings = {
raw : 0,
copyRect : 1,
rre : 2,
hextile : 5,
zrle : 16,
pseudoCursor : -239,
pseudoDesktopSize : -223
};
var constants = require('./constants');
var serverMsgTypes = constants.serverMsgTypes;
var encodings = constants.encodings;

exports.message = function (rfb, opts) {
this
Expand Down

0 comments on commit 58491ba

Please sign in to comment.