open file in all connected ides

pull/223/head
nightwing 2015-11-25 14:56:50 +04:00
rodzic 3b1db263ff
commit 099ac56457
2 zmienionych plików z 42 dodań i 21 usunięć

Wyświetl plik

@ -10,7 +10,7 @@ module.exports = function (vfs, options, register) {
function createListenClient(api){
var client = net.connect(SOCKET, function(data){
if (data) api.onData(data);
api.onConnect(client);
});
client.setEncoding("utf8");
client.unref();
@ -36,7 +36,6 @@ module.exports = function (vfs, options, register) {
createListenServer(api);
});
api.onConnect(client);
api.disconnect = function(){
client.end();
@ -45,24 +44,46 @@ module.exports = function (vfs, options, register) {
return client;
}
function createListenServer(api){
// var timeout = setTimeout(function(){
// unixServer.close();
// }, 500);
var unixServer = net.createServer(function(client) {
client.setEncoding("utf8");
function createListenServer(api){
function broadcast(data, client) {
clients.forEach(function(c) {
if (c != client)
c.write(data);
});
}
function registerClient(client) {
if (client.setEncoding)
client.setEncoding("utf8");
client.on("data", function(data){
if (data) api.onData(data);
// TODO add a way for sending message to one client
broadcast(data, client);
});
function cleanup(e) {
var i = clients.indexOf(client);
if (i != -1)
clients.splice(i, 1);
client.removeListener("end", cleanup);
client.removeListener("error", cleanup);
}
client.on("end", cleanup);
client.on("error", cleanup);
client.on("error", function(data){
// console.error("ERROR", api.id, data);
});
api.onConnect(client);
});
clients.push(client);
}
api
var clients = [];
var stream = new Stream();
stream.readable = true;
stream.writable = true;
stream.write = function(e) {
api.onData(e);
};
registerClient(stream);
var unixServer = net.createServer(registerClient);
unixServer.listen(SOCKET);
unixServer.on("error", function(err){
@ -85,6 +106,9 @@ module.exports = function (vfs, options, register) {
stream = new Stream();
stream.readable = true;
stream.writable = true;
stream.write = function(data){
if (client) client.write(data);
};
var client;
var sent = false;
@ -107,10 +131,6 @@ module.exports = function (vfs, options, register) {
// createListenServer
createListenClient(api);
stream.write = function(data){
if (client) client.write(data);
};
},
disconnect: function(){

Wyświetl plik

@ -40,7 +40,8 @@ define(function(require, exports, module) {
e.respond(null, true);
break;
default:
console.error("Unknown Bridge Command: ", message.type);
if (message.type)
console.error("Unknown Bridge Command: ", message.type);
break;
}
}, plugin);