kopia lustrzana https://github.com/c9/core
77 wiersze
2.0 KiB
JavaScript
77 wiersze
2.0 KiB
JavaScript
![]() |
/** Sends client side logs to vfs via the websocket connection **/
|
||
|
|
||
|
define(function (require, exports, module) {
|
||
|
"use strict";
|
||
|
|
||
|
main.consumes = ["Plugin", "ext", "c9"];
|
||
|
main.provides = ["vfs.log"];
|
||
|
return main;
|
||
|
|
||
|
function main(options, imports, register) {
|
||
|
var Plugin = imports.Plugin;
|
||
|
var c9 = imports.c9;
|
||
|
var ext = imports.ext;
|
||
|
var plugin = new Plugin("Ajax.org", main.consumes);
|
||
|
|
||
|
var loaded = false;
|
||
|
var server = null;
|
||
|
|
||
|
function load() {
|
||
|
if (loaded) return false;
|
||
|
loaded = true;
|
||
|
|
||
|
ext.loadRemotePlugin("log", {
|
||
|
code: require("text!./log-service.js"),
|
||
|
redefine: true
|
||
|
}, function(err, remote) {
|
||
|
if (err) return console.error(err);
|
||
|
|
||
|
server = remote;
|
||
|
});
|
||
|
|
||
|
c9.on("stateChange", function(e) {
|
||
|
if (e.state & c9.NETWORK) {
|
||
|
load();
|
||
|
}
|
||
|
else {
|
||
|
loaded = false;
|
||
|
server = null;
|
||
|
}
|
||
|
}, plugin);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
function log() {
|
||
|
if (!server) return console.error("Cannot log, client is offline");
|
||
|
|
||
|
var args = Array.prototype.slice.call(arguments);
|
||
|
var message = "";
|
||
|
args.forEach(function (arg) {
|
||
|
if (typeof arg === "object") {
|
||
|
return message += JSON.stringify(arg);
|
||
|
}
|
||
|
message += arg;
|
||
|
});
|
||
|
|
||
|
server.log(message);
|
||
|
}
|
||
|
|
||
|
plugin.on("load", function() {
|
||
|
load();
|
||
|
});
|
||
|
|
||
|
plugin.on("unload", function() {
|
||
|
loaded = false;
|
||
|
server = null;
|
||
|
});
|
||
|
|
||
|
plugin.freezePublicAPI({
|
||
|
log: log
|
||
|
});
|
||
|
|
||
|
register(null, {
|
||
|
"vfs.log": plugin
|
||
|
});
|
||
|
}
|
||
|
})
|