Comparing version 0.1.7 to 0.1.8
@@ -339,3 +339,2 @@ /** | ||
var pendingInitializers = []; | ||
var pendingComponents = []; | ||
@@ -391,3 +390,3 @@ var addInitializerCallback = function(names, cb) { | ||
var compName = componentNames[i]; | ||
if (Instance[compName] || pendingComponents[componentName]) { | ||
if (Instance[compName] || pendingComponents[compName]) { | ||
// component already exists: remove | ||
@@ -397,3 +396,3 @@ componentNames.splice(i, 1); | ||
else { | ||
pendingComponents[componentName] = 1; | ||
pendingComponents[compName] = 1; | ||
} | ||
@@ -423,3 +422,3 @@ } | ||
// ignore already existing components | ||
console.warn('Component was requested more than once: ' + componentName + | ||
console.warn('Component installation was sent more than once: ' + componentName + | ||
' -- Make sure to check (or add checks to) all calls to Tools.requestClientComponents.'); | ||
@@ -442,32 +441,37 @@ componentDefs.splice(i, 1); | ||
// call `onNewComponent` | ||
Instance.forEachComponentOfAnyType(function(component) { | ||
if (component.onNewComponent) { | ||
for (var j = 0; j < componentDefs.length; ++j) { | ||
var componentName = componentDefs[j].Client.FullName; | ||
component.onNewComponent(Instance[componentName]); | ||
} | ||
} | ||
}); | ||
// check for pending callbacks to call | ||
for (var i = pendingInitializers.length-1; i >= 0; --i) { | ||
var init = pendingInitializers[i]; | ||
var done = true; | ||
for (var j = 0; j < init.names.length; ++j) { | ||
if (!Instance[init.names[j]]) { | ||
// this callback is still waiting for components that were not delivered | ||
done = false; | ||
break; | ||
} | ||
} | ||
if (done) { | ||
// all requested components have been loaded | ||
// -> call callback & remove initializer | ||
if (init.cb) { | ||
init.cb(); | ||
} | ||
pendingInitializers.splice(i, 1); | ||
} | ||
} | ||
// we are done initializing, but there are still some host-sent commands | ||
// that are still pending that were sent in the same batch as this | ||
// -> Defer until those commands have been executed | ||
setTimeout(function() { | ||
// call `onNewComponent` | ||
Instance.forEachComponentOfAnyType(function(component) { | ||
if (component.onNewComponent) { | ||
for (var j = 0; j < componentDefs.length; ++j) { | ||
var componentName = componentDefs[j].Client.FullName; | ||
component.onNewComponent(Instance[componentName]); | ||
} | ||
} | ||
}); | ||
// check for pending callbacks to call | ||
for (var i = pendingInitializers.length-1; i >= 0; --i) { | ||
var init = pendingInitializers[i]; | ||
var done = true; | ||
for (var j = 0; j < init.names.length; ++j) { | ||
if (!Instance[init.names[j]]) { | ||
// this callback is still waiting for components that were not delivered | ||
done = false; | ||
break; | ||
} | ||
} | ||
if (done) { | ||
// all requested components have been loaded | ||
// -> call callback & remove initializer | ||
if (init.cb) { | ||
init.cb(); | ||
} | ||
pendingInitializers.splice(i, 1); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -549,5 +553,8 @@ } | ||
app.get(cfg.baseUrl + "*", function(req, res, next) { | ||
// create a domain to avoid fatal catastrophe caused by a single client | ||
// see: http://clock.co.uk/blog/preventing-http-raise-hangup-error-on-destroyed-socket-write-from-crashing-your-nodejs-server | ||
var reqDomain = domain.create(); | ||
// register error handler to avoid application crash | ||
var onError = function(err) { | ||
Shared.Libs.ComponentCommunications.reportConnectionError(req, res, err); | ||
}; | ||
req.on('error', onError); | ||
req.socket.on('error', onError); | ||
@@ -590,2 +597,3 @@ var session = req.session; | ||
refresh: function() { | ||
console.log('Page refresh requested...'); | ||
window.location.reload(); | ||
@@ -592,0 +600,0 @@ } |
@@ -167,2 +167,8 @@ /** | ||
implementations: {}, | ||
__ctor: function() { | ||
this.events = { | ||
connectionError: squishy.createEvent(this) | ||
}; | ||
}, | ||
@@ -197,2 +203,8 @@ /** | ||
/** | ||
* This should be called if there was any connection error. | ||
*/ | ||
reportConnectionError: function(req, res, err) { | ||
this.events.connectionError.fire(req, res, err); | ||
}, | ||
@@ -479,3 +491,3 @@ Private: { | ||
var sendBufferToHost = function() { | ||
// send out buffer | ||
// send out buffer; | ||
thisInstance.getDefaultConnection().sendCommandsToHost(buffer); | ||
@@ -569,5 +581,8 @@ | ||
var cb = function(req, res, next) { | ||
req.on('error', function(err) { | ||
console.warn('Connection error: ' + err); | ||
}); | ||
// register error handler | ||
var onError = function(err) { | ||
Shared.Libs.ComponentCommunications.reportConnectionError(req, res, err); | ||
}; | ||
req.on('error', onError); | ||
req.socket.on('error', onError); | ||
@@ -617,3 +632,3 @@ // extract body data | ||
// put command action | ||
// execute actions | ||
Instance.Libs.ComponentCommunications.executeCommandRequest(commands, res); | ||
@@ -624,3 +639,6 @@ }.bind(this)); | ||
// register router callback | ||
app.post(cfg.baseUrl, cb); | ||
app.post(cfg.baseUrl, cb) | ||
.on('error', function(err) { | ||
console.error('Connection error during HTTP get: ' + err); | ||
});; | ||
}, | ||
@@ -680,5 +698,2 @@ | ||
var xhReq = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); | ||
// convert commands to JSON | ||
var contents = JSON.stringify(commands); | ||
@@ -719,4 +734,4 @@ // send out the command request | ||
// send actual content | ||
xhReq.send(contents); | ||
// send commands in JSON format | ||
xhReq.send(JSON.stringify(commands)); | ||
} | ||
@@ -723,0 +738,0 @@ } |
@@ -504,6 +504,18 @@ /** | ||
// if we catch it through the global error handler, and often only after a second try. | ||
window.onerror = function(message, filename, lineno, colno, error) { | ||
console.error('An error has occured. If you do not see a meaningful stacktrace, refresh once ' + | ||
'(the first raised error in the window usually does not stick the landing, at least in Chrome).'); | ||
}; | ||
if (typeof(window) !== undefined) { | ||
window.onerror = function(message, filename, lineno, colno, error) { | ||
console.error('An error has occured. If you do not see a meaningful stacktrace, refresh once ' + | ||
'(the first raised error in the window usually does not stick the landing, at least in Chrome).'); | ||
}; | ||
console.log('Bootstraping NoGap' + (window.top.document !== document ? ' (inside iframe)' : '') + '...'); | ||
} | ||
else { | ||
console.log('Bootstraping NoGap...'); | ||
} | ||
if (squishy.getGlobalContext().nogapInstalled) { | ||
console.error(new Error('INTERNAL ERROR: NoGap tried to install itself twice.').stack); | ||
} | ||
squishy.getGlobalContext().nogapInstalled = 1; | ||
@@ -510,0 +522,0 @@ // get stuff from clientData |
@@ -68,3 +68,5 @@ /** | ||
*/ | ||
Tools.requestClientComponents = Instance.Libs.ComponentBootstrap.requestClientComponents.bind(Instance.Libs.ComponentBootstrap); | ||
Tools.requestClientComponents = function(namessss) { | ||
Instance.Libs.ComponentBootstrap.requestClientComponents.apply(Instance.Libs.ComponentBootstrap, arguments); | ||
}; | ||
@@ -71,0 +73,0 @@ /** |
{ | ||
"name": "nogap", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"author": { | ||
@@ -18,6 +18,4 @@ "name": "Dominik Seifert", | ||
}, | ||
"devDependencies": { | ||
}, | ||
"scripts": { | ||
}, | ||
"devDependencies": {}, | ||
"scripts": {}, | ||
"engines": { | ||
@@ -24,0 +22,0 @@ "node": ">= 0.8.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
322220
4243