- Created complete documentation in docs/ directory - Added PROJECT_OVERVIEW.md with feature highlights and getting started guide - Added ARCHITECTURE.md with system design and technical details - Added SECURITY.md with comprehensive security implementation guide - Added DEVELOPMENT.md with development workflows and best practices - Added DEPLOYMENT.md with production deployment instructions - Added API.md with complete REST API documentation - Added CONTRIBUTING.md with contribution guidelines - Added CHANGELOG.md with version history and migration notes - Reorganized all documentation files into docs/ directory for better organization - Updated README.md with proper documentation links and quick navigation - Enhanced project structure with professional documentation standards
901 lines
25 KiB
JavaScript
901 lines
25 KiB
JavaScript
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.VMAP = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var ADBreak;
|
|
|
|
ADBreak = (function() {
|
|
function ADBreak() {
|
|
this.breakType = null;
|
|
this.timeOffset = null;
|
|
this.breakId = null;
|
|
this.allowMultipleAds = false;
|
|
this.followRedirects = true;
|
|
this.id = null;
|
|
this.templateType = null;
|
|
this.vastAdData = null;
|
|
this.adTagURI = null;
|
|
this.isWrapper = false;
|
|
this.trackingEvent = null;
|
|
}
|
|
|
|
return ADBreak;
|
|
|
|
})();
|
|
|
|
module.exports = ADBreak;
|
|
|
|
},{}],2:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var ADSource;
|
|
|
|
ADSource = (function() {
|
|
function ADSource() {
|
|
this.allowMultipleAds = false;
|
|
this.followRedirects = false;
|
|
this.id = null;
|
|
this.templateType = null;
|
|
this.vastAdData = null;
|
|
this.adTagURI = null;
|
|
this.isWrapper = false;
|
|
}
|
|
|
|
return ADSource;
|
|
|
|
})();
|
|
|
|
module.exports = ADSource;
|
|
|
|
},{}],3:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var VMAPClient, VMAPParser, VMAPUtil;
|
|
|
|
VMAPParser = require('./parser.coffee');
|
|
|
|
VMAPUtil = require('./vmaputil.coffee');
|
|
|
|
VMAPClient = (function() {
|
|
function VMAPClient() {}
|
|
|
|
VMAPClient.options = {
|
|
withCredentials: true,
|
|
timeout: 0
|
|
};
|
|
|
|
VMAPClient.get = function(url, opts, cb) {
|
|
var extend, options;
|
|
extend = exports.extend = function(object, properties) {
|
|
var key, val;
|
|
for (key in properties) {
|
|
val = properties[key];
|
|
object[key] = val;
|
|
}
|
|
return object;
|
|
};
|
|
if (!cb) {
|
|
if (typeof opts === 'function') {
|
|
cb = opts;
|
|
}
|
|
options = {};
|
|
}
|
|
options = extend(this.options, opts);
|
|
return VMAPParser.parse(url, options, (function(_this) {
|
|
return function(response) {
|
|
return cb(response);
|
|
};
|
|
})(this));
|
|
};
|
|
|
|
return VMAPClient;
|
|
|
|
})();
|
|
|
|
module.exports = VMAPClient;
|
|
|
|
},{"./parser.coffee":5,"./vmaputil.coffee":10}],4:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var EventEmitter, EventTracker, VMAPUtil,
|
|
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
hasProp = {}.hasOwnProperty;
|
|
|
|
VMAPUtil = require('./vmaputil.coffee');
|
|
|
|
EventEmitter = require('events').EventEmitter;
|
|
|
|
EventTracker = (function(superClass) {
|
|
extend(EventTracker, superClass);
|
|
|
|
function EventTracker(trackingEvents) {
|
|
this.trackingEvents = trackingEvents;
|
|
}
|
|
|
|
EventTracker.prototype.breakStart = function() {
|
|
return this.track("breakStart");
|
|
};
|
|
|
|
EventTracker.prototype.breakEnd = function() {
|
|
return this.track("breakEnd");
|
|
};
|
|
|
|
EventTracker.prototype.error = function(error) {
|
|
return this.track("error", false, error);
|
|
};
|
|
|
|
EventTracker.prototype.track = function(eventName, once, variables) {
|
|
var trackingURLTemplates;
|
|
if (once == null) {
|
|
once = false;
|
|
}
|
|
trackingURLTemplates = this.trackingEvents[eventName];
|
|
if (trackingURLTemplates != null) {
|
|
this.trackURLs(trackingURLTemplates);
|
|
}
|
|
if (once === true) {
|
|
delete this.trackingEvents[eventName];
|
|
}
|
|
};
|
|
|
|
EventTracker.prototype.trackURLs = function(URLTemplates, variables) {
|
|
if (variables == null) {
|
|
variables = {};
|
|
}
|
|
return VMAPUtil.track(URLTemplates, variables);
|
|
};
|
|
|
|
return EventTracker;
|
|
|
|
})(EventEmitter);
|
|
|
|
module.exports = EventTracker;
|
|
|
|
},{"./vmaputil.coffee":10,"events":11}],5:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var AdBreak, AdSource, EventEmitter, URLHandler, VMAPParser, VMAPResponse, VMAPUtil;
|
|
|
|
URLHandler = require('./urlhandler.coffee');
|
|
|
|
AdBreak = require('./adbreak.coffee');
|
|
|
|
AdSource = require('./addata.coffee');
|
|
|
|
VMAPResponse = require('./vmapresponse.coffee');
|
|
|
|
EventEmitter = require('events').EventEmitter;
|
|
|
|
VMAPUtil = require('./vmaputil.coffee');
|
|
|
|
VMAPParser = (function() {
|
|
function VMAPParser() {}
|
|
|
|
VMAPParser.parse = function(url, options, cb) {
|
|
if (!cb) {
|
|
if (typeof options === 'function') {
|
|
cb = options;
|
|
}
|
|
options = {};
|
|
}
|
|
return this._parse(url, null, options, function(err, response) {
|
|
return cb(response);
|
|
});
|
|
};
|
|
|
|
VMAPParser.vent = new EventEmitter();
|
|
|
|
VMAPParser.track = function(templates, errorCode) {
|
|
this.vent.emit('VMAP-error', errorCode);
|
|
return VMAPUtil.track(templates, errorCode);
|
|
};
|
|
|
|
VMAPParser._parseSource = function(err, xml, cb) {
|
|
var adBreak, complete, extensions, i, j, len, len1, node, ref, ref1, response;
|
|
if (err != null) {
|
|
return cb(err);
|
|
}
|
|
response = new VMAPResponse();
|
|
response.adbreaks = [];
|
|
if (!(((xml != null ? xml.documentElement : void 0) != null) && ((xml.documentElement.nodeName === 'VMAP') || (xml.documentElement.nodeName === 'vmap:VMAP')))) {
|
|
return cb();
|
|
}
|
|
ref = xml.documentElement.childNodes;
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
|
node = ref[i];
|
|
if (node.nodeName === 'Error') {
|
|
response.errorURLTemplates.push(this.parseNodeText(node));
|
|
}
|
|
}
|
|
ref1 = xml.documentElement.childNodes;
|
|
for (j = 0, len1 = ref1.length; j < len1; j++) {
|
|
node = ref1[j];
|
|
switch (node.nodeName) {
|
|
case "vmap:AdBreak":
|
|
adBreak = this.parseAdBreakElement(node);
|
|
if (adBreak != null) {
|
|
response.adbreaks.push(adBreak);
|
|
} else {
|
|
this.track(response.errorURLTemplates, {
|
|
ERRORCODE: 101
|
|
});
|
|
}
|
|
break;
|
|
case "vmap:Extensions":
|
|
extensions = this.parseExtensionElement(node);
|
|
}
|
|
}
|
|
complete = (function(_this) {
|
|
return function(errorAlreadyRaised) {
|
|
if (errorAlreadyRaised == null) {
|
|
errorAlreadyRaised = false;
|
|
}
|
|
if (!response) {
|
|
return;
|
|
}
|
|
if (response.adbreaks.length === 0) {
|
|
if (!errorAlreadyRaised) {
|
|
_this.track(response.errorURLTemplates, {
|
|
ERRORCODE: 303
|
|
});
|
|
}
|
|
response = null;
|
|
}
|
|
return cb(null, response);
|
|
};
|
|
})(this);
|
|
return complete();
|
|
};
|
|
|
|
VMAPParser._parse = function(url, parentURLs, options, cb) {
|
|
if (!cb) {
|
|
if (typeof options === 'function') {
|
|
cb = options;
|
|
}
|
|
options = {};
|
|
}
|
|
return URLHandler.get(url, options, (function(_this) {
|
|
return function(err, xml) {
|
|
return _this._parseSource(err, xml, cb);
|
|
};
|
|
})(this));
|
|
};
|
|
|
|
|
|
/**
|
|
* Parse extensions field
|
|
* @todo implement extensions
|
|
* @param {node} extensionsElement xml dom node for extensions
|
|
* @return {json} return extensions or xml document
|
|
*/
|
|
|
|
VMAPParser.parseExtensionElement = function(extensionsElement) {
|
|
return null;
|
|
};
|
|
|
|
VMAPParser.parseAdBreakElement = function(adBreakElement) {
|
|
var adBreak, adSource, extensions, i, len, node, ref, trackingEvents;
|
|
adBreak = new AdBreak();
|
|
|
|
/**
|
|
* @todo May contains multiple break type.
|
|
* @type {[type]}
|
|
*/
|
|
adBreak.breakType = adBreakElement.getAttribute("breakType");
|
|
adBreak.breakId = adBreakElement.getAttribute("breakId");
|
|
adBreak.timeOffset = adBreakElement.getAttribute("timeOffset");
|
|
ref = adBreakElement.childNodes;
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
|
node = ref[i];
|
|
switch (node.nodeName) {
|
|
case "vmap:AdSource":
|
|
adSource = this.parseAdSource(node);
|
|
if (adSource) {
|
|
adBreak.allowMultipleAds = adSource.allowMultipleAds;
|
|
adBreak.followRedirects = adSource.followRedirects;
|
|
adBreak.id = adSource.id;
|
|
adBreak.templateType = adSource.templateType;
|
|
adBreak.vastAdData = adSource.vastAdData;
|
|
adBreak.adTagURI = adSource.adTagURI;
|
|
adBreak.isWrapper = adSource.isWrapper;
|
|
}
|
|
break;
|
|
case "vmap:TrackingEvents":
|
|
trackingEvents = this.parseTrackingEvent(node);
|
|
if (trackingEvents) {
|
|
adBreak.trackingEvent = trackingEvents;
|
|
}
|
|
break;
|
|
case "vmap:Extensions":
|
|
extensions = this.parseExtensionElement(node);
|
|
}
|
|
}
|
|
return adBreak;
|
|
};
|
|
|
|
VMAPParser.parseTrackingEvent = function(trackingEventElement) {
|
|
var i, len, ref, trackingElement, trackingEvent;
|
|
trackingEvent = {};
|
|
trackingEvent.breakStart = [];
|
|
trackingEvent.breakEnd = [];
|
|
trackingEvent.error = [];
|
|
ref = trackingEventElement.childNodes;
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
|
trackingElement = ref[i];
|
|
if (trackingElement.getAttribute === void 0) {
|
|
continue;
|
|
}
|
|
switch (trackingElement.getAttribute("event")) {
|
|
case "breakStart":
|
|
trackingEvent.breakStart.push(this.parseNodeText(trackingElement));
|
|
break;
|
|
case "breakEnd":
|
|
trackingEvent.breakEnd.push(this.parseNodeText(trackingElement));
|
|
break;
|
|
case "error":
|
|
trackingEvent.error.push(this.parseNodeText(trackingElement));
|
|
}
|
|
}
|
|
return trackingEvent;
|
|
};
|
|
|
|
VMAPParser.parseAdSource = function(adSourceElement) {
|
|
var adSource, i, len, node, ref;
|
|
adSource = new AdSource();
|
|
adSource.allowMultipleAds = VMAPUtil.parseBoolean(adSourceElement.getAttribute('allowMultipleAds'));
|
|
adSource.followRedirects = VMAPUtil.parseBoolean(adSourceElement.getAttribute('followRedirects'));
|
|
adSource.id = adSourceElement.getAttribute("id");
|
|
ref = adSourceElement.childNodes;
|
|
for (i = 0, len = ref.length; i < len; i++) {
|
|
node = ref[i];
|
|
switch (node.nodeName) {
|
|
case "vmap:VASTData":
|
|
adSource.vastAdData = node.childNodes;
|
|
adSource.templateType = "vast3";
|
|
break;
|
|
case "vmap:AdTagURI":
|
|
adSource.adTagURI = this.parseNodeText(node);
|
|
adSource.templateType = node.getAttribute("templateType");
|
|
adSource.isWrapper = true;
|
|
break;
|
|
case "vmap:CustomAdData":
|
|
adSource.vastAdData = node.childNodes;
|
|
adSource.templateType = node.getAttribute("templateType");
|
|
}
|
|
}
|
|
return adSource;
|
|
};
|
|
|
|
VMAPParser.parseNodeText = function(node) {
|
|
return node && (node.textContent || node.text || '').trim();
|
|
};
|
|
|
|
VMAPParser.isUrl = function(node) {
|
|
return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?\/\/=]*)/i.test(this.parseNodeText(node));
|
|
};
|
|
|
|
return VMAPParser;
|
|
|
|
})();
|
|
|
|
module.exports = VMAPParser;
|
|
|
|
},{"./adbreak.coffee":1,"./addata.coffee":2,"./urlhandler.coffee":6,"./vmapresponse.coffee":9,"./vmaputil.coffee":10,"events":11}],6:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var URLHandler, flash, xhr;
|
|
|
|
xhr = require('./urlhandlers/xmlhttprequest.coffee');
|
|
|
|
flash = require('./urlhandlers/flash.coffee');
|
|
|
|
URLHandler = (function() {
|
|
function URLHandler() {}
|
|
|
|
URLHandler.get = function(url, options, cb) {
|
|
if (!cb) {
|
|
if (typeof options === 'function') {
|
|
cb = options;
|
|
}
|
|
options = {};
|
|
}
|
|
if (options.urlhandler && options.urlhandler.supported()) {
|
|
return options.urlhandler.get(url, options, cb);
|
|
} else if (typeof window === "undefined" || window === null) {
|
|
return require('./urlhandlers/' + 'node.coffee').get(url, options, cb);
|
|
} else if (xhr.supported()) {
|
|
return xhr.get(url, options, cb);
|
|
} else if (flash.supported()) {
|
|
return flash.get(url, options, cb);
|
|
} else {
|
|
return cb();
|
|
}
|
|
};
|
|
|
|
return URLHandler;
|
|
|
|
})();
|
|
|
|
module.exports = URLHandler;
|
|
|
|
},{"./urlhandlers/flash.coffee":7,"./urlhandlers/xmlhttprequest.coffee":8}],7:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var FlashURLHandler;
|
|
|
|
FlashURLHandler = (function() {
|
|
function FlashURLHandler() {}
|
|
|
|
FlashURLHandler.xdr = function() {
|
|
var xdr;
|
|
if (window.XDomainRequest) {
|
|
xdr = new XDomainRequest();
|
|
}
|
|
return xdr;
|
|
};
|
|
|
|
FlashURLHandler.supported = function() {
|
|
return !!this.xdr();
|
|
};
|
|
|
|
FlashURLHandler.get = function(url, options, cb) {
|
|
var xdr, xmlDocument;
|
|
if (xmlDocument = typeof window.ActiveXObject === "function" ? new window.ActiveXObject("Microsoft.XMLDOM") : void 0) {
|
|
xmlDocument.async = false;
|
|
} else {
|
|
return cb();
|
|
}
|
|
xdr = this.xdr();
|
|
xdr.open('GET', url);
|
|
xdr.timeout = options.timeout || 0;
|
|
xdr.withCredentials = options.withCredentials || false;
|
|
xdr.send();
|
|
return xdr.onload = function() {
|
|
xmlDocument.loadXML(xdr.responseText);
|
|
return cb(null, xmlDocument);
|
|
};
|
|
};
|
|
|
|
return FlashURLHandler;
|
|
|
|
})();
|
|
|
|
module.exports = FlashURLHandler;
|
|
|
|
},{}],8:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var XHRURLHandler;
|
|
|
|
XHRURLHandler = (function() {
|
|
function XHRURLHandler() {}
|
|
|
|
XHRURLHandler.xhr = function() {
|
|
var xhr;
|
|
xhr = new window.XMLHttpRequest();
|
|
if ('withCredentials' in xhr) {
|
|
return xhr;
|
|
}
|
|
};
|
|
|
|
XHRURLHandler.supported = function() {
|
|
return !!this.xhr();
|
|
};
|
|
|
|
XHRURLHandler.get = function(url, options, cb) {
|
|
var error, xhr;
|
|
try {
|
|
xhr = this.xhr();
|
|
xhr.open('GET', url);
|
|
xhr.timeout = options.timeout || 0;
|
|
xhr.withCredentials = options.withCredentials || false;
|
|
xhr.send();
|
|
return xhr.onreadystatechange = function() {
|
|
if (xhr.readyState === 4) {
|
|
return cb(null, xhr.responseXML);
|
|
}
|
|
};
|
|
} catch (error) {
|
|
return cb();
|
|
}
|
|
};
|
|
|
|
return XHRURLHandler;
|
|
|
|
})();
|
|
|
|
module.exports = XHRURLHandler;
|
|
|
|
},{}],9:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var VMAPResponse;
|
|
|
|
VMAPResponse = (function() {
|
|
function VMAPResponse() {}
|
|
|
|
VMAPResponse.adbreaks = [];
|
|
|
|
return VMAPResponse;
|
|
|
|
})();
|
|
|
|
module.exports = VMAPResponse;
|
|
|
|
},{}],10:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
var VMAPUtil;
|
|
|
|
VMAPUtil = (function() {
|
|
function VMAPUtil() {}
|
|
|
|
VMAPUtil.track = function(URLTemplates, variables) {
|
|
var URL, URLs, i, j, len, results;
|
|
URLs = this.resolveURLTemplates(URLTemplates, variables);
|
|
results = [];
|
|
for (j = 0, len = URLs.length; j < len; j++) {
|
|
URL = URLs[j];
|
|
if (typeof window !== "undefined" && window !== null) {
|
|
i = new Image();
|
|
results.push(i.src = URL);
|
|
} else {
|
|
|
|
}
|
|
}
|
|
return results;
|
|
};
|
|
|
|
VMAPUtil.resolveURLTemplates = function(URLTemplates, variables) {
|
|
var URLTemplate, URLs, j, key, len, macro1, macro2, resolveURL, value;
|
|
URLs = [];
|
|
if (variables == null) {
|
|
variables = {};
|
|
}
|
|
if (!("CACHEBUSTING" in variables)) {
|
|
variables["CACHEBUSTING"] = Math.round(Math.random() * 1.0e+10);
|
|
}
|
|
variables["random"] = variables["CACHEBUSTING"];
|
|
for (j = 0, len = URLTemplates.length; j < len; j++) {
|
|
URLTemplate = URLTemplates[j];
|
|
resolveURL = URLTemplate;
|
|
if (!resolveURL) {
|
|
continue;
|
|
}
|
|
for (key in variables) {
|
|
value = variables[key];
|
|
macro1 = "[" + key + "]";
|
|
macro2 = "%%" + key + "%%";
|
|
resolveURL = resolveURL.replace(macro1, value);
|
|
resolveURL = resolveURL.replace(macro2, value);
|
|
}
|
|
URLs.push(resolveURL);
|
|
}
|
|
return URLs;
|
|
};
|
|
|
|
VMAPUtil.parseBoolean = function(string) {
|
|
var bool;
|
|
bool = (function() {
|
|
switch (false) {
|
|
case string.toLowerCase() !== 'true':
|
|
return true;
|
|
case string.toLowerCase() !== 'false':
|
|
return false;
|
|
}
|
|
})();
|
|
if (typeof bool === "boolean") {
|
|
return bool;
|
|
}
|
|
return void 0;
|
|
};
|
|
|
|
return VMAPUtil;
|
|
|
|
})();
|
|
|
|
module.exports = VMAPUtil;
|
|
|
|
},{}],11:[function(require,module,exports){
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
// copy of this software and associated documentation files (the
|
|
// "Software"), to deal in the Software without restriction, including
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
// following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included
|
|
// in all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
function EventEmitter() {
|
|
this._events = this._events || {};
|
|
this._maxListeners = this._maxListeners || undefined;
|
|
}
|
|
module.exports = EventEmitter;
|
|
|
|
// Backwards-compat with node 0.10.x
|
|
EventEmitter.EventEmitter = EventEmitter;
|
|
|
|
EventEmitter.prototype._events = undefined;
|
|
EventEmitter.prototype._maxListeners = undefined;
|
|
|
|
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
// added to it. This is a useful default which helps finding memory leaks.
|
|
EventEmitter.defaultMaxListeners = 10;
|
|
|
|
// Obviously not all Emitters should be limited to 10. This function allows
|
|
// that to be increased. Set to zero for unlimited.
|
|
EventEmitter.prototype.setMaxListeners = function(n) {
|
|
if (!isNumber(n) || n < 0 || isNaN(n))
|
|
throw TypeError('n must be a positive number');
|
|
this._maxListeners = n;
|
|
return this;
|
|
};
|
|
|
|
EventEmitter.prototype.emit = function(type) {
|
|
var er, handler, len, args, i, listeners;
|
|
|
|
if (!this._events)
|
|
this._events = {};
|
|
|
|
// If there is no 'error' event listener then throw.
|
|
if (type === 'error') {
|
|
if (!this._events.error ||
|
|
(isObject(this._events.error) && !this._events.error.length)) {
|
|
er = arguments[1];
|
|
if (er instanceof Error) {
|
|
throw er; // Unhandled 'error' event
|
|
}
|
|
throw TypeError('Uncaught, unspecified "error" event.');
|
|
}
|
|
}
|
|
|
|
handler = this._events[type];
|
|
|
|
if (isUndefined(handler))
|
|
return false;
|
|
|
|
if (isFunction(handler)) {
|
|
switch (arguments.length) {
|
|
// fast cases
|
|
case 1:
|
|
handler.call(this);
|
|
break;
|
|
case 2:
|
|
handler.call(this, arguments[1]);
|
|
break;
|
|
case 3:
|
|
handler.call(this, arguments[1], arguments[2]);
|
|
break;
|
|
// slower
|
|
default:
|
|
len = arguments.length;
|
|
args = new Array(len - 1);
|
|
for (i = 1; i < len; i++)
|
|
args[i - 1] = arguments[i];
|
|
handler.apply(this, args);
|
|
}
|
|
} else if (isObject(handler)) {
|
|
len = arguments.length;
|
|
args = new Array(len - 1);
|
|
for (i = 1; i < len; i++)
|
|
args[i - 1] = arguments[i];
|
|
|
|
listeners = handler.slice();
|
|
len = listeners.length;
|
|
for (i = 0; i < len; i++)
|
|
listeners[i].apply(this, args);
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
EventEmitter.prototype.addListener = function(type, listener) {
|
|
var m;
|
|
|
|
if (!isFunction(listener))
|
|
throw TypeError('listener must be a function');
|
|
|
|
if (!this._events)
|
|
this._events = {};
|
|
|
|
// To avoid recursion in the case that type === "newListener"! Before
|
|
// adding it to the listeners, first emit "newListener".
|
|
if (this._events.newListener)
|
|
this.emit('newListener', type,
|
|
isFunction(listener.listener) ?
|
|
listener.listener : listener);
|
|
|
|
if (!this._events[type])
|
|
// Optimize the case of one listener. Don't need the extra array object.
|
|
this._events[type] = listener;
|
|
else if (isObject(this._events[type]))
|
|
// If we've already got an array, just append.
|
|
this._events[type].push(listener);
|
|
else
|
|
// Adding the second element, need to change to array.
|
|
this._events[type] = [this._events[type], listener];
|
|
|
|
// Check for listener leak
|
|
if (isObject(this._events[type]) && !this._events[type].warned) {
|
|
var m;
|
|
if (!isUndefined(this._maxListeners)) {
|
|
m = this._maxListeners;
|
|
} else {
|
|
m = EventEmitter.defaultMaxListeners;
|
|
}
|
|
|
|
if (m && m > 0 && this._events[type].length > m) {
|
|
this._events[type].warned = true;
|
|
console.error('(node) warning: possible EventEmitter memory ' +
|
|
'leak detected. %d listeners added. ' +
|
|
'Use emitter.setMaxListeners() to increase limit.',
|
|
this._events[type].length);
|
|
if (typeof console.trace === 'function') {
|
|
// not supported in IE 10
|
|
console.trace();
|
|
}
|
|
}
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
|
|
EventEmitter.prototype.once = function(type, listener) {
|
|
if (!isFunction(listener))
|
|
throw TypeError('listener must be a function');
|
|
|
|
var fired = false;
|
|
|
|
function g() {
|
|
this.removeListener(type, g);
|
|
|
|
if (!fired) {
|
|
fired = true;
|
|
listener.apply(this, arguments);
|
|
}
|
|
}
|
|
|
|
g.listener = listener;
|
|
this.on(type, g);
|
|
|
|
return this;
|
|
};
|
|
|
|
// emits a 'removeListener' event iff the listener was removed
|
|
EventEmitter.prototype.removeListener = function(type, listener) {
|
|
var list, position, length, i;
|
|
|
|
if (!isFunction(listener))
|
|
throw TypeError('listener must be a function');
|
|
|
|
if (!this._events || !this._events[type])
|
|
return this;
|
|
|
|
list = this._events[type];
|
|
length = list.length;
|
|
position = -1;
|
|
|
|
if (list === listener ||
|
|
(isFunction(list.listener) && list.listener === listener)) {
|
|
delete this._events[type];
|
|
if (this._events.removeListener)
|
|
this.emit('removeListener', type, listener);
|
|
|
|
} else if (isObject(list)) {
|
|
for (i = length; i-- > 0;) {
|
|
if (list[i] === listener ||
|
|
(list[i].listener && list[i].listener === listener)) {
|
|
position = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (position < 0)
|
|
return this;
|
|
|
|
if (list.length === 1) {
|
|
list.length = 0;
|
|
delete this._events[type];
|
|
} else {
|
|
list.splice(position, 1);
|
|
}
|
|
|
|
if (this._events.removeListener)
|
|
this.emit('removeListener', type, listener);
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
|
var key, listeners;
|
|
|
|
if (!this._events)
|
|
return this;
|
|
|
|
// not listening for removeListener, no need to emit
|
|
if (!this._events.removeListener) {
|
|
if (arguments.length === 0)
|
|
this._events = {};
|
|
else if (this._events[type])
|
|
delete this._events[type];
|
|
return this;
|
|
}
|
|
|
|
// emit removeListener for all listeners on all events
|
|
if (arguments.length === 0) {
|
|
for (key in this._events) {
|
|
if (key === 'removeListener') continue;
|
|
this.removeAllListeners(key);
|
|
}
|
|
this.removeAllListeners('removeListener');
|
|
this._events = {};
|
|
return this;
|
|
}
|
|
|
|
listeners = this._events[type];
|
|
|
|
if (isFunction(listeners)) {
|
|
this.removeListener(type, listeners);
|
|
} else {
|
|
// LIFO order
|
|
while (listeners.length)
|
|
this.removeListener(type, listeners[listeners.length - 1]);
|
|
}
|
|
delete this._events[type];
|
|
|
|
return this;
|
|
};
|
|
|
|
EventEmitter.prototype.listeners = function(type) {
|
|
var ret;
|
|
if (!this._events || !this._events[type])
|
|
ret = [];
|
|
else if (isFunction(this._events[type]))
|
|
ret = [this._events[type]];
|
|
else
|
|
ret = this._events[type].slice();
|
|
return ret;
|
|
};
|
|
|
|
EventEmitter.listenerCount = function(emitter, type) {
|
|
var ret;
|
|
if (!emitter._events || !emitter._events[type])
|
|
ret = 0;
|
|
else if (isFunction(emitter._events[type]))
|
|
ret = 1;
|
|
else
|
|
ret = emitter._events[type].length;
|
|
return ret;
|
|
};
|
|
|
|
function isFunction(arg) {
|
|
return typeof arg === 'function';
|
|
}
|
|
|
|
function isNumber(arg) {
|
|
return typeof arg === 'number';
|
|
}
|
|
|
|
function isObject(arg) {
|
|
return typeof arg === 'object' && arg !== null;
|
|
}
|
|
|
|
function isUndefined(arg) {
|
|
return arg === void 0;
|
|
}
|
|
|
|
},{}],12:[function(require,module,exports){
|
|
// Generated by CoffeeScript 1.10.0
|
|
module.exports = {
|
|
client: require('./client.coffee'),
|
|
parser: require('./parser.coffee'),
|
|
util: require('./vmaputil.coffee'),
|
|
tracker: require('./eventtracker.coffee')
|
|
};
|
|
|
|
},{"./client.coffee":3,"./eventtracker.coffee":4,"./parser.coffee":5,"./vmaputil.coffee":10}]},{},[12])(12)
|
|
}); |