kopia lustrzana https://github.com/c9/core
Refactored bridge to have bi-directional communication and request/response
rodzic
9bc6190ad0
commit
0a86081af0
|
@ -65,7 +65,7 @@
|
|||
"c9.ide.find": "#6cc6d3379d",
|
||||
"c9.ide.find.infiles": "#72582de3cd",
|
||||
"c9.ide.find.replace": "#e4daf722b8",
|
||||
"c9.ide.run.debug": "#638e6b00b3",
|
||||
"c9.ide.run.debug": "#8b903a06d0",
|
||||
"c9.automate": "#47e2c429c9",
|
||||
"c9.ide.ace.emmet": "#e5f1a92ac3",
|
||||
"c9.ide.ace.gotoline": "#4d1a93172c",
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
define(function(require, exports, module) {
|
||||
|
||||
var EventEmitter = require("events").EventEmitter;
|
||||
|
||||
module.exports = function(stream) {
|
||||
var emit = this.emit;
|
||||
|
||||
var buffer = "";
|
||||
stream.on("data", function(chunk) {
|
||||
buffer += chunk;
|
||||
|
||||
var parts = buffer.split("\n");
|
||||
while (parts.length) {
|
||||
try {
|
||||
var message = JSON.parse(buffer[0]);
|
||||
emit("data", { message: message });
|
||||
buffer.shift();
|
||||
}
|
||||
catch (e) {
|
||||
if (parts.length !== 1) {
|
||||
emit("error", e);
|
||||
buffer.shift();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
buffer = parts.join("\n");
|
||||
});
|
||||
|
||||
stream.on("error", function(err){
|
||||
emit("error", err)
|
||||
});
|
||||
|
||||
stream.on("close", function(data){
|
||||
emit("close", data);
|
||||
});
|
||||
|
||||
this.write = function(data){
|
||||
stream.write(JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.prototype = new EventEmitter();
|
||||
|
||||
});
|
Ładowanie…
Reference in New Issue