kopia lustrzana https://github.com/c9/core
open file in all connected ides
rodzic
3b1db263ff
commit
099ac56457
|
@ -10,7 +10,7 @@ module.exports = function (vfs, options, register) {
|
||||||
|
|
||||||
function createListenClient(api){
|
function createListenClient(api){
|
||||||
var client = net.connect(SOCKET, function(data){
|
var client = net.connect(SOCKET, function(data){
|
||||||
if (data) api.onData(data);
|
api.onConnect(client);
|
||||||
});
|
});
|
||||||
client.setEncoding("utf8");
|
client.setEncoding("utf8");
|
||||||
client.unref();
|
client.unref();
|
||||||
|
@ -36,7 +36,6 @@ module.exports = function (vfs, options, register) {
|
||||||
createListenServer(api);
|
createListenServer(api);
|
||||||
});
|
});
|
||||||
|
|
||||||
api.onConnect(client);
|
|
||||||
|
|
||||||
api.disconnect = function(){
|
api.disconnect = function(){
|
||||||
client.end();
|
client.end();
|
||||||
|
@ -45,24 +44,46 @@ module.exports = function (vfs, options, register) {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createListenServer(api){
|
function createListenServer(api){
|
||||||
// var timeout = setTimeout(function(){
|
function broadcast(data, client) {
|
||||||
// unixServer.close();
|
clients.forEach(function(c) {
|
||||||
// }, 500);
|
if (c != client)
|
||||||
|
c.write(data);
|
||||||
var unixServer = net.createServer(function(client) {
|
});
|
||||||
client.setEncoding("utf8");
|
}
|
||||||
|
function registerClient(client) {
|
||||||
|
if (client.setEncoding)
|
||||||
|
client.setEncoding("utf8");
|
||||||
|
|
||||||
client.on("data", function(data){
|
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);
|
clients.push(client);
|
||||||
});
|
}
|
||||||
|
|
||||||
api.onConnect(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.listen(SOCKET);
|
||||||
|
|
||||||
unixServer.on("error", function(err){
|
unixServer.on("error", function(err){
|
||||||
|
@ -85,6 +106,9 @@ module.exports = function (vfs, options, register) {
|
||||||
stream = new Stream();
|
stream = new Stream();
|
||||||
stream.readable = true;
|
stream.readable = true;
|
||||||
stream.writable = true;
|
stream.writable = true;
|
||||||
|
stream.write = function(data){
|
||||||
|
if (client) client.write(data);
|
||||||
|
};
|
||||||
|
|
||||||
var client;
|
var client;
|
||||||
var sent = false;
|
var sent = false;
|
||||||
|
@ -107,10 +131,6 @@ module.exports = function (vfs, options, register) {
|
||||||
|
|
||||||
// createListenServer
|
// createListenServer
|
||||||
createListenClient(api);
|
createListenClient(api);
|
||||||
|
|
||||||
stream.write = function(data){
|
|
||||||
if (client) client.write(data);
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
|
|
||||||
disconnect: function(){
|
disconnect: function(){
|
||||||
|
|
|
@ -40,7 +40,8 @@ define(function(require, exports, module) {
|
||||||
e.respond(null, true);
|
e.respond(null, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.error("Unknown Bridge Command: ", message.type);
|
if (message.type)
|
||||||
|
console.error("Unknown Bridge Command: ", message.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}, plugin);
|
}, plugin);
|
||||||
|
|
Ładowanie…
Reference in New Issue