Skip to content

Commit

Permalink
chore(release): 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
indr committed Feb 12, 2020
1 parent 20906dd commit 3e86731
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 80 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.6.0](https://github.com/indr/webcg-framework/compare/v2.5.0...v2.6.0) (2020-02-12)


### Features

* add support for asynchronous command handling ([20906dd](https://github.com/indr/webcg-framework/commit/20906dda0f0e3d5c156c94dfd8e66c6a18c7b900))


### Bug Fixes

* update [email protected] ([05c0472](https://github.com/indr/webcg-framework/commit/05c047229ad10d1c1f98c21258e8f5696a1d7272))

## [2.5.0](https://github.com/indr/webcg-framework/compare/v2.4.0...v2.5.0) (2020-01-22)


Expand Down
18 changes: 16 additions & 2 deletions dist/webcg-devtools.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
factory();
}((function () { 'use strict';

var version = "1.5.0";
var version = "2.0.0";

/*!
* Vue.js v2.6.11
Expand Down Expand Up @@ -7497,7 +7497,7 @@
}, 0);
}

var STORAGE_KEY_PREFIX = 'webcg-devtools';
var STORAGE_KEY_PREFIX = 'webcg-devtools.' + hashCode('' + window.location.pathname);

function getStorageItem (name, defaultValue) {
try {
Expand All @@ -7517,6 +7517,20 @@
set: setStorageItem
};

// https://stackoverflow.com/a/8831937
function hashCode (str) {
var hash = 0;
if (!str || str.length === 0) {
return hash
}
for (var i = 0; i < str.length; i++) {
var char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
return hash
}

//
//
//
Expand Down
Binary file removed dist/webcg-framework-2.5.0.zip
Binary file not shown.
Binary file added dist/webcg-framework-2.6.0.zip
Binary file not shown.
207 changes: 132 additions & 75 deletions dist/webcg-framework.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,54 @@
factory();
}((function () { 'use strict';

var version = "2.5.0";
var version = "2.6.0";

var Parser = /*@__PURE__*/(function () {
function Parser () {}
var Parser = function Parser () {};

Parser.prototype.parse = function parse (raw) {
if (typeof raw === 'object') { return raw }
if (typeof raw !== 'string') { return null }
if (raw.length <= 0) { return null }
if (raw[0] === '<') {
return this._parseXml(raw)
}
if (raw[0] === '{') {
return JSON.parse(raw)
}
};

Parser.prototype._parseXml = function _parseXml (xmlString) {
var xmlDoc = this._loadXmlDoc(xmlString);
var result = {};
var componentDataElements = xmlDoc.getElementsByTagName('componentData');
for (var i = 0; i < componentDataElements.length; i++) {
var componentId = componentDataElements[i].getAttribute('id');
result[componentId] = {};
var dataElements = componentDataElements[i].getElementsByTagName('data');
for (var ii = 0; ii < dataElements.length; ii++) {
var dataElement = dataElements[ii];
result[componentId][dataElement.getAttribute('id')] = dataElement.getAttribute('value');
}
}
return result
};
Parser.prototype.parse = function parse (raw) {
if (typeof raw === 'object') { return raw }
if (typeof raw !== 'string') { return null }
if (raw.length <= 0) { return null }
if (raw[0] === '<') {
return this._parseXml(raw)
}
if (raw[0] === '{') {
return JSON.parse(raw)
}
};

Parser.prototype._loadXmlDoc = function _loadXmlDoc (xmlString) {
if (window && window.DOMParser && typeof XMLDocument !== 'undefined') {
return new window.DOMParser().parseFromString(xmlString, 'text/xml')
} else {
// Internet Explorer
// eslint-disable-next-line no-undef
var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.loadXML(xmlString);
return xmlDoc
Parser.prototype._parseXml = function _parseXml (xmlString) {
var xmlDoc = this._loadXmlDoc(xmlString);
var result = {};
var componentDataElements = xmlDoc.getElementsByTagName('componentData');
for (var i = 0; i < componentDataElements.length; i++) {
var componentId = componentDataElements[i].getAttribute('id');
result[componentId] = {};
var dataElements = componentDataElements[i].getElementsByTagName('data');
for (var ii = 0; ii < dataElements.length; ii++) {
var dataElement = dataElements[ii];
result[componentId][dataElement.getAttribute('id')] = dataElement.getAttribute('value');
}
};
}
return result
};

return Parser;
}());
Parser.prototype._loadXmlDoc = function _loadXmlDoc (xmlString) {
if (window && window.DOMParser && typeof XMLDocument !== 'undefined') {
return new window.DOMParser().parseFromString(xmlString, 'text/xml')
} else {
// Internet Explorer
// eslint-disable-next-line no-undef
var xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.loadXML(xmlString);
return xmlDoc
}
};

var FUNCTIONS = ['play', 'stop', 'next', 'update'];

var State = Object.freeze({ 'stopped': 0, 'playing': 1 });
var State = Object.freeze({ stopped: 0, playing: 1 });

var WebCG = function WebCG (window) {
var this$1 = this;
Expand All @@ -66,7 +62,9 @@
this$1._window[each].webcg = true;
});
this._state = State.stopped;
this._transitioning = false;
this._bufferCommands = false;
this._commandQueue = [];
};

WebCG.prototype.addEventListener = function addEventListener (type, listener) {
Expand All @@ -93,8 +91,14 @@
};

WebCG.prototype.invokeFunction = function invokeFunction (name) {
if (this._bufferCommand.apply(this, ['_dispatch'].concat(Array.prototype.slice.call(arguments, 0)))) { return }
this._dispatch.apply(this, arguments);
var this$1 = this;

if (this._bufferCommand.apply(this, ['invokeFunction'].concat(Array.from(arguments)))) { return }
this._transitioning = true;
this._dispatch.apply(this, arguments).finally(function () {
this$1._transitioning = false;
this$1._shiftCommand();
});
};

WebCG.prototype.removeEventListener = function removeEventListener (type, listener) {
Expand All @@ -121,47 +125,83 @@
};

WebCG.prototype.flushCommands = function flushCommands () {
var this$1 = this;

this._bufferCommands = false;
this._commandQueue.forEach(function (each) {
this$1[each.name].apply(this$1, each.args);
});
this._commandQueue = [];
this._shiftCommand();
};

WebCG.prototype._shiftCommand = function _shiftCommand () {
if (this._commandQueue.length) {
var command = this._commandQueue.shift();
this[command.name].apply(this, command.args);
}
};

WebCG.prototype.play = function play () {
var this$1 = this;

if (this._bufferCommand('play')) { return }
if (this._state !== State.playing) {
this._dispatch('play');
this._state = State.playing;
this._transitioning = true;
this._dispatch('play').finally(function () {
this$1._transitioning = false;
this$1._state = State.playing;
this$1._shiftCommand();
});
}
};

WebCG.prototype.stop = function stop () {
var this$1 = this;

if (this._bufferCommand('stop')) { return }
if (this._state === State.playing) {
this._dispatch('stop');
this._state = State.stopped;
this._transitioning = true;
this._dispatch('stop').finally(function () {
this$1._transitioning = false;
this$1._state = State.stopped;
this$1._shiftCommand();
});
}
};

WebCG.prototype.next = function next () {
var this$1 = this;

if (this._bufferCommand('next')) { return }
this._dispatch('next');
this._transitioning = true;
this._dispatch('next').finally(function () {
this$1._transitioning = false;
this$1._shiftCommand();
});
};

WebCG.prototype.update = function update (data) {
var this$1 = this;

if (this._bufferCommand('update', data)) { return }
var handled = this._dispatch('update', data);
if (!handled) {
var parsed = new Parser().parse(data);
this._dispatch('data', parsed);
}
this._transitioning = true;
this._dispatch('update', data).then(function (handled) {
this$1._transitioning = false;
if (handled) {
this$1._shiftCommand();
} else {
var parsed = new Parser().parse(data);
this$1._transitioning = true;
this$1._dispatch('data', parsed).finally(function () {
this$1._transitioning = false;
this$1._shiftCommand();
});
}
}).catch(function () {
this$1._transitioning = false;
this$1._shiftCommand();
});
};

WebCG.prototype._bufferCommand = function _bufferCommand (name) {
if (!this._bufferCommands) { return false }
if (!this._transitioning && !this._bufferCommands) {
return false
}
var args = Array.prototype.slice.call(arguments, 1);
this._commandQueue.push({ name: name, args: args });
return true
Expand All @@ -170,18 +210,35 @@
WebCG.prototype._dispatch = function _dispatch (type) {
var listeners = this._getListeners(type);
var args = Array.prototype.slice.call(arguments, 1);
var handled = false;
for (var i = listeners.length - 1; i >= 0 && handled === false; i--) {
var listener = listeners[i];
if (typeof listener !== 'function') { continue }
try {
handled = !!listener.apply(null, args);
} catch (error) {
console.warn(("[webcg-framework] " + type + " event listener threw " + (error.constructor.name) + ": " + (error.message)));
handled = false;
}
}
return handled

var promises = listeners
.filter(function (listener) { return typeof listener === 'function'; })
.map(function (listener) {
return new Promise(function (resolve, reject) {
try {
var result = listener.apply(null, args);
if (result && typeof result === 'object' && Object.getPrototypeOf(result).constructor === Promise) {
result.then(function (handled) {
resolve(!!handled);
}).catch(function (error) {
console.warn(("[webcg-framework] " + type + " event listener threw " + (error.constructor.name) + ": " + (error.message)));
resolve(false);
});
} else {
resolve(!!result);
}
} catch (error) {
console.warn(("[webcg-framework] " + type + " event listener threw " + (error.constructor.name) + ": " + (error.message)));
resolve(false);
}
})
});

return Promise.all(promises).then(function (values) {
return values.reduce(function (aggr, curr) {
return aggr || curr
}, false)
})
};

WebCG.prototype._getListeners = function _getListeners (type) {
Expand Down
2 changes: 1 addition & 1 deletion docs/webcg-framework.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
factory();
}((function () { 'use strict';

var version = "2.5.0";
var version = "2.6.0";

var Parser = function Parser () {};

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webcg-framework",
"version": "2.5.0",
"version": "2.6.0",
"description": "Framework to create HTML templates and graphic overlays for WebCG and CasparCG",
"browser": "dist/webcg-framework.umd.js",
"scripts": {
Expand Down

0 comments on commit 3e86731

Please sign in to comment.