mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
Merge pull request #95 from Arteris/tcp_fallback
Fall back to TCP if socket does not exist
This commit is contained in:
commit
f13a438e94
2 changed files with 41 additions and 22 deletions
|
|
@ -1,6 +1,10 @@
|
||||||
before_script:
|
before_script:
|
||||||
- "export DISPLAY=:99.0"
|
- "export DISPLAY=:99.0"
|
||||||
- "sh -e /etc/init.d/xvfb start"
|
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -nolisten $NOLISTEN"
|
||||||
|
|
||||||
|
env:
|
||||||
|
- NOLISTEN=tcp
|
||||||
|
- NOLISTEN=unix
|
||||||
|
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
|
|
|
||||||
57
lib/xcore.js
57
lib/xcore.js
|
|
@ -20,10 +20,9 @@ var coreRequests = require('./corereqs');
|
||||||
var stdatoms = require('./stdatoms');
|
var stdatoms = require('./stdatoms');
|
||||||
var em = require('./eventmask').eventMask;
|
var em = require('./eventmask').eventMask;
|
||||||
|
|
||||||
function XClient(stream, displayNum, screenNum, options)
|
function XClient(displayNum, screenNum, options)
|
||||||
{
|
{
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
this.stream = stream;
|
|
||||||
this.options = options ? options : {};
|
this.options = options ? options : {};
|
||||||
|
|
||||||
// TODO: this is probably not used
|
// TODO: this is probably not used
|
||||||
|
|
@ -33,6 +32,12 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
this.displayNum = displayNum;
|
this.displayNum = displayNum;
|
||||||
this.screenNum = screenNum;
|
this.screenNum = screenNum;
|
||||||
this.authHost = os.hostname();
|
this.authHost = os.hostname();
|
||||||
|
}
|
||||||
|
util.inherits(XClient, EventEmitter);
|
||||||
|
|
||||||
|
XClient.prototype.init = function(stream)
|
||||||
|
{
|
||||||
|
this.stream = stream;
|
||||||
|
|
||||||
var pack_stream = new PackStream();
|
var pack_stream = new PackStream();
|
||||||
|
|
||||||
|
|
@ -108,7 +113,6 @@ function XClient(stream, displayNum, screenNum, options)
|
||||||
this.startHandshake();
|
this.startHandshake();
|
||||||
this._closing = false;
|
this._closing = false;
|
||||||
}
|
}
|
||||||
util.inherits(XClient, EventEmitter);
|
|
||||||
|
|
||||||
// TODO: close() = set 'closing' flag, watch it in replies and writeQueue, terminate if empty
|
// TODO: close() = set 'closing' flag, watch it in replies and writeQueue, terminate if empty
|
||||||
XClient.prototype.terminate = function()
|
XClient.prototype.terminate = function()
|
||||||
|
|
@ -569,6 +573,8 @@ module.exports.createClient = function(options, initCb)
|
||||||
|
|
||||||
// open stream
|
// open stream
|
||||||
var stream;
|
var stream;
|
||||||
|
var connected = false;
|
||||||
|
var cbCalled = false;
|
||||||
var socketPath;
|
var socketPath;
|
||||||
|
|
||||||
// try local socket on non-windows platforms
|
// try local socket on non-windows platforms
|
||||||
|
|
@ -585,18 +591,35 @@ module.exports.createClient = function(options, initCb)
|
||||||
socketPath = '/tmp/.X11-unix/X' + displayNum;
|
socketPath = '/tmp/.X11-unix/X' + displayNum;
|
||||||
}
|
}
|
||||||
//socketPath = '/tmp/.X11-unix/X' + displayNum;
|
//socketPath = '/tmp/.X11-unix/X' + displayNum;
|
||||||
if(socketPath)
|
var client = new XClient(displayNum, screenNum, options);
|
||||||
{
|
|
||||||
stream = net.createConnection(socketPath);
|
var connectStream = function() {
|
||||||
}
|
if (socketPath) {
|
||||||
else
|
stream = net.createConnection(socketPath);
|
||||||
{
|
} else {
|
||||||
stream = net.createConnection(6000 + parseInt(displayNum), host);
|
stream = net.createConnection(6000 + parseInt(displayNum), host);
|
||||||
}
|
}
|
||||||
var client = new XClient(stream, displayNum, screenNum, options);
|
stream.on('connect', function() {
|
||||||
|
connected = true;
|
||||||
|
client.init(stream);
|
||||||
|
});
|
||||||
|
stream.on('error', function(err) {
|
||||||
|
if (!connected && socketPath && err.code === 'ENOENT') {
|
||||||
|
// Retry connection with TCP on localhost
|
||||||
|
socketPath = null;
|
||||||
|
host = 'localhost';
|
||||||
|
connectStream();
|
||||||
|
} else if (initCb && !cbCalled) {
|
||||||
|
cbCalled = true;
|
||||||
|
initCb(err);
|
||||||
|
} else {
|
||||||
|
client.emit('error', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
connectStream();
|
||||||
if (initCb)
|
if (initCb)
|
||||||
{
|
{
|
||||||
var cbCalled = false;
|
|
||||||
client.on('connect', function(display) {
|
client.on('connect', function(display) {
|
||||||
// opt-in BigReq
|
// opt-in BigReq
|
||||||
if (!options.disableBigRequests) {
|
if (!options.disableBigRequests) {
|
||||||
|
|
@ -614,14 +637,6 @@ module.exports.createClient = function(options, initCb)
|
||||||
initCb(undefined, display);
|
initCb(undefined, display);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
stream.on('error', function(err) {
|
|
||||||
if (cbCalled)
|
|
||||||
client.emit('error', err);
|
|
||||||
else {
|
|
||||||
cbCalled = true;
|
|
||||||
initCb(err);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue