Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@meyer/hyperdeck-emulator

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meyer/hyperdeck-emulator - npm Package Compare versions

Comparing version 0.0.4-canary.24.60511e7 to 0.0.4-canary.25.5372bb6

dist/invariant.d.ts

590

dist/hyperdeck-emulator.cjs.development.js

@@ -8,3 +8,3 @@ 'use strict';

var events = require('events');
var util = require('util');
var util = _interopDefault(require('util'));
var net = require('net');

@@ -170,40 +170,43 @@ var pino = _interopDefault(require('pino'));

function invariant(condition, message) {
if (!condition) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
throw new Error(util.format.apply(util, [message].concat(args)));
}
}
var _responseNamesByCode;
var CRLF = '\r\n';
var TResponse = /*#__PURE__*/function () {
function TResponse(code, params) {
this.code = code;
this.params = params;
this.name = responseNamesByCode[code];
}
var TResponse = function TResponse(code, params) {
var _this = this;
var _proto = TResponse.prototype;
this.code = code;
this.params = params;
_proto.build = function build() {
var data = util.format('%d %s', this.code, this.name);
this.build = function () {
return messageForCode(_this.code, _this.params);
};
if (this.params) {
data += ':' + CRLF;
!responseNamesByCode.hasOwnProperty(code) ? invariant(false, 'Invalid code: `%o`', code) : void 0;
this.name = responseNamesByCode[code];
};
var formatClipsGetResponse = function formatClipsGetResponse(res) {
var clipsCount = res.clips.length;
var response = {
clipsCount: clipsCount
};
for (var _i = 0, _Object$entries = Object.entries(this.params); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _Object$entries[_i],
key = _Object$entries$_i[0],
value = _Object$entries$_i[1];
for (var idx = 0; idx < clipsCount; idx++) {
var clip = res.clips[idx];
var clipKey = (idx + 1).toString();
response[clipKey] = clip.name + " " + clip.startT + " " + clip.duration;
}
if (!value) {
continue;
}
data += util.format('%s: %s', key, value) + CRLF;
}
}
data += CRLF;
return data;
};
return TResponse;
}();
return response;
};
var ErrorResponse = function ErrorResponse(code, message) {
var _this = this;
var _this2 = this;

@@ -214,4 +217,6 @@ this.code = code;

this.build = function () {
return util.format('%d %s', _this.code, _this.message);
return _this2.code + ' ' + _this2.message + CRLF;
};
!responseNamesByCode.hasOwnProperty(code) ? invariant(false, 'Invalid code: `%o`', code) : void 0;
};

@@ -302,2 +307,62 @@

var responseNamesByCode = (_responseNamesByCode = {}, _responseNamesByCode[exports.AsynchronousCode.ConfigurationInfo] = 'configuration info', _responseNamesByCode[exports.AsynchronousCode.ConnectionInfo] = 'connection info', _responseNamesByCode[exports.AsynchronousCode.RemoteInfo] = 'remote info', _responseNamesByCode[exports.AsynchronousCode.SlotInfo] = CommandNames.SlotInfoCommand, _responseNamesByCode[exports.AsynchronousCode.TransportInfo] = CommandNames.TransportInfoCommand, _responseNamesByCode[exports.ErrorCode.ConnectionRejected] = 'connection rejected', _responseNamesByCode[exports.ErrorCode.DiskError] = 'disk error', _responseNamesByCode[exports.ErrorCode.DiskFull] = 'disk full', _responseNamesByCode[exports.ErrorCode.FormatNotPrepared] = 'format not prepared', _responseNamesByCode[exports.ErrorCode.InternalError] = 'internal error', _responseNamesByCode[exports.ErrorCode.InvalidCodec] = 'invalid codec', _responseNamesByCode[exports.ErrorCode.InvalidFormat] = 'invalid format', _responseNamesByCode[exports.ErrorCode.InvalidState] = 'invalid state', _responseNamesByCode[exports.ErrorCode.InvalidToken] = 'invalid token', _responseNamesByCode[exports.ErrorCode.InvalidValue] = 'invalid value', _responseNamesByCode[exports.ErrorCode.NoDisk] = 'no disk', _responseNamesByCode[exports.ErrorCode.NoInput] = 'no input', _responseNamesByCode[exports.ErrorCode.OutOfRange] = 'out of range', _responseNamesByCode[exports.ErrorCode.RemoteControlDisabled] = 'remote control disabled', _responseNamesByCode[exports.ErrorCode.SyntaxError] = 'syntax error', _responseNamesByCode[exports.ErrorCode.TimelineEmpty] = 'timeline empty', _responseNamesByCode[exports.ErrorCode.Unsupported] = 'unsupported', _responseNamesByCode[exports.ErrorCode.UnsupportedParameter] = 'unsupported parameter', _responseNamesByCode[exports.SynchronousCode.ClipsCount] = CommandNames.ClipsCountCommand, _responseNamesByCode[exports.SynchronousCode.ClipsInfo] = 'clips info', _responseNamesByCode[exports.SynchronousCode.Configuration] = CommandNames.ConfigurationCommand, _responseNamesByCode[exports.SynchronousCode.DeviceInfo] = CommandNames.DeviceInfoCommand, _responseNamesByCode[exports.SynchronousCode.DiskList] = CommandNames.DiskListCommand, _responseNamesByCode[exports.SynchronousCode.FormatReady] = 'format ready', _responseNamesByCode[exports.SynchronousCode.Notify] = CommandNames.NotifyCommand, _responseNamesByCode[exports.SynchronousCode.OK] = 'ok', _responseNamesByCode[exports.SynchronousCode.Remote] = CommandNames.RemoteCommand, _responseNamesByCode[exports.SynchronousCode.SlotInfo] = CommandNames.SlotInfoCommand, _responseNamesByCode[exports.SynchronousCode.TransportInfo] = CommandNames.TransportInfoCommand, _responseNamesByCode[exports.SynchronousCode.Uptime] = CommandNames.UptimeCommand, _responseNamesByCode);
var Timecode = /*#__PURE__*/function () {
function Timecode(hh, mm, ss, ff) {
this._timecode = [hh, mm, ss, ff].map(function (code) {
var codeInt = Math.floor(code);
if (codeInt !== code || code < 0 || code > 99) {
throw new Error('Timecode params must be an integer between 0 and 99');
} // turn the integer into a potentially zero-prefixed string
return (codeInt + 100).toString().slice(-2);
}).join(':');
}
var _proto = Timecode.prototype;
_proto.toString = function toString() {
return this._timecode;
};
return Timecode;
}();
var messageForCode = function messageForCode(code, params) {
var firstLine = code + " " + responseNamesByCode[code]; // bail if no params
if (!params) {
return firstLine + CRLF;
} // filter out params with null/undefined values
var paramEntries = Object.entries(params).filter(function (_ref) {
var value = _ref[1];
return value != null;
}); // bail if no params after filtering
if (paramEntries.length === 0) {
return firstLine + CRLF;
} // turn the params object into a key/value
return paramEntries.reduce(function (prev, _ref2) {
var key = _ref2[0],
value = _ref2[1];
var valueString;
if (typeof value === 'string') {
valueString = value;
} else if (typeof value === 'boolean') {
valueString = value ? 'true' : 'false';
} else if (typeof value === 'number') {
valueString = value.toString();
} else {
throw new Error('Unhandled value type: ' + typeof value);
} // convert camelCase keys to space-separated words
var formattedKey = key.replace(/([a-z])([A-Z]+)/, '$1 $2').toLowerCase();
return prev + formattedKey + ': ' + valueString + CRLF;
}, firstLine + ':' + CRLF) + CRLF;
};
var ParameterMap = {

@@ -334,3 +399,2 @@ help: [],

};
var SlotStatus;

@@ -342,3 +406,3 @@ (function (SlotStatus) {

SlotStatus["MOUNTED"] = "mounted";
})(SlotStatus || (SlotStatus = {}));
})(exports.SlotStatus || (exports.SlotStatus = {}));

@@ -412,3 +476,3 @@ (function (VideoFormat) {

this._log = logger.child({
source: 'MultilineParser'
name: 'MultilineParser'
});

@@ -562,3 +626,3 @@ }

};
_this._parser = new MultilineParser(_this.logger);
_this._parser = new MultilineParser(logger);

@@ -582,3 +646,3 @@ _this._socket.setEncoding('utf-8');

_this.sendResponse(new TResponse(exports.AsynchronousCode.ConnectionInfo, {
'protocol version': '1.6',
'protocol version': '1.11',
model: 'NodeJS Hyperdeck Server Library'

@@ -595,3 +659,5 @@ }));

this.logger.debug('onMessage(%s)', data);
this.logger.info({
data: data
}, 'onMessage');
this._lastReceived = Date.now();

@@ -601,5 +667,7 @@

this.logger.debug('commands:', cmds);
this.logger.info({
cmds: cmds
}, 'commands');
for (var _iterator = _createForOfIteratorHelperLoose(cmds), _step; !(_step = _iterator()).done;) {
var _loop = function _loop() {
var cmd = _step.value;

@@ -609,20 +677,18 @@

if (cmd.name === CommandNames.WatchdogCommand) {
(function () {
if (_this2._watchdogTimer) clearInterval(_this2._watchdogTimer);
var watchdogCmd = cmd;
if (_this2._watchdogTimer) clearInterval(_this2._watchdogTimer);
var watchdogCmd = cmd;
if (watchdogCmd.parameters.period) {
_this2._watchdogTimer = setInterval(function () {
if (Date.now() - _this2._lastReceived > Number(watchdogCmd.parameters.period)) {
_this2._socket.destroy();
if (watchdogCmd.parameters.period) {
_this2._watchdogTimer = setInterval(function () {
if (Date.now() - _this2._lastReceived > Number(watchdogCmd.parameters.period)) {
_this2._socket.destroy();
_this2.emit('disconnected');
_this2.emit('disconnected');
if (_this2._watchdogTimer) {
clearInterval(_this2._watchdogTimer);
}
if (_this2._watchdogTimer) {
clearInterval(_this2._watchdogTimer);
}
}, Number(watchdogCmd.parameters.period) * 1000);
}
})();
}
}, Number(watchdogCmd.parameters.period) * 1000);
}
} else if (cmd.name === CommandNames.NotifyCommand) {

@@ -635,4 +701,4 @@ var notifyCmd = cmd;

if (this._notifySettings[param] !== undefined) {
this._notifySettings[param] = notifyCmd.parameters[param] === 'true';
if (_this2._notifySettings[param] !== undefined) {
_this2._notifySettings[param] = notifyCmd.parameters[param] === 'true';
}

@@ -643,35 +709,50 @@ }

for (var _i2 = 0, _Object$keys2 = Object.keys(this._notifySettings); _i2 < _Object$keys2.length; _i2++) {
for (var _i2 = 0, _Object$keys2 = Object.keys(_this2._notifySettings); _i2 < _Object$keys2.length; _i2++) {
var key = _Object$keys2[_i2];
settings[key] = this._notifySettings[key] ? 'true' : 'false';
settings[key] = _this2._notifySettings[key] ? 'true' : 'false';
}
this.sendResponse(new TResponse(exports.SynchronousCode.Notify, settings));
continue;
_this2.sendResponse(new TResponse(exports.SynchronousCode.Notify, settings), cmd);
return "continue";
}
}
this._receivedCommand(cmd).then(function (res) {
_this2.logger.info({
res: res
}, '_receivedCommand response');
_this2._receivedCommand(cmd).then(function (res) {
return _this2.sendResponse(res, cmd);
}, // not implemented by client code:
function () {
return _this2.sendResponse(new TResponse(exports.ErrorCode.Unsupported), cmd);
});
};
_this2.sendResponse(res);
}, function () {
_this2.logger.error({}, '_receivedCommand error response'); // not implemented by client code:
for (var _iterator = _createForOfIteratorHelperLoose(cmds), _step; !(_step = _iterator()).done;) {
var _ret = _loop();
_this2.sendResponse(new TResponse(exports.ErrorCode.Unsupported));
});
if (_ret === "continue") continue;
}
};
_proto.sendResponse = function sendResponse(res) {
var msg = res.build();
_proto.sendResponse = function sendResponse(res, cmd) {
var responseText = res.build();
var txt = '--> ' + ((cmd === null || cmd === void 0 ? void 0 : cmd.name) || 'sendResponse');
this._socket.write(msg);
if (res instanceof TResponse && exports.ErrorCode[res.code]) {
this.logger.error({
responseText: responseText
}, txt);
} else {
this.logger.info({
responseText: responseText
}, txt);
}
this._socket.write(responseText);
};
_proto.notify = function notify(type, params) {
this.logger.debug('notify:', type, params);
this.logger.info({
type: type,
params: params
}, 'notify');

@@ -737,3 +818,2 @@ if (type === exports.NotifyType.Configuration && this._notifySettings.configuration) {

this.onShuttle = noop;
this.onRemote = noop;
this.onConfiguration = noop;

@@ -745,11 +825,14 @@ this.onUptime = noop;

this.logger = logger.child({
source: 'HyperDeck Emulator'
name: 'HyperDeck Emulator'
});
this._server = net.createServer(function (socket) {
_this.logger.debug('connection');
_this.logger.info('connection');
var socketId = Math.random().toString(35).substr(-6);
_this._sockets[socketId] = new HyperdeckSocket(socket, _this.logger.child({
source: 'HyperDeck socket ' + socketId
}), function (cmd) {
var socketLogger = _this.logger.child({
name: 'HyperDeck socket ' + socketId
});
_this._sockets[socketId] = new HyperdeckSocket(socket, socketLogger, function (cmd) {
return _this._receivedCommand(cmd);

@@ -759,2 +842,3 @@ });

_this._sockets[socketId].on('disconnected', function () {
socketLogger.info('disconnected');
delete _this._sockets[socketId];

@@ -805,101 +889,103 @@ });

try {
var _exit24 = false;
var _this3 = this;
_this3.logger.info({
cmd: cmd
}, '_receivedCommand');
// TODO(meyer) more sophisticated debouncing
return Promise.resolve(new Promise(function (resolve) {
return setTimeout(function () {
return resolve();
}, 200);
})).then(function () {
var _exit = false;
return Promise.resolve(_catch(function () {
function _temp46(_result) {
var _exit2 = false;
if (_exit24) return _result;
_this3.logger.info({
cmd: cmd
}, '<-- ' + cmd.name);
function _temp44(_result2) {
var _exit3 = false;
if (_exit2) return _result2;
return _catch(function () {
function _temp44(_result) {
var _exit2 = false;
if (_exit) return _result;
function _temp42(_result3) {
var _exit4 = false;
if (_exit3) return _result3;
function _temp42(_result2) {
var _exit3 = false;
if (_exit2) return _result2;
function _temp40(_result4) {
var _exit5 = false;
if (_exit4) return _result4;
function _temp40(_result3) {
var _exit4 = false;
if (_exit3) return _result3;
function _temp38(_result5) {
var _exit6 = false;
if (_exit5) return _result5;
function _temp38(_result4) {
var _exit5 = false;
if (_exit4) return _result4;
function _temp36(_result6) {
var _exit7 = false;
if (_exit6) return _result6;
function _temp36(_result5) {
var _exit6 = false;
if (_exit5) return _result5;
function _temp34(_result7) {
var _exit8 = false;
if (_exit7) return _result7;
function _temp34(_result6) {
var _exit7 = false;
if (_exit6) return _result6;
function _temp32(_result8) {
var _exit9 = false;
if (_exit8) return _result8;
function _temp32(_result7) {
var _exit8 = false;
if (_exit7) return _result7;
function _temp30(_result9) {
var _exit10 = false;
if (_exit9) return _result9;
function _temp30(_result8) {
var _exit9 = false;
if (_exit8) return _result8;
function _temp28(_result10) {
var _exit11 = false;
if (_exit10) return _result10;
function _temp28(_result9) {
var _exit10 = false;
if (_exit9) return _result9;
function _temp26(_result11) {
var _exit12 = false;
if (_exit11) return _result11;
function _temp26(_result10) {
var _exit11 = false;
if (_exit10) return _result10;
function _temp24(_result12) {
var _exit13 = false;
if (_exit12) return _result12;
function _temp24(_result11) {
var _exit12 = false;
if (_exit11) return _result11;
function _temp22(_result13) {
var _exit14 = false;
if (_exit13) return _result13;
function _temp22(_result12) {
var _exit13 = false;
if (_exit12) return _result12;
function _temp20(_result14) {
var _exit15 = false;
if (_exit14) return _result14;
function _temp20(_result13) {
var _exit14 = false;
if (_exit13) return _result13;
function _temp18(_result15) {
var _exit16 = false;
if (_exit15) return _result15;
function _temp18(_result14) {
var _exit15 = false;
if (_exit14) return _result14;
function _temp16(_result16) {
var _exit17 = false;
if (_exit16) return _result16;
function _temp16(_result15) {
var _exit16 = false;
if (_exit15) return _result15;
function _temp14(_result17) {
var _exit18 = false;
if (_exit17) return _result17;
function _temp14(_result16) {
var _exit17 = false;
if (_exit16) return _result16;
function _temp12(_result18) {
var _exit19 = false;
if (_exit18) return _result18;
function _temp12(_result17) {
var _exit18 = false;
if (_exit17) return _result17;
function _temp10(_result19) {
var _exit20 = false;
if (_exit19) return _result19;
function _temp10(_result18) {
var _exit19 = false;
if (_exit18) return _result18;
function _temp8(_result20) {
var _exit21 = false;
if (_exit20) return _result20;
function _temp8(_result19) {
var _exit20 = false;
if (_exit19) return _result19;
function _temp6(_result21) {
var _exit22 = false;
if (_exit21) return _result21;
function _temp6(_result20) {
var _exit21 = false;
if (_exit20) return _result20;
function _temp4(_result22) {
var _exit23 = false;
if (_exit22) return _result22;
function _temp4(_result21) {
var _exit22 = false;
if (_exit21) return _result21;
function _temp2(_result23) {
if (_exit23) return _result23;
function _temp2(_result22) {
if (_exit22) return _result22;

@@ -922,3 +1008,3 @@ if (cmd.name === CommandNames.WatchdogCommand) {

return Promise.resolve(_this3.onIdentify(cmd)).then(function () {
_exit23 = true;
_exit22 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -936,7 +1022,7 @@ });

if (res) {
_exit22 = true;
_exit21 = true;
return new TResponse(exports.SynchronousCode.FormatReady, res);
}
_exit22 = true;
_exit21 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -953,3 +1039,3 @@ });

return Promise.resolve(_this3.onUptime(cmd)).then(function (res) {
_exit21 = true;
_exit20 = true;
return new TResponse(exports.SynchronousCode.Uptime, res);

@@ -963,2 +1049,9 @@ });

if (cmd.name === CommandNames.RemoteCommand) {
return new TResponse(exports.SynchronousCode.Remote, {
enabled: true,
override: false
});
}
var _temp7 = function () {

@@ -968,7 +1061,7 @@ if (cmd.name === CommandNames.ConfigurationCommand) {

if (res) {
_exit20 = true;
_exit19 = true;
return new TResponse(exports.SynchronousCode.Configuration, res);
}
_exit20 = true;
_exit19 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -983,11 +1076,6 @@ });

var _temp9 = function () {
if (cmd.name === CommandNames.RemoteCommand) {
return Promise.resolve(_this3.onRemote(cmd)).then(function (res) {
if (!res) {
_exit19 = true;
return new TResponse(exports.SynchronousCode.OK);
}
_exit19 = true;
return new TResponse(exports.SynchronousCode.Remote, res);
if (cmd.name === CommandNames.ShuttleCommand) {
return Promise.resolve(_this3.onShuttle(cmd)).then(function () {
_exit18 = true;
return new TResponse(exports.SynchronousCode.OK);
});

@@ -1001,5 +1089,5 @@ }

var _temp11 = function () {
if (cmd.name === CommandNames.ShuttleCommand) {
return Promise.resolve(_this3.onShuttle(cmd)).then(function () {
_exit18 = true;
if (cmd.name === CommandNames.JogCommand) {
return Promise.resolve(_this3.onJog(cmd)).then(function () {
_exit17 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1013,6 +1101,11 @@ });

if (cmd.name === CommandNames.NotifyCommand) {
// implemented in socket.ts
return new TResponse(exports.SynchronousCode.OK);
}
var _temp13 = function () {
if (cmd.name === CommandNames.JogCommand) {
return Promise.resolve(_this3.onJog(cmd)).then(function () {
_exit17 = true;
if (cmd.name === CommandNames.GoToCommand) {
return Promise.resolve(_this3.onGoTo(cmd)).then(function () {
_exit16 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1026,11 +1119,6 @@ });

if (cmd.name === CommandNames.NotifyCommand) {
// implemented in socket.ts
return new TResponse(exports.SynchronousCode.OK);
}
var _temp15 = function () {
if (cmd.name === CommandNames.GoToCommand) {
return Promise.resolve(_this3.onGoTo(cmd)).then(function () {
_exit16 = true;
if (cmd.name === CommandNames.SlotSelectCommand) {
return Promise.resolve(_this3.onSlotSelect(cmd)).then(function () {
_exit15 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1045,6 +1133,6 @@ });

var _temp17 = function () {
if (cmd.name === CommandNames.SlotSelectCommand) {
return Promise.resolve(_this3.onSlotSelect(cmd)).then(function () {
_exit15 = true;
return new TResponse(exports.SynchronousCode.OK);
if (cmd.name === CommandNames.SlotInfoCommand) {
return Promise.resolve(_this3.onSlotInfo(cmd)).then(function (res) {
_exit14 = true;
return new TResponse(exports.SynchronousCode.SlotInfo, res);
});

@@ -1058,6 +1146,6 @@ }

var _temp19 = function () {
if (cmd.name === CommandNames.SlotInfoCommand) {
return Promise.resolve(_this3.onSlotInfo(cmd)).then(function (res) {
_exit14 = true;
return new TResponse(exports.SynchronousCode.SlotInfo, res);
if (cmd.name === CommandNames.TransportInfoCommand) {
return Promise.resolve(_this3.onTransportInfo(cmd)).then(function (res) {
_exit13 = true;
return new TResponse(exports.SynchronousCode.TransportInfo, res);
});

@@ -1071,6 +1159,6 @@ }

var _temp21 = function () {
if (cmd.name === CommandNames.TransportInfoCommand) {
return Promise.resolve(_this3.onTransportInfo(cmd)).then(function (res) {
_exit13 = true;
return new TResponse(exports.SynchronousCode.TransportInfo, res);
if (cmd.name === CommandNames.ClipsClearCommand) {
return Promise.resolve(_this3.onClipsClear(cmd)).then(function () {
_exit12 = true;
return new TResponse(exports.SynchronousCode.OK);
});

@@ -1084,5 +1172,5 @@ }

var _temp23 = function () {
if (cmd.name === CommandNames.ClipsClearCommand) {
return Promise.resolve(_this3.onClipsClear(cmd)).then(function () {
_exit12 = true;
if (cmd.name === CommandNames.ClipsAddCommand) {
return Promise.resolve(_this3.onClipsAdd(cmd)).then(function () {
_exit11 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1097,6 +1185,6 @@ });

var _temp25 = function () {
if (cmd.name === CommandNames.ClipsAddCommand) {
return Promise.resolve(_this3.onClipsAdd(cmd)).then(function () {
_exit11 = true;
return new TResponse(exports.SynchronousCode.OK);
if (cmd.name === CommandNames.ClipsGetCommand) {
return Promise.resolve(_this3.onClipsGet(cmd).then(formatClipsGetResponse)).then(function (res) {
_exit10 = true;
return new TResponse(exports.SynchronousCode.ClipsInfo, res);
});

@@ -1110,6 +1198,6 @@ }

var _temp27 = function () {
if (cmd.name === CommandNames.ClipsGetCommand) {
return Promise.resolve(_this3.onClipsGet(cmd)).then(function (res) {
_exit10 = true;
return new TResponse(exports.SynchronousCode.ClipsInfo, res);
if (cmd.name === CommandNames.ClipsCountCommand) {
return Promise.resolve(_this3.onClipsCount(cmd)).then(function (res) {
_exit9 = true;
return new TResponse(exports.SynchronousCode.ClipsCount, res);
});

@@ -1123,6 +1211,6 @@ }

var _temp29 = function () {
if (cmd.name === CommandNames.ClipsCountCommand) {
return Promise.resolve(_this3.onClipsCount(cmd)).then(function (res) {
_exit9 = true;
return new TResponse(exports.SynchronousCode.ClipsCount, res);
if (cmd.name === CommandNames.StopCommand) {
return Promise.resolve(_this3.onStop(cmd)).then(function () {
_exit8 = true;
return new TResponse(exports.SynchronousCode.OK);
});

@@ -1136,5 +1224,5 @@ }

var _temp31 = function () {
if (cmd.name === CommandNames.StopCommand) {
return Promise.resolve(_this3.onStop(cmd)).then(function () {
_exit8 = true;
if (cmd.name === CommandNames.RecordCommand) {
return Promise.resolve(_this3.onRecord(cmd)).then(function () {
_exit7 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1149,5 +1237,5 @@ });

var _temp33 = function () {
if (cmd.name === CommandNames.RecordCommand) {
return Promise.resolve(_this3.onRecord(cmd)).then(function () {
_exit7 = true;
if (cmd.name === CommandNames.PlayrangeClearCommand) {
return Promise.resolve(_this3.onPlayrangeClear(cmd)).then(function () {
_exit6 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1162,5 +1250,5 @@ });

var _temp35 = function () {
if (cmd.name === CommandNames.PlayrangeClearCommand) {
return Promise.resolve(_this3.onPlayrangeClear(cmd)).then(function () {
_exit6 = true;
if (cmd.name === CommandNames.PlayrangeSetCommand) {
return Promise.resolve(_this3.onPlayrangeSet(cmd)).then(function () {
_exit5 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1175,5 +1263,5 @@ });

var _temp37 = function () {
if (cmd.name === CommandNames.PlayrangeSetCommand) {
return Promise.resolve(_this3.onPlayrangeSet(cmd)).then(function () {
_exit5 = true;
if (cmd.name === CommandNames.PlayCommand) {
return Promise.resolve(_this3.onPlay(cmd)).then(function () {
_exit4 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1188,5 +1276,5 @@ });

var _temp39 = function () {
if (cmd.name === CommandNames.PlayCommand) {
return Promise.resolve(_this3.onPlay(cmd)).then(function () {
_exit4 = true;
if (cmd.name === CommandNames.PreviewCommand) {
return Promise.resolve(_this3.onPreview(cmd)).then(function () {
_exit3 = true;
return new TResponse(exports.SynchronousCode.OK);

@@ -1201,6 +1289,6 @@ });

var _temp41 = function () {
if (cmd.name === CommandNames.PreviewCommand) {
return Promise.resolve(_this3.onPreview(cmd)).then(function () {
_exit3 = true;
return new TResponse(exports.SynchronousCode.OK);
if (cmd.name === CommandNames.DiskListCommand) {
return Promise.resolve(_this3.onDiskList(cmd)).then(function (res) {
_exit2 = true;
return new TResponse(exports.SynchronousCode.DiskList, res);
});

@@ -1214,6 +1302,6 @@ }

var _temp43 = function () {
if (cmd.name === CommandNames.DiskListCommand) {
return Promise.resolve(_this3.onDiskList(cmd)).then(function (res) {
_exit2 = true;
return new TResponse(exports.SynchronousCode.DiskList, res);
if (cmd.name === CommandNames.DeviceInfoCommand) {
return Promise.resolve(_this3.onDeviceInfo(cmd)).then(function (res) {
_exit = true;
return new TResponse(exports.SynchronousCode.DeviceInfo, res);
});

@@ -1224,21 +1312,26 @@ }

return _temp43 && _temp43.then ? _temp43.then(_temp44) : _temp44(_temp43);
}
}, function (err) {
if (err instanceof UnimplementedError) {
_this3.logger.error({
cmd: cmd
}, 'unimplemented');
var _temp45 = function () {
if (cmd.name === CommandNames.DeviceInfoCommand) {
return Promise.resolve(_this3.onDeviceInfo(cmd)).then(function (res) {
_exit24 = true;
return new TResponse(exports.SynchronousCode.DeviceInfo, res);
});
return new TResponse(exports.ErrorCode.Unsupported);
}
}();
return _temp45 && _temp45.then ? _temp45.then(_temp46) : _temp46(_temp45);
}, function (err) {
if (err instanceof UnimplementedError) {
return new TResponse(exports.ErrorCode.Unsupported);
}
if (err && typeof err.code === 'number' && exports.ErrorCode[err.code] && err.msg) {
_this3.logger.error({
err: err
}, 'error with code');
return err && typeof err.code === 'number' && exports.ErrorCode[err.code] && err.msg ? new ErrorResponse(err.code, err.msg) : new TResponse(exports.ErrorCode.InternalError);
}));
return new ErrorResponse(err.code, err.msg);
}
_this3.logger.error({
cmd: cmd
}, 'internal error');
return new TResponse(exports.ErrorCode.InternalError);
});
});
} catch (e) {

@@ -1254,2 +1347,3 @@ return Promise.reject(e);

exports.ResponseInterface = ResponseInterface;
exports.Timecode = Timecode;
//# sourceMappingURL=hyperdeck-emulator.cjs.development.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("events"),o=require("util"),r=require("net"),t=(e=require("pino"))&&"object"==typeof e&&"default"in e?e.default:e;function i(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e,n){return(a=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function c(e,n,o){return(c=u()?Reflect.construct:function(e,n,o){var r=[null];r.push.apply(r,n);var t=new(Function.bind.apply(e,r));return o&&a(t,o.prototype),t}).apply(null,arguments)}function f(e){var n="function"==typeof Map?new Map:void 0;return(f=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(e))return n.get(e);n.set(e,o)}function o(){return c(e,arguments,s(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),a(o,e)})(e)}function p(e,n){(null==n||n>e.length)&&(n=e.length);for(var o=0,r=new Array(n);o<n;o++)r[o]=e[o];return r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var d,m,l,h,C,y,v=function(){function e(e,n){this.code=e,this.params=n,this.name=P[e]}return e.prototype.build=function(){var e=o.format("%d %s",this.code,this.name);if(this.params){e+=":\r\n";for(var n=0,r=Object.entries(this.params);n<r.length;n++){var t=r[n],i=t[1];i&&(e+=o.format("%s: %s",t[0],i)+"\r\n")}}return e+"\r\n"},e}(),g=function(e,n){var r=this;this.code=e,this.message=n,this.build=function(){return o.format("%d %s",r.code,r.message)}};(m=exports.ErrorCode||(exports.ErrorCode={}))[m.SyntaxError=100]="SyntaxError",m[m.UnsupportedParameter=101]="UnsupportedParameter",m[m.InvalidValue=102]="InvalidValue",m[m.Unsupported=103]="Unsupported",m[m.DiskFull=104]="DiskFull",m[m.NoDisk=105]="NoDisk",m[m.DiskError=106]="DiskError",m[m.TimelineEmpty=107]="TimelineEmpty",m[m.InternalError=108]="InternalError",m[m.OutOfRange=109]="OutOfRange",m[m.NoInput=110]="NoInput",m[m.RemoteControlDisabled=111]="RemoteControlDisabled",m[m.ConnectionRejected=120]="ConnectionRejected",m[m.InvalidState=150]="InvalidState",m[m.InvalidCodec=151]="InvalidCodec",m[m.InvalidFormat=160]="InvalidFormat",m[m.InvalidToken=161]="InvalidToken",m[m.FormatNotPrepared=162]="FormatNotPrepared",(l=exports.SynchronousCode||(exports.SynchronousCode={}))[l.OK=200]="OK",l[l.SlotInfo=202]="SlotInfo",l[l.DeviceInfo=204]="DeviceInfo",l[l.ClipsInfo=205]="ClipsInfo",l[l.DiskList=206]="DiskList",l[l.TransportInfo=208]="TransportInfo",l[l.Notify=209]="Notify",l[l.Remote=210]="Remote",l[l.Configuration=211]="Configuration",l[l.ClipsCount=214]="ClipsCount",l[l.Uptime=215]="Uptime",l[l.FormatReady=216]="FormatReady",(h=exports.AsynchronousCode||(exports.AsynchronousCode={}))[h.ConnectionInfo=500]="ConnectionInfo",h[h.SlotInfo=502]="SlotInfo",h[h.TransportInfo=508]="TransportInfo",h[h.RemoteInfo=510]="RemoteInfo",h[h.ConfigurationInfo=511]="ConfigurationInfo",(C=exports.NotifyType||(exports.NotifyType={}))[C.Slot=0]="Slot",C[C.Transport=1]="Transport",C[C.Remote=2]="Remote",C[C.Configuration=3]="Configuration",function(e){e.DeviceInfoCommand="device info",e.DiskListCommand="disk list",e.PreviewCommand="preview",e.PlayCommand="play",e.PlayrangeSetCommand="playrange set",e.PlayrangeClearCommand="playrange clear",e.RecordCommand="record",e.StopCommand="stop",e.ClipsCountCommand="clips count",e.ClipsGetCommand="clips get",e.ClipsAddCommand="clips add",e.ClipsClearCommand="clips clear",e.TransportInfoCommand="transport info",e.SlotInfoCommand="slot info",e.SlotSelectCommand="slot select",e.NotifyCommand="notify",e.GoToCommand="goto",e.JogCommand="jog",e.ShuttleCommand="shuttle",e.RemoteCommand="remote",e.ConfigurationCommand="configuration",e.UptimeCommand="uptime",e.FormatCommand="format",e.IdentifyCommand="identify",e.WatchdogCommand="watchdog",e.PingCommand="ping"}(y||(y={}));var S,x,_,I,w,R,P=((d={})[exports.AsynchronousCode.ConfigurationInfo]="configuration info",d[exports.AsynchronousCode.ConnectionInfo]="connection info",d[exports.AsynchronousCode.RemoteInfo]="remote info",d[exports.AsynchronousCode.SlotInfo]=y.SlotInfoCommand,d[exports.AsynchronousCode.TransportInfo]=y.TransportInfoCommand,d[exports.ErrorCode.ConnectionRejected]="connection rejected",d[exports.ErrorCode.DiskError]="disk error",d[exports.ErrorCode.DiskFull]="disk full",d[exports.ErrorCode.FormatNotPrepared]="format not prepared",d[exports.ErrorCode.InternalError]="internal error",d[exports.ErrorCode.InvalidCodec]="invalid codec",d[exports.ErrorCode.InvalidFormat]="invalid format",d[exports.ErrorCode.InvalidState]="invalid state",d[exports.ErrorCode.InvalidToken]="invalid token",d[exports.ErrorCode.InvalidValue]="invalid value",d[exports.ErrorCode.NoDisk]="no disk",d[exports.ErrorCode.NoInput]="no input",d[exports.ErrorCode.OutOfRange]="out of range",d[exports.ErrorCode.RemoteControlDisabled]="remote control disabled",d[exports.ErrorCode.SyntaxError]="syntax error",d[exports.ErrorCode.TimelineEmpty]="timeline empty",d[exports.ErrorCode.Unsupported]="unsupported",d[exports.ErrorCode.UnsupportedParameter]="unsupported parameter",d[exports.SynchronousCode.ClipsCount]=y.ClipsCountCommand,d[exports.SynchronousCode.ClipsInfo]="clips info",d[exports.SynchronousCode.Configuration]=y.ConfigurationCommand,d[exports.SynchronousCode.DeviceInfo]=y.DeviceInfoCommand,d[exports.SynchronousCode.DiskList]=y.DiskListCommand,d[exports.SynchronousCode.FormatReady]="format ready",d[exports.SynchronousCode.Notify]=y.NotifyCommand,d[exports.SynchronousCode.OK]="ok",d[exports.SynchronousCode.Remote]=y.RemoteCommand,d[exports.SynchronousCode.SlotInfo]=y.SlotInfoCommand,d[exports.SynchronousCode.TransportInfo]=y.TransportInfoCommand,d[exports.SynchronousCode.Uptime]=y.UptimeCommand,d),T={help:[],commands:[],"device info":[],"disk list":["slot id"],quit:[],ping:[],preview:["enable"],play:["speed","loop","single clip"],"playrange set":["clip id","in","out"],"playrange clear":[],record:["name"],stop:[],"clips count":[],"clips get":["clip id","count"],"clips add":["name"],"clips clear":[],"transport info":[],"slot info":["slot id"],"slot select":["slot id","video format"],notify:["remote","transport","slot","configuration","dropped frames"],goto:["clip id","clip","timeline","timecode","slot id"],jog:["timecode"],shuttle:["speed"],remote:["enable","override"],configuration:["video input","audio input","file format"],uptime:[],format:["prepare","confirm"],identify:["enable"],watchdog:["period"]};!function(e){e.EMPTY="empty",e.MOUNTING="mounting",e.ERROR="error",e.MOUNTED="mounted"}(S||(S={})),(x=exports.VideoFormat||(exports.VideoFormat={})).NTSC="NTSC",x.PAL="PAL",x.NTSCp="NTSCp",x.PALp="PALp",x._720p50="720p50",x._720p5994="720p5994",x._720p60="720p60",x._1080p23976="1080p23976",x._1080p24="1080p24",x._1080p25="1080p25",x._1080p2997="1080p2997",x._1080p30="1080p30",x._1080i50="1080i50",x._1080i5994="1080i5994",x._1080i60="1080i60",x._4Kp23976="4Kp23976",x._4Kp24="4Kp24",x._4Kp25="4Kp25",x._4Kp2997="4Kp2997",x._4Kp30="4Kp30",x._4Kp50="4Kp50",x._4Kp5994="4Kp5994",x._4Kp60="4Kp60",(_=exports.TransportStatus||(exports.TransportStatus={})).PREVIEW="preview",_.STOPPED="stopped",_.PLAY="play",_.FORWARD="forward",_.REWIND="rewind",_.JOG="jog",_.SHUTTLE="shuttle",_.RECORD="record",(I=exports.FileFormats||(exports.FileFormats={})).QuickTimeUncompressed="QuickTimeUncompressed",I.QuickTimeProResHQ="QuickTimeProResHQ",I.QuickTimeProRes="QuickTimeProRes",I.QuickTimeProResLT="QuickTimeProResLT",I.QuickTimeProResProxy="QuickTimeProResProxy",I.QuickTimeDNxHR220="QuickTimeDNxHR220",I.DNxHR220="DNxHR220",function(e){e.embedded="embedded",e.XLR="XLR",e.RCA="RCA"}(w||(w={})),function(e){e.SDI="SDI",e.HDMI="HDMI",e.component="component"}(R||(R={}));var k=function(){function e(e){this._linesQueue=[],this._log=e.child({source:"MultilineParser"})}var n=e.prototype;return n.receivedString=function(e){var n=[],o=e.split("\r\n");for(o.length>0&&""===o[o.length-1]&&o.pop(),this._linesQueue=this._linesQueue.concat(o);this._linesQueue.length>0;)if(""!==this._linesQueue[0])if(-1===this._linesQueue[0].indexOf(":")||1===this._linesQueue.length&&this._linesQueue[0].indexOf(":")>0){var r=this.parseResponse(this._linesQueue.splice(0,1));r&&n.push(r)}else{var t=this._linesQueue.indexOf("");if(-1===t)break;var i=this._linesQueue.splice(0,t+1),s=this.parseResponse(i);s&&n.push(s)}else this._linesQueue.shift();return n},n.parseResponse=function(e){if(1===(e=e.map((function(e){return e.trim()}))).length&&e[0].indexOf(":")>-1){var n=e[0].split(": "),o=n.shift();if(!o)throw new Error("Unrecognised command");var r={},t=new Set(T[o]),i=n.shift();if(!i)throw new Error("No named parameters found");for(var s=0;s<n.length-1;s++){for(var a=n[s].split(" "),u="",c=a.length-1;c>=0&&(u=(a.pop()+" "+u).trim(),!t.has(u));c--);if(!a.length)throw new Error("Command malformed / paramName not recognised");r[i]=a.join(" "),i=u}return r[i]=n[n.length-1],{raw:e.join("\r\n"),name:o,parameters:r}}var f=e[0].match(/(.+?)(:|)$/im);if(!f)return this._log.error({header:e[0]},"failed to parse header"),null;for(var p=f[1],d={},m=1;m<e.length;m++){var l=e[m].match(/^(.*?): (.*)$/im);l?d[l[1]]=l[2]:this._log.error({line:e[m]},"failed to parse line")}return{raw:e.join("\r\n"),name:p,parameters:d}},e}(),b=function(e){function n(n,o,r){var t;return(t=e.call(this)||this)._socket=n,t.logger=o,t._receivedCommand=r,t._lastReceived=-1,t._watchdogTimer=null,t._notifySettings={slot:!1,transport:!1,remote:!1,configuration:!1,"dropped frames":!1},t._parser=new k(t.logger),t._socket.setEncoding("utf-8"),t._socket.on("data",(function(e){t._onMessage(e)})),t._socket.on("error",(function(){o.info("error"),t._socket.destroy(),t.emit("disconnected"),o.info("disconnected")})),t.sendResponse(new v(exports.AsynchronousCode.ConnectionInfo,{"protocol version":"1.6",model:"NodeJS Hyperdeck Server Library"})),t}i(n,e);var o=n.prototype;return o._onMessage=function(e){var n=this;this.logger.debug("onMessage(%s)",e),this._lastReceived=Date.now();var o=this._parser.receivedString(e);this.logger.debug("commands:",o);for(var r,t=function(e,n){var o;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(o=function(e,n){if(e){if("string"==typeof e)return p(e,void 0);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?p(e,void 0):void 0}}(e))){o&&(e=o);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(o=e[Symbol.iterator]()).next.bind(o)}(o);!(r=t()).done;){var i=r.value;if(i.name===y.WatchdogCommand)!function(){n._watchdogTimer&&clearInterval(n._watchdogTimer);var e=i;e.parameters.period&&(n._watchdogTimer=setInterval((function(){Date.now()-n._lastReceived>Number(e.parameters.period)&&(n._socket.destroy(),n.emit("disconnected"),n._watchdogTimer&&clearInterval(n._watchdogTimer))}),1e3*Number(e.parameters.period)))}();else if(i.name===y.NotifyCommand){var s=i;if(!(Object.keys(s.parameters).length>0)){for(var a={},u=0,c=Object.keys(this._notifySettings);u<c.length;u++){var f=c[u];a[f]=this._notifySettings[f]?"true":"false"}this.sendResponse(new v(exports.SynchronousCode.Notify,a));continue}for(var d=0,m=Object.keys(s.parameters);d<m.length;d++){var l=m[d];void 0!==this._notifySettings[l]&&(this._notifySettings[l]="true"===s.parameters[l])}}this._receivedCommand(i).then((function(e){n.logger.info({res:e},"_receivedCommand response"),n.sendResponse(e)}),(function(){n.logger.error({},"_receivedCommand error response"),n.sendResponse(new v(exports.ErrorCode.Unsupported))}))}},o.sendResponse=function(e){var n=e.build();this._socket.write(n)},o.notify=function(e,n){this.logger.debug("notify:",e,n),e===exports.NotifyType.Configuration&&this._notifySettings.configuration?this.sendResponse(new v(exports.AsynchronousCode.ConfigurationInfo,n)):e===exports.NotifyType.Remote&&this._notifySettings.remote?this.sendResponse(new v(exports.AsynchronousCode.RemoteInfo,n)):e===exports.NotifyType.Slot&&this._notifySettings.slot?this.sendResponse(new v(exports.AsynchronousCode.SlotInfo,n)):e===exports.NotifyType.Transport&&this._notifySettings.transport&&this.sendResponse(new v(exports.AsynchronousCode.TransportInfo,n))},n}(n.EventEmitter),O=function(e){function n(){return e.apply(this,arguments)||this}return i(n,e),n}(f(Error)),E=function(){try{throw new O}catch(e){return Promise.reject(e)}};exports.HyperdeckServer=function(){function e(e,n){var o=this;void 0===n&&(n=t()),this._sockets={},this.onDeviceInfo=E,this.onDiskList=E,this.onPreview=E,this.onPlay=E,this.onPlayrangeSet=E,this.onPlayrangeClear=E,this.onRecord=E,this.onStop=E,this.onClipsCount=E,this.onClipsGet=E,this.onClipsAdd=E,this.onClipsClear=E,this.onTransportInfo=E,this.onSlotInfo=E,this.onSlotSelect=E,this.onGoTo=E,this.onJog=E,this.onShuttle=E,this.onRemote=E,this.onConfiguration=E,this.onUptime=E,this.onFormat=E,this.onIdentify=E,this.onWatchdog=E,this.logger=n.child({source:"HyperDeck Emulator"}),this._server=r.createServer((function(e){o.logger.debug("connection");var n=Math.random().toString(35).substr(-6);o._sockets[n]=new b(e,o.logger.child({source:"HyperDeck socket "+n}),(function(e){return o._receivedCommand(e)})),o._sockets[n].on("disconnected",(function(){delete o._sockets[n]}))})),this._server.on("listening",(function(){return o.logger.info("listening")})),this._server.on("close",(function(){return o.logger.info("connection closed")})),this._server.on("error",(function(e){return o.logger.error("server error:",e)})),this._server.maxConnections=1,this._server.listen(9993,e)}var n=e.prototype;return n.close=function(){this._server.unref()},n.notifySlot=function(e){this._notify(exports.NotifyType.Slot,e)},n.notifyTransport=function(e){this._notify(exports.NotifyType.Transport,e)},n._notify=function(e,n){for(var o=0,r=Object.keys(this._sockets);o<r.length;o++)this._sockets[r[o]].notify(e,n)},n._receivedCommand=function(e){try{var n=!1,o=this;return o.logger.info({cmd:e},"_receivedCommand"),Promise.resolve(function(r,t){try{var i=function(){function r(r){var t=!1;if(n)return r;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){var t=!1;if(r)return n;function i(n){var r=!1;if(t)return n;function i(n){if(r)return n;if(e.name===y.WatchdogCommand)return new v(exports.SynchronousCode.OK);if(e.name===y.PingCommand)return new v(exports.SynchronousCode.OK);throw new Error("Unhandled command name: "+e.name)}var s=function(){if(e.name===y.IdentifyCommand)return Promise.resolve(o.onIdentify(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.FormatCommand)return Promise.resolve(o.onFormat(e)).then((function(e){return e?(t=!0,new v(exports.SynchronousCode.FormatReady,e)):(t=!0,new v(exports.SynchronousCode.OK))}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.UptimeCommand)return Promise.resolve(o.onUptime(e)).then((function(e){return r=!0,new v(exports.SynchronousCode.Uptime,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.ConfigurationCommand)return Promise.resolve(o.onConfiguration(e)).then((function(e){return e?(t=!0,new v(exports.SynchronousCode.Configuration,e)):(t=!0,new v(exports.SynchronousCode.OK))}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.RemoteCommand)return Promise.resolve(o.onRemote(e)).then((function(e){return e?(r=!0,new v(exports.SynchronousCode.Remote,e)):(r=!0,new v(exports.SynchronousCode.OK))}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.ShuttleCommand)return Promise.resolve(o.onShuttle(e)).then((function(){return t=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.JogCommand)return Promise.resolve(o.onJog(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}if(e.name===y.NotifyCommand)return new v(exports.SynchronousCode.OK);var s=function(){if(e.name===y.GoToCommand)return Promise.resolve(o.onGoTo(e)).then((function(){return t=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.SlotSelectCommand)return Promise.resolve(o.onSlotSelect(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.SlotInfoCommand)return Promise.resolve(o.onSlotInfo(e)).then((function(e){return t=!0,new v(exports.SynchronousCode.SlotInfo,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.TransportInfoCommand)return Promise.resolve(o.onTransportInfo(e)).then((function(e){return r=!0,new v(exports.SynchronousCode.TransportInfo,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.ClipsClearCommand)return Promise.resolve(o.onClipsClear(e)).then((function(){return t=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.ClipsAddCommand)return Promise.resolve(o.onClipsAdd(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.ClipsGetCommand)return Promise.resolve(o.onClipsGet(e)).then((function(e){return t=!0,new v(exports.SynchronousCode.ClipsInfo,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.ClipsCountCommand)return Promise.resolve(o.onClipsCount(e)).then((function(e){return r=!0,new v(exports.SynchronousCode.ClipsCount,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.StopCommand)return Promise.resolve(o.onStop(e)).then((function(){return t=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.RecordCommand)return Promise.resolve(o.onRecord(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.PlayrangeClearCommand)return Promise.resolve(o.onPlayrangeClear(e)).then((function(){return t=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.PlayrangeSetCommand)return Promise.resolve(o.onPlayrangeSet(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.PlayCommand)return Promise.resolve(o.onPlay(e)).then((function(){return t=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.PreviewCommand)return Promise.resolve(o.onPreview(e)).then((function(){return r=!0,new v(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===y.DiskListCommand)return Promise.resolve(o.onDiskList(e)).then((function(e){return t=!0,new v(exports.SynchronousCode.DiskList,e)}))}();return s&&s.then?s.then(i):i(s)}var t=function(){if(e.name===y.DeviceInfoCommand)return Promise.resolve(o.onDeviceInfo(e)).then((function(e){return n=!0,new v(exports.SynchronousCode.DeviceInfo,e)}))}();return t&&t.then?t.then(r):r(t)}()}catch(e){return t(e)}return i&&i.then?i.then(void 0,t):i}(0,(function(e){return e instanceof O?new v(exports.ErrorCode.Unsupported):e&&"number"==typeof e.code&&exports.ErrorCode[e.code]&&e.msg?new g(e.code,e.msg):new v(exports.ErrorCode.InternalError)})))}catch(e){return Promise.reject(e)}},e}(),exports.ResponseInterface={__proto__:null};
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n,o=require("events"),r=e(require("util")),t=require("net"),i=e(require("pino"));function s(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,n){return(u=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function f(e,n,o){return(f=c()?Reflect.construct:function(e,n,o){var r=[null];r.push.apply(r,n);var t=new(Function.bind.apply(e,r));return o&&u(t,o.prototype),t}).apply(null,arguments)}function p(e){var n="function"==typeof Map?new Map:void 0;return(p=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(e))return n.get(e);n.set(e,o)}function o(){return f(e,arguments,a(this).constructor)}return o.prototype=Object.create(e.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),u(o,e)})(e)}function d(e,n){(null==n||n>e.length)&&(n=e.length);for(var o=0,r=new Array(n);o<n;o++)r[o]=e[o];return r}function m(e,n){if(!e){for(var o=arguments.length,t=new Array(o>2?o-2:0),i=2;i<o;i++)t[i-2]=arguments[i];throw new Error(r.format.apply(r,[n].concat(t)))}}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var l,h,C,y,v,g=function(e,n){var o=this;this.code=e,this.params=n,this.build=function(){return E(o.code,o.params)},k.hasOwnProperty(e)||m(!1),this.name=k[e]},S=function(e){for(var n=e.clips.length,o={clipsCount:n},r=0;r<n;r++){var t=e.clips[r];o[(r+1).toString()]=t.name+" "+t.startT+" "+t.duration}return o},x=function(e,n){var o=this;this.code=e,this.message=n,this.build=function(){return o.code+" "+o.message+"\r\n"},k.hasOwnProperty(e)||m(!1)};(l=exports.ErrorCode||(exports.ErrorCode={}))[l.SyntaxError=100]="SyntaxError",l[l.UnsupportedParameter=101]="UnsupportedParameter",l[l.InvalidValue=102]="InvalidValue",l[l.Unsupported=103]="Unsupported",l[l.DiskFull=104]="DiskFull",l[l.NoDisk=105]="NoDisk",l[l.DiskError=106]="DiskError",l[l.TimelineEmpty=107]="TimelineEmpty",l[l.InternalError=108]="InternalError",l[l.OutOfRange=109]="OutOfRange",l[l.NoInput=110]="NoInput",l[l.RemoteControlDisabled=111]="RemoteControlDisabled",l[l.ConnectionRejected=120]="ConnectionRejected",l[l.InvalidState=150]="InvalidState",l[l.InvalidCodec=151]="InvalidCodec",l[l.InvalidFormat=160]="InvalidFormat",l[l.InvalidToken=161]="InvalidToken",l[l.FormatNotPrepared=162]="FormatNotPrepared",(h=exports.SynchronousCode||(exports.SynchronousCode={}))[h.OK=200]="OK",h[h.SlotInfo=202]="SlotInfo",h[h.DeviceInfo=204]="DeviceInfo",h[h.ClipsInfo=205]="ClipsInfo",h[h.DiskList=206]="DiskList",h[h.TransportInfo=208]="TransportInfo",h[h.Notify=209]="Notify",h[h.Remote=210]="Remote",h[h.Configuration=211]="Configuration",h[h.ClipsCount=214]="ClipsCount",h[h.Uptime=215]="Uptime",h[h.FormatReady=216]="FormatReady",(C=exports.AsynchronousCode||(exports.AsynchronousCode={}))[C.ConnectionInfo=500]="ConnectionInfo",C[C.SlotInfo=502]="SlotInfo",C[C.TransportInfo=508]="TransportInfo",C[C.RemoteInfo=510]="RemoteInfo",C[C.ConfigurationInfo=511]="ConfigurationInfo",(y=exports.NotifyType||(exports.NotifyType={}))[y.Slot=0]="Slot",y[y.Transport=1]="Transport",y[y.Remote=2]="Remote",y[y.Configuration=3]="Configuration",function(e){e.DeviceInfoCommand="device info",e.DiskListCommand="disk list",e.PreviewCommand="preview",e.PlayCommand="play",e.PlayrangeSetCommand="playrange set",e.PlayrangeClearCommand="playrange clear",e.RecordCommand="record",e.StopCommand="stop",e.ClipsCountCommand="clips count",e.ClipsGetCommand="clips get",e.ClipsAddCommand="clips add",e.ClipsClearCommand="clips clear",e.TransportInfoCommand="transport info",e.SlotInfoCommand="slot info",e.SlotSelectCommand="slot select",e.NotifyCommand="notify",e.GoToCommand="goto",e.JogCommand="jog",e.ShuttleCommand="shuttle",e.RemoteCommand="remote",e.ConfigurationCommand="configuration",e.UptimeCommand="uptime",e.FormatCommand="format",e.IdentifyCommand="identify",e.WatchdogCommand="watchdog",e.PingCommand="ping"}(v||(v={}));var _,I,w,P,R,T,k=((n={})[exports.AsynchronousCode.ConfigurationInfo]="configuration info",n[exports.AsynchronousCode.ConnectionInfo]="connection info",n[exports.AsynchronousCode.RemoteInfo]="remote info",n[exports.AsynchronousCode.SlotInfo]=v.SlotInfoCommand,n[exports.AsynchronousCode.TransportInfo]=v.TransportInfoCommand,n[exports.ErrorCode.ConnectionRejected]="connection rejected",n[exports.ErrorCode.DiskError]="disk error",n[exports.ErrorCode.DiskFull]="disk full",n[exports.ErrorCode.FormatNotPrepared]="format not prepared",n[exports.ErrorCode.InternalError]="internal error",n[exports.ErrorCode.InvalidCodec]="invalid codec",n[exports.ErrorCode.InvalidFormat]="invalid format",n[exports.ErrorCode.InvalidState]="invalid state",n[exports.ErrorCode.InvalidToken]="invalid token",n[exports.ErrorCode.InvalidValue]="invalid value",n[exports.ErrorCode.NoDisk]="no disk",n[exports.ErrorCode.NoInput]="no input",n[exports.ErrorCode.OutOfRange]="out of range",n[exports.ErrorCode.RemoteControlDisabled]="remote control disabled",n[exports.ErrorCode.SyntaxError]="syntax error",n[exports.ErrorCode.TimelineEmpty]="timeline empty",n[exports.ErrorCode.Unsupported]="unsupported",n[exports.ErrorCode.UnsupportedParameter]="unsupported parameter",n[exports.SynchronousCode.ClipsCount]=v.ClipsCountCommand,n[exports.SynchronousCode.ClipsInfo]="clips info",n[exports.SynchronousCode.Configuration]=v.ConfigurationCommand,n[exports.SynchronousCode.DeviceInfo]=v.DeviceInfoCommand,n[exports.SynchronousCode.DiskList]=v.DiskListCommand,n[exports.SynchronousCode.FormatReady]="format ready",n[exports.SynchronousCode.Notify]=v.NotifyCommand,n[exports.SynchronousCode.OK]="ok",n[exports.SynchronousCode.Remote]=v.RemoteCommand,n[exports.SynchronousCode.SlotInfo]=v.SlotInfoCommand,n[exports.SynchronousCode.TransportInfo]=v.TransportInfoCommand,n[exports.SynchronousCode.Uptime]=v.UptimeCommand,n),b=function(){function e(e,n,o,r){this._timecode=[e,n,o,r].map((function(e){var n=Math.floor(e);if(n!==e||e<0||e>99)throw new Error("Timecode params must be an integer between 0 and 99");return(n+100).toString().slice(-2)})).join(":")}return e.prototype.toString=function(){return this._timecode},e}(),E=function(e,n){var o=e+" "+k[e];if(!n)return o+"\r\n";var r=Object.entries(n).filter((function(e){return null!=e[1]}));return 0===r.length?o+"\r\n":r.reduce((function(e,n){var o,r=n[0],t=n[1];if("string"==typeof t)o=t;else if("boolean"==typeof t)o=t?"true":"false";else{if("number"!=typeof t)throw new Error("Unhandled value type: "+typeof t);o=t.toString()}return e+r.replace(/([a-z])([A-Z]+)/,"$1 $2").toLowerCase()+": "+o+"\r\n"}),o+":\r\n")+"\r\n"},O={help:[],commands:[],"device info":[],"disk list":["slot id"],quit:[],ping:[],preview:["enable"],play:["speed","loop","single clip"],"playrange set":["clip id","in","out"],"playrange clear":[],record:["name"],stop:[],"clips count":[],"clips get":["clip id","count"],"clips add":["name"],"clips clear":[],"transport info":[],"slot info":["slot id"],"slot select":["slot id","video format"],notify:["remote","transport","slot","configuration","dropped frames"],goto:["clip id","clip","timeline","timecode","slot id"],jog:["timecode"],shuttle:["speed"],remote:["enable","override"],configuration:["video input","audio input","file format"],uptime:[],format:["prepare","confirm"],identify:["enable"],watchdog:["period"]};(_=exports.SlotStatus||(exports.SlotStatus={})).EMPTY="empty",_.MOUNTING="mounting",_.ERROR="error",_.MOUNTED="mounted",(I=exports.VideoFormat||(exports.VideoFormat={})).NTSC="NTSC",I.PAL="PAL",I.NTSCp="NTSCp",I.PALp="PALp",I._720p50="720p50",I._720p5994="720p5994",I._720p60="720p60",I._1080p23976="1080p23976",I._1080p24="1080p24",I._1080p25="1080p25",I._1080p2997="1080p2997",I._1080p30="1080p30",I._1080i50="1080i50",I._1080i5994="1080i5994",I._1080i60="1080i60",I._4Kp23976="4Kp23976",I._4Kp24="4Kp24",I._4Kp25="4Kp25",I._4Kp2997="4Kp2997",I._4Kp30="4Kp30",I._4Kp50="4Kp50",I._4Kp5994="4Kp5994",I._4Kp60="4Kp60",(w=exports.TransportStatus||(exports.TransportStatus={})).PREVIEW="preview",w.STOPPED="stopped",w.PLAY="play",w.FORWARD="forward",w.REWIND="rewind",w.JOG="jog",w.SHUTTLE="shuttle",w.RECORD="record",(P=exports.FileFormats||(exports.FileFormats={})).QuickTimeUncompressed="QuickTimeUncompressed",P.QuickTimeProResHQ="QuickTimeProResHQ",P.QuickTimeProRes="QuickTimeProRes",P.QuickTimeProResLT="QuickTimeProResLT",P.QuickTimeProResProxy="QuickTimeProResProxy",P.QuickTimeDNxHR220="QuickTimeDNxHR220",P.DNxHR220="DNxHR220",function(e){e.embedded="embedded",e.XLR="XLR",e.RCA="RCA"}(R||(R={})),function(e){e.SDI="SDI",e.HDMI="HDMI",e.component="component"}(T||(T={}));var D=function(){function e(e){this._linesQueue=[],this._log=e.child({name:"MultilineParser"})}var n=e.prototype;return n.receivedString=function(e){var n=[],o=e.split("\r\n");for(o.length>0&&""===o[o.length-1]&&o.pop(),this._linesQueue=this._linesQueue.concat(o);this._linesQueue.length>0;)if(""!==this._linesQueue[0])if(-1===this._linesQueue[0].indexOf(":")||1===this._linesQueue.length&&this._linesQueue[0].indexOf(":")>0){var r=this.parseResponse(this._linesQueue.splice(0,1));r&&n.push(r)}else{var t=this._linesQueue.indexOf("");if(-1===t)break;var i=this._linesQueue.splice(0,t+1),s=this.parseResponse(i);s&&n.push(s)}else this._linesQueue.shift();return n},n.parseResponse=function(e){if(1===(e=e.map((function(e){return e.trim()}))).length&&e[0].indexOf(":")>-1){var n=e[0].split(": "),o=n.shift();if(!o)throw new Error("Unrecognised command");var r={},t=new Set(O[o]),i=n.shift();if(!i)throw new Error("No named parameters found");for(var s=0;s<n.length-1;s++){for(var a=n[s].split(" "),u="",c=a.length-1;c>=0&&(u=(a.pop()+" "+u).trim(),!t.has(u));c--);if(!a.length)throw new Error("Command malformed / paramName not recognised");r[i]=a.join(" "),i=u}return r[i]=n[n.length-1],{raw:e.join("\r\n"),name:o,parameters:r}}var f=e[0].match(/(.+?)(:|)$/im);if(!f)return this._log.error({header:e[0]},"failed to parse header"),null;for(var p=f[1],d={},m=1;m<e.length;m++){var l=e[m].match(/^(.*?): (.*)$/im);l?d[l[1]]=l[2]:this._log.error({line:e[m]},"failed to parse line")}return{raw:e.join("\r\n"),name:p,parameters:d}},e}(),N=function(e){function n(n,o,r){var t;return(t=e.call(this)||this)._socket=n,t.logger=o,t._receivedCommand=r,t._lastReceived=-1,t._watchdogTimer=null,t._notifySettings={slot:!1,transport:!1,remote:!1,configuration:!1,"dropped frames":!1},t._parser=new D(o),t._socket.setEncoding("utf-8"),t._socket.on("data",(function(e){t._onMessage(e)})),t._socket.on("error",(function(){o.info("error"),t._socket.destroy(),t.emit("disconnected"),o.info("disconnected")})),t.sendResponse(new g(exports.AsynchronousCode.ConnectionInfo,{"protocol version":"1.11",model:"NodeJS Hyperdeck Server Library"})),t}s(n,e);var o=n.prototype;return o._onMessage=function(e){var n=this;this.logger.info({data:e},"onMessage"),this._lastReceived=Date.now();var o=this._parser.receivedString(e);this.logger.info({cmds:o},"commands");for(var r,t=function(){var e=r.value;if(e.name===v.WatchdogCommand){n._watchdogTimer&&clearInterval(n._watchdogTimer);var o=e;o.parameters.period&&(n._watchdogTimer=setInterval((function(){Date.now()-n._lastReceived>Number(o.parameters.period)&&(n._socket.destroy(),n.emit("disconnected"),n._watchdogTimer&&clearInterval(n._watchdogTimer))}),1e3*Number(o.parameters.period)))}else if(e.name===v.NotifyCommand){var t=e;if(!(Object.keys(t.parameters).length>0)){for(var i={},s=0,a=Object.keys(n._notifySettings);s<a.length;s++){var u=a[s];i[u]=n._notifySettings[u]?"true":"false"}return n.sendResponse(new g(exports.SynchronousCode.Notify,i),e),"continue"}for(var c=0,f=Object.keys(t.parameters);c<f.length;c++){var p=f[c];void 0!==n._notifySettings[p]&&(n._notifySettings[p]="true"===t.parameters[p])}}n._receivedCommand(e).then((function(o){return n.sendResponse(o,e)}),(function(){return n.sendResponse(new g(exports.ErrorCode.Unsupported),e)}))},i=function(e,n){var o;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(o=function(e,n){if(e){if("string"==typeof e)return d(e,void 0);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?d(e,void 0):void 0}}(e))){o&&(e=o);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(o=e[Symbol.iterator]()).next.bind(o)}(o);!(r=i()).done;)t()},o.sendResponse=function(e,n){var o=e.build(),r="--\x3e "+((null==n?void 0:n.name)||"sendResponse");e instanceof g&&exports.ErrorCode[e.code]?this.logger.error({responseText:o},r):this.logger.info({responseText:o},r),this._socket.write(o)},o.notify=function(e,n){this.logger.info({type:e,params:n},"notify"),e===exports.NotifyType.Configuration&&this._notifySettings.configuration?this.sendResponse(new g(exports.AsynchronousCode.ConfigurationInfo,n)):e===exports.NotifyType.Remote&&this._notifySettings.remote?this.sendResponse(new g(exports.AsynchronousCode.RemoteInfo,n)):e===exports.NotifyType.Slot&&this._notifySettings.slot?this.sendResponse(new g(exports.AsynchronousCode.SlotInfo,n)):e===exports.NotifyType.Transport&&this._notifySettings.transport&&this.sendResponse(new g(exports.AsynchronousCode.TransportInfo,n))},n}(o.EventEmitter),K=function(e){function n(){return e.apply(this,arguments)||this}return s(n,e),n}(p(Error)),A=function(){try{throw new K}catch(e){return Promise.reject(e)}};exports.HyperdeckServer=function(){function e(e,n){var o=this;void 0===n&&(n=i()),this._sockets={},this.onDeviceInfo=A,this.onDiskList=A,this.onPreview=A,this.onPlay=A,this.onPlayrangeSet=A,this.onPlayrangeClear=A,this.onRecord=A,this.onStop=A,this.onClipsCount=A,this.onClipsGet=A,this.onClipsAdd=A,this.onClipsClear=A,this.onTransportInfo=A,this.onSlotInfo=A,this.onSlotSelect=A,this.onGoTo=A,this.onJog=A,this.onShuttle=A,this.onConfiguration=A,this.onUptime=A,this.onFormat=A,this.onIdentify=A,this.onWatchdog=A,this.logger=n.child({name:"HyperDeck Emulator"}),this._server=t.createServer((function(e){o.logger.info("connection");var n=Math.random().toString(35).substr(-6),r=o.logger.child({name:"HyperDeck socket "+n});o._sockets[n]=new N(e,r,(function(e){return o._receivedCommand(e)})),o._sockets[n].on("disconnected",(function(){r.info("disconnected"),delete o._sockets[n]}))})),this._server.on("listening",(function(){return o.logger.info("listening")})),this._server.on("close",(function(){return o.logger.info("connection closed")})),this._server.on("error",(function(e){return o.logger.error("server error:",e)})),this._server.maxConnections=1,this._server.listen(9993,e)}var n=e.prototype;return n.close=function(){this._server.unref()},n.notifySlot=function(e){this._notify(exports.NotifyType.Slot,e)},n.notifyTransport=function(e){this._notify(exports.NotifyType.Transport,e)},n._notify=function(e,n){for(var o=0,r=Object.keys(this._sockets);o<r.length;o++)this._sockets[r[o]].notify(e,n)},n._receivedCommand=function(e){try{var n=this;return Promise.resolve(new Promise((function(e){return setTimeout((function(){return e()}),200)}))).then((function(){var o=!1;return n.logger.info({cmd:e},"<-- "+e.name),function(r,t){try{var i=function(){function r(r){var t=!1;if(o)return r;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(o){var r=!1;if(t)return o;function i(o){var t=!1;if(r)return o;function i(n){if(t)return n;if(e.name===v.WatchdogCommand)return new g(exports.SynchronousCode.OK);if(e.name===v.PingCommand)return new g(exports.SynchronousCode.OK);throw new Error("Unhandled command name: "+e.name)}var s=function(){if(e.name===v.IdentifyCommand)return Promise.resolve(n.onIdentify(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.FormatCommand)return Promise.resolve(n.onFormat(e)).then((function(e){return e?(r=!0,new g(exports.SynchronousCode.FormatReady,e)):(r=!0,new g(exports.SynchronousCode.OK))}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.UptimeCommand)return Promise.resolve(n.onUptime(e)).then((function(e){return t=!0,new g(exports.SynchronousCode.Uptime,e)}))}();return s&&s.then?s.then(i):i(s)}if(e.name===v.RemoteCommand)return new g(exports.SynchronousCode.Remote,{enabled:!0,override:!1});var s=function(){if(e.name===v.ConfigurationCommand)return Promise.resolve(n.onConfiguration(e)).then((function(e){return e?(r=!0,new g(exports.SynchronousCode.Configuration,e)):(r=!0,new g(exports.SynchronousCode.OK))}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.ShuttleCommand)return Promise.resolve(n.onShuttle(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.JogCommand)return Promise.resolve(n.onJog(e)).then((function(){return r=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}if(e.name===v.NotifyCommand)return new g(exports.SynchronousCode.OK);var s=function(){if(e.name===v.GoToCommand)return Promise.resolve(n.onGoTo(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.SlotSelectCommand)return Promise.resolve(n.onSlotSelect(e)).then((function(){return r=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.SlotInfoCommand)return Promise.resolve(n.onSlotInfo(e)).then((function(e){return t=!0,new g(exports.SynchronousCode.SlotInfo,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.TransportInfoCommand)return Promise.resolve(n.onTransportInfo(e)).then((function(e){return r=!0,new g(exports.SynchronousCode.TransportInfo,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.ClipsClearCommand)return Promise.resolve(n.onClipsClear(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.ClipsAddCommand)return Promise.resolve(n.onClipsAdd(e)).then((function(){return r=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.ClipsGetCommand)return Promise.resolve(n.onClipsGet(e).then(S)).then((function(e){return t=!0,new g(exports.SynchronousCode.ClipsInfo,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.ClipsCountCommand)return Promise.resolve(n.onClipsCount(e)).then((function(e){return r=!0,new g(exports.SynchronousCode.ClipsCount,e)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.StopCommand)return Promise.resolve(n.onStop(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.RecordCommand)return Promise.resolve(n.onRecord(e)).then((function(){return r=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.PlayrangeClearCommand)return Promise.resolve(n.onPlayrangeClear(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.PlayrangeSetCommand)return Promise.resolve(n.onPlayrangeSet(e)).then((function(){return r=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.PlayCommand)return Promise.resolve(n.onPlay(e)).then((function(){return t=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.PreviewCommand)return Promise.resolve(n.onPreview(e)).then((function(){return r=!0,new g(exports.SynchronousCode.OK)}))}();return s&&s.then?s.then(i):i(s)}var s=function(){if(e.name===v.DiskListCommand)return Promise.resolve(n.onDiskList(e)).then((function(e){return t=!0,new g(exports.SynchronousCode.DiskList,e)}))}();return s&&s.then?s.then(i):i(s)}var t=function(){if(e.name===v.DeviceInfoCommand)return Promise.resolve(n.onDeviceInfo(e)).then((function(e){return o=!0,new g(exports.SynchronousCode.DeviceInfo,e)}))}();return t&&t.then?t.then(r):r(t)}()}catch(e){return t(e)}return i&&i.then?i.then(void 0,t):i}(0,(function(o){return o instanceof K?(n.logger.error({cmd:e},"unimplemented"),new g(exports.ErrorCode.Unsupported)):o&&"number"==typeof o.code&&exports.ErrorCode[o.code]&&o.msg?(n.logger.error({err:o},"error with code"),new x(o.code,o.msg)):(n.logger.error({cmd:e},"internal error"),new g(exports.ErrorCode.InternalError))}))}))}catch(e){return Promise.reject(e)}},e}(),exports.ResponseInterface={__proto__:null},exports.Timecode=b;
//# sourceMappingURL=hyperdeck-emulator.cjs.production.min.js.map
import { EventEmitter } from 'events';
import { format } from 'util';
import util from 'util';
import { createServer } from 'net';

@@ -163,40 +163,43 @@ import pino from 'pino';

function invariant(condition, message) {
if (!condition) {
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
throw new Error(util.format.apply(util, [message].concat(args)));
}
}
var _responseNamesByCode;
var CRLF = '\r\n';
var TResponse = /*#__PURE__*/function () {
function TResponse(code, params) {
this.code = code;
this.params = params;
this.name = responseNamesByCode[code];
}
var TResponse = function TResponse(code, params) {
var _this = this;
var _proto = TResponse.prototype;
this.code = code;
this.params = params;
_proto.build = function build() {
var data = format('%d %s', this.code, this.name);
this.build = function () {
return messageForCode(_this.code, _this.params);
};
if (this.params) {
data += ':' + CRLF;
!responseNamesByCode.hasOwnProperty(code) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid code: `%o`', code) : invariant(false) : void 0;
this.name = responseNamesByCode[code];
};
var formatClipsGetResponse = function formatClipsGetResponse(res) {
var clipsCount = res.clips.length;
var response = {
clipsCount: clipsCount
};
for (var _i = 0, _Object$entries = Object.entries(this.params); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _Object$entries[_i],
key = _Object$entries$_i[0],
value = _Object$entries$_i[1];
for (var idx = 0; idx < clipsCount; idx++) {
var clip = res.clips[idx];
var clipKey = (idx + 1).toString();
response[clipKey] = clip.name + " " + clip.startT + " " + clip.duration;
}
if (!value) {
continue;
}
data += format('%s: %s', key, value) + CRLF;
}
}
data += CRLF;
return data;
};
return TResponse;
}();
return response;
};
var ErrorResponse = function ErrorResponse(code, message) {
var _this = this;
var _this2 = this;

@@ -207,4 +210,6 @@ this.code = code;

this.build = function () {
return format('%d %s', _this.code, _this.message);
return _this2.code + ' ' + _this2.message + CRLF;
};
!responseNamesByCode.hasOwnProperty(code) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid code: `%o`', code) : invariant(false) : void 0;
};

@@ -302,2 +307,62 @@ var ErrorCode;

var responseNamesByCode = (_responseNamesByCode = {}, _responseNamesByCode[AsynchronousCode.ConfigurationInfo] = 'configuration info', _responseNamesByCode[AsynchronousCode.ConnectionInfo] = 'connection info', _responseNamesByCode[AsynchronousCode.RemoteInfo] = 'remote info', _responseNamesByCode[AsynchronousCode.SlotInfo] = CommandNames.SlotInfoCommand, _responseNamesByCode[AsynchronousCode.TransportInfo] = CommandNames.TransportInfoCommand, _responseNamesByCode[ErrorCode.ConnectionRejected] = 'connection rejected', _responseNamesByCode[ErrorCode.DiskError] = 'disk error', _responseNamesByCode[ErrorCode.DiskFull] = 'disk full', _responseNamesByCode[ErrorCode.FormatNotPrepared] = 'format not prepared', _responseNamesByCode[ErrorCode.InternalError] = 'internal error', _responseNamesByCode[ErrorCode.InvalidCodec] = 'invalid codec', _responseNamesByCode[ErrorCode.InvalidFormat] = 'invalid format', _responseNamesByCode[ErrorCode.InvalidState] = 'invalid state', _responseNamesByCode[ErrorCode.InvalidToken] = 'invalid token', _responseNamesByCode[ErrorCode.InvalidValue] = 'invalid value', _responseNamesByCode[ErrorCode.NoDisk] = 'no disk', _responseNamesByCode[ErrorCode.NoInput] = 'no input', _responseNamesByCode[ErrorCode.OutOfRange] = 'out of range', _responseNamesByCode[ErrorCode.RemoteControlDisabled] = 'remote control disabled', _responseNamesByCode[ErrorCode.SyntaxError] = 'syntax error', _responseNamesByCode[ErrorCode.TimelineEmpty] = 'timeline empty', _responseNamesByCode[ErrorCode.Unsupported] = 'unsupported', _responseNamesByCode[ErrorCode.UnsupportedParameter] = 'unsupported parameter', _responseNamesByCode[SynchronousCode.ClipsCount] = CommandNames.ClipsCountCommand, _responseNamesByCode[SynchronousCode.ClipsInfo] = 'clips info', _responseNamesByCode[SynchronousCode.Configuration] = CommandNames.ConfigurationCommand, _responseNamesByCode[SynchronousCode.DeviceInfo] = CommandNames.DeviceInfoCommand, _responseNamesByCode[SynchronousCode.DiskList] = CommandNames.DiskListCommand, _responseNamesByCode[SynchronousCode.FormatReady] = 'format ready', _responseNamesByCode[SynchronousCode.Notify] = CommandNames.NotifyCommand, _responseNamesByCode[SynchronousCode.OK] = 'ok', _responseNamesByCode[SynchronousCode.Remote] = CommandNames.RemoteCommand, _responseNamesByCode[SynchronousCode.SlotInfo] = CommandNames.SlotInfoCommand, _responseNamesByCode[SynchronousCode.TransportInfo] = CommandNames.TransportInfoCommand, _responseNamesByCode[SynchronousCode.Uptime] = CommandNames.UptimeCommand, _responseNamesByCode);
var Timecode = /*#__PURE__*/function () {
function Timecode(hh, mm, ss, ff) {
this._timecode = [hh, mm, ss, ff].map(function (code) {
var codeInt = Math.floor(code);
if (codeInt !== code || code < 0 || code > 99) {
throw new Error('Timecode params must be an integer between 0 and 99');
} // turn the integer into a potentially zero-prefixed string
return (codeInt + 100).toString().slice(-2);
}).join(':');
}
var _proto = Timecode.prototype;
_proto.toString = function toString() {
return this._timecode;
};
return Timecode;
}();
var messageForCode = function messageForCode(code, params) {
var firstLine = code + " " + responseNamesByCode[code]; // bail if no params
if (!params) {
return firstLine + CRLF;
} // filter out params with null/undefined values
var paramEntries = Object.entries(params).filter(function (_ref) {
var value = _ref[1];
return value != null;
}); // bail if no params after filtering
if (paramEntries.length === 0) {
return firstLine + CRLF;
} // turn the params object into a key/value
return paramEntries.reduce(function (prev, _ref2) {
var key = _ref2[0],
value = _ref2[1];
var valueString;
if (typeof value === 'string') {
valueString = value;
} else if (typeof value === 'boolean') {
valueString = value ? 'true' : 'false';
} else if (typeof value === 'number') {
valueString = value.toString();
} else {
throw new Error('Unhandled value type: ' + typeof value);
} // convert camelCase keys to space-separated words
var formattedKey = key.replace(/([a-z])([A-Z]+)/, '$1 $2').toLowerCase();
return prev + formattedKey + ': ' + valueString + CRLF;
}, firstLine + ':' + CRLF) + CRLF;
};
var ParameterMap = {

@@ -416,3 +481,3 @@ help: [],

this._log = logger.child({
source: 'MultilineParser'
name: 'MultilineParser'
});

@@ -566,3 +631,3 @@ }

};
_this._parser = new MultilineParser(_this.logger);
_this._parser = new MultilineParser(logger);

@@ -586,3 +651,3 @@ _this._socket.setEncoding('utf-8');

_this.sendResponse(new TResponse(AsynchronousCode.ConnectionInfo, {
'protocol version': '1.6',
'protocol version': '1.11',
model: 'NodeJS Hyperdeck Server Library'

@@ -599,3 +664,5 @@ }));

this.logger.debug('onMessage(%s)', data);
this.logger.info({
data: data
}, 'onMessage');
this._lastReceived = Date.now();

@@ -605,5 +672,7 @@

this.logger.debug('commands:', cmds);
this.logger.info({
cmds: cmds
}, 'commands');
for (var _iterator = _createForOfIteratorHelperLoose(cmds), _step; !(_step = _iterator()).done;) {
var _loop = function _loop() {
var cmd = _step.value;

@@ -613,20 +682,18 @@

if (cmd.name === CommandNames.WatchdogCommand) {
(function () {
if (_this2._watchdogTimer) clearInterval(_this2._watchdogTimer);
var watchdogCmd = cmd;
if (_this2._watchdogTimer) clearInterval(_this2._watchdogTimer);
var watchdogCmd = cmd;
if (watchdogCmd.parameters.period) {
_this2._watchdogTimer = setInterval(function () {
if (Date.now() - _this2._lastReceived > Number(watchdogCmd.parameters.period)) {
_this2._socket.destroy();
if (watchdogCmd.parameters.period) {
_this2._watchdogTimer = setInterval(function () {
if (Date.now() - _this2._lastReceived > Number(watchdogCmd.parameters.period)) {
_this2._socket.destroy();
_this2.emit('disconnected');
_this2.emit('disconnected');
if (_this2._watchdogTimer) {
clearInterval(_this2._watchdogTimer);
}
if (_this2._watchdogTimer) {
clearInterval(_this2._watchdogTimer);
}
}, Number(watchdogCmd.parameters.period) * 1000);
}
})();
}
}, Number(watchdogCmd.parameters.period) * 1000);
}
} else if (cmd.name === CommandNames.NotifyCommand) {

@@ -639,4 +706,4 @@ var notifyCmd = cmd;

if (this._notifySettings[param] !== undefined) {
this._notifySettings[param] = notifyCmd.parameters[param] === 'true';
if (_this2._notifySettings[param] !== undefined) {
_this2._notifySettings[param] = notifyCmd.parameters[param] === 'true';
}

@@ -647,35 +714,50 @@ }

for (var _i2 = 0, _Object$keys2 = Object.keys(this._notifySettings); _i2 < _Object$keys2.length; _i2++) {
for (var _i2 = 0, _Object$keys2 = Object.keys(_this2._notifySettings); _i2 < _Object$keys2.length; _i2++) {
var key = _Object$keys2[_i2];
settings[key] = this._notifySettings[key] ? 'true' : 'false';
settings[key] = _this2._notifySettings[key] ? 'true' : 'false';
}
this.sendResponse(new TResponse(SynchronousCode.Notify, settings));
continue;
_this2.sendResponse(new TResponse(SynchronousCode.Notify, settings), cmd);
return "continue";
}
}
this._receivedCommand(cmd).then(function (res) {
_this2.logger.info({
res: res
}, '_receivedCommand response');
_this2._receivedCommand(cmd).then(function (res) {
return _this2.sendResponse(res, cmd);
}, // not implemented by client code:
function () {
return _this2.sendResponse(new TResponse(ErrorCode.Unsupported), cmd);
});
};
_this2.sendResponse(res);
}, function () {
_this2.logger.error({}, '_receivedCommand error response'); // not implemented by client code:
for (var _iterator = _createForOfIteratorHelperLoose(cmds), _step; !(_step = _iterator()).done;) {
var _ret = _loop();
_this2.sendResponse(new TResponse(ErrorCode.Unsupported));
});
if (_ret === "continue") continue;
}
};
_proto.sendResponse = function sendResponse(res) {
var msg = res.build();
_proto.sendResponse = function sendResponse(res, cmd) {
var responseText = res.build();
var txt = '--> ' + ((cmd === null || cmd === void 0 ? void 0 : cmd.name) || 'sendResponse');
this._socket.write(msg);
if (res instanceof TResponse && ErrorCode[res.code]) {
this.logger.error({
responseText: responseText
}, txt);
} else {
this.logger.info({
responseText: responseText
}, txt);
}
this._socket.write(responseText);
};
_proto.notify = function notify(type, params) {
this.logger.debug('notify:', type, params);
this.logger.info({
type: type,
params: params
}, 'notify');

@@ -741,3 +823,2 @@ if (type === NotifyType.Configuration && this._notifySettings.configuration) {

this.onShuttle = noop;
this.onRemote = noop;
this.onConfiguration = noop;

@@ -749,11 +830,14 @@ this.onUptime = noop;

this.logger = logger.child({
source: 'HyperDeck Emulator'
name: 'HyperDeck Emulator'
});
this._server = createServer(function (socket) {
_this.logger.debug('connection');
_this.logger.info('connection');
var socketId = Math.random().toString(35).substr(-6);
_this._sockets[socketId] = new HyperdeckSocket(socket, _this.logger.child({
source: 'HyperDeck socket ' + socketId
}), function (cmd) {
var socketLogger = _this.logger.child({
name: 'HyperDeck socket ' + socketId
});
_this._sockets[socketId] = new HyperdeckSocket(socket, socketLogger, function (cmd) {
return _this._receivedCommand(cmd);

@@ -763,2 +847,3 @@ });

_this._sockets[socketId].on('disconnected', function () {
socketLogger.info('disconnected');
delete _this._sockets[socketId];

@@ -809,101 +894,103 @@ });

try {
var _exit24 = false;
var _this3 = this;
_this3.logger.info({
cmd: cmd
}, '_receivedCommand');
// TODO(meyer) more sophisticated debouncing
return Promise.resolve(new Promise(function (resolve) {
return setTimeout(function () {
return resolve();
}, 200);
})).then(function () {
var _exit = false;
return Promise.resolve(_catch(function () {
function _temp46(_result) {
var _exit2 = false;
if (_exit24) return _result;
_this3.logger.info({
cmd: cmd
}, '<-- ' + cmd.name);
function _temp44(_result2) {
var _exit3 = false;
if (_exit2) return _result2;
return _catch(function () {
function _temp44(_result) {
var _exit2 = false;
if (_exit) return _result;
function _temp42(_result3) {
var _exit4 = false;
if (_exit3) return _result3;
function _temp42(_result2) {
var _exit3 = false;
if (_exit2) return _result2;
function _temp40(_result4) {
var _exit5 = false;
if (_exit4) return _result4;
function _temp40(_result3) {
var _exit4 = false;
if (_exit3) return _result3;
function _temp38(_result5) {
var _exit6 = false;
if (_exit5) return _result5;
function _temp38(_result4) {
var _exit5 = false;
if (_exit4) return _result4;
function _temp36(_result6) {
var _exit7 = false;
if (_exit6) return _result6;
function _temp36(_result5) {
var _exit6 = false;
if (_exit5) return _result5;
function _temp34(_result7) {
var _exit8 = false;
if (_exit7) return _result7;
function _temp34(_result6) {
var _exit7 = false;
if (_exit6) return _result6;
function _temp32(_result8) {
var _exit9 = false;
if (_exit8) return _result8;
function _temp32(_result7) {
var _exit8 = false;
if (_exit7) return _result7;
function _temp30(_result9) {
var _exit10 = false;
if (_exit9) return _result9;
function _temp30(_result8) {
var _exit9 = false;
if (_exit8) return _result8;
function _temp28(_result10) {
var _exit11 = false;
if (_exit10) return _result10;
function _temp28(_result9) {
var _exit10 = false;
if (_exit9) return _result9;
function _temp26(_result11) {
var _exit12 = false;
if (_exit11) return _result11;
function _temp26(_result10) {
var _exit11 = false;
if (_exit10) return _result10;
function _temp24(_result12) {
var _exit13 = false;
if (_exit12) return _result12;
function _temp24(_result11) {
var _exit12 = false;
if (_exit11) return _result11;
function _temp22(_result13) {
var _exit14 = false;
if (_exit13) return _result13;
function _temp22(_result12) {
var _exit13 = false;
if (_exit12) return _result12;
function _temp20(_result14) {
var _exit15 = false;
if (_exit14) return _result14;
function _temp20(_result13) {
var _exit14 = false;
if (_exit13) return _result13;
function _temp18(_result15) {
var _exit16 = false;
if (_exit15) return _result15;
function _temp18(_result14) {
var _exit15 = false;
if (_exit14) return _result14;
function _temp16(_result16) {
var _exit17 = false;
if (_exit16) return _result16;
function _temp16(_result15) {
var _exit16 = false;
if (_exit15) return _result15;
function _temp14(_result17) {
var _exit18 = false;
if (_exit17) return _result17;
function _temp14(_result16) {
var _exit17 = false;
if (_exit16) return _result16;
function _temp12(_result18) {
var _exit19 = false;
if (_exit18) return _result18;
function _temp12(_result17) {
var _exit18 = false;
if (_exit17) return _result17;
function _temp10(_result19) {
var _exit20 = false;
if (_exit19) return _result19;
function _temp10(_result18) {
var _exit19 = false;
if (_exit18) return _result18;
function _temp8(_result20) {
var _exit21 = false;
if (_exit20) return _result20;
function _temp8(_result19) {
var _exit20 = false;
if (_exit19) return _result19;
function _temp6(_result21) {
var _exit22 = false;
if (_exit21) return _result21;
function _temp6(_result20) {
var _exit21 = false;
if (_exit20) return _result20;
function _temp4(_result22) {
var _exit23 = false;
if (_exit22) return _result22;
function _temp4(_result21) {
var _exit22 = false;
if (_exit21) return _result21;
function _temp2(_result23) {
if (_exit23) return _result23;
function _temp2(_result22) {
if (_exit22) return _result22;

@@ -926,3 +1013,3 @@ if (cmd.name === CommandNames.WatchdogCommand) {

return Promise.resolve(_this3.onIdentify(cmd)).then(function () {
_exit23 = true;
_exit22 = true;
return new TResponse(SynchronousCode.OK);

@@ -940,7 +1027,7 @@ });

if (res) {
_exit22 = true;
_exit21 = true;
return new TResponse(SynchronousCode.FormatReady, res);
}
_exit22 = true;
_exit21 = true;
return new TResponse(SynchronousCode.OK);

@@ -957,3 +1044,3 @@ });

return Promise.resolve(_this3.onUptime(cmd)).then(function (res) {
_exit21 = true;
_exit20 = true;
return new TResponse(SynchronousCode.Uptime, res);

@@ -967,2 +1054,9 @@ });

if (cmd.name === CommandNames.RemoteCommand) {
return new TResponse(SynchronousCode.Remote, {
enabled: true,
override: false
});
}
var _temp7 = function () {

@@ -972,7 +1066,7 @@ if (cmd.name === CommandNames.ConfigurationCommand) {

if (res) {
_exit20 = true;
_exit19 = true;
return new TResponse(SynchronousCode.Configuration, res);
}
_exit20 = true;
_exit19 = true;
return new TResponse(SynchronousCode.OK);

@@ -987,11 +1081,6 @@ });

var _temp9 = function () {
if (cmd.name === CommandNames.RemoteCommand) {
return Promise.resolve(_this3.onRemote(cmd)).then(function (res) {
if (!res) {
_exit19 = true;
return new TResponse(SynchronousCode.OK);
}
_exit19 = true;
return new TResponse(SynchronousCode.Remote, res);
if (cmd.name === CommandNames.ShuttleCommand) {
return Promise.resolve(_this3.onShuttle(cmd)).then(function () {
_exit18 = true;
return new TResponse(SynchronousCode.OK);
});

@@ -1005,5 +1094,5 @@ }

var _temp11 = function () {
if (cmd.name === CommandNames.ShuttleCommand) {
return Promise.resolve(_this3.onShuttle(cmd)).then(function () {
_exit18 = true;
if (cmd.name === CommandNames.JogCommand) {
return Promise.resolve(_this3.onJog(cmd)).then(function () {
_exit17 = true;
return new TResponse(SynchronousCode.OK);

@@ -1017,6 +1106,11 @@ });

if (cmd.name === CommandNames.NotifyCommand) {
// implemented in socket.ts
return new TResponse(SynchronousCode.OK);
}
var _temp13 = function () {
if (cmd.name === CommandNames.JogCommand) {
return Promise.resolve(_this3.onJog(cmd)).then(function () {
_exit17 = true;
if (cmd.name === CommandNames.GoToCommand) {
return Promise.resolve(_this3.onGoTo(cmd)).then(function () {
_exit16 = true;
return new TResponse(SynchronousCode.OK);

@@ -1030,11 +1124,6 @@ });

if (cmd.name === CommandNames.NotifyCommand) {
// implemented in socket.ts
return new TResponse(SynchronousCode.OK);
}
var _temp15 = function () {
if (cmd.name === CommandNames.GoToCommand) {
return Promise.resolve(_this3.onGoTo(cmd)).then(function () {
_exit16 = true;
if (cmd.name === CommandNames.SlotSelectCommand) {
return Promise.resolve(_this3.onSlotSelect(cmd)).then(function () {
_exit15 = true;
return new TResponse(SynchronousCode.OK);

@@ -1049,6 +1138,6 @@ });

var _temp17 = function () {
if (cmd.name === CommandNames.SlotSelectCommand) {
return Promise.resolve(_this3.onSlotSelect(cmd)).then(function () {
_exit15 = true;
return new TResponse(SynchronousCode.OK);
if (cmd.name === CommandNames.SlotInfoCommand) {
return Promise.resolve(_this3.onSlotInfo(cmd)).then(function (res) {
_exit14 = true;
return new TResponse(SynchronousCode.SlotInfo, res);
});

@@ -1062,6 +1151,6 @@ }

var _temp19 = function () {
if (cmd.name === CommandNames.SlotInfoCommand) {
return Promise.resolve(_this3.onSlotInfo(cmd)).then(function (res) {
_exit14 = true;
return new TResponse(SynchronousCode.SlotInfo, res);
if (cmd.name === CommandNames.TransportInfoCommand) {
return Promise.resolve(_this3.onTransportInfo(cmd)).then(function (res) {
_exit13 = true;
return new TResponse(SynchronousCode.TransportInfo, res);
});

@@ -1075,6 +1164,6 @@ }

var _temp21 = function () {
if (cmd.name === CommandNames.TransportInfoCommand) {
return Promise.resolve(_this3.onTransportInfo(cmd)).then(function (res) {
_exit13 = true;
return new TResponse(SynchronousCode.TransportInfo, res);
if (cmd.name === CommandNames.ClipsClearCommand) {
return Promise.resolve(_this3.onClipsClear(cmd)).then(function () {
_exit12 = true;
return new TResponse(SynchronousCode.OK);
});

@@ -1088,5 +1177,5 @@ }

var _temp23 = function () {
if (cmd.name === CommandNames.ClipsClearCommand) {
return Promise.resolve(_this3.onClipsClear(cmd)).then(function () {
_exit12 = true;
if (cmd.name === CommandNames.ClipsAddCommand) {
return Promise.resolve(_this3.onClipsAdd(cmd)).then(function () {
_exit11 = true;
return new TResponse(SynchronousCode.OK);

@@ -1101,6 +1190,6 @@ });

var _temp25 = function () {
if (cmd.name === CommandNames.ClipsAddCommand) {
return Promise.resolve(_this3.onClipsAdd(cmd)).then(function () {
_exit11 = true;
return new TResponse(SynchronousCode.OK);
if (cmd.name === CommandNames.ClipsGetCommand) {
return Promise.resolve(_this3.onClipsGet(cmd).then(formatClipsGetResponse)).then(function (res) {
_exit10 = true;
return new TResponse(SynchronousCode.ClipsInfo, res);
});

@@ -1114,6 +1203,6 @@ }

var _temp27 = function () {
if (cmd.name === CommandNames.ClipsGetCommand) {
return Promise.resolve(_this3.onClipsGet(cmd)).then(function (res) {
_exit10 = true;
return new TResponse(SynchronousCode.ClipsInfo, res);
if (cmd.name === CommandNames.ClipsCountCommand) {
return Promise.resolve(_this3.onClipsCount(cmd)).then(function (res) {
_exit9 = true;
return new TResponse(SynchronousCode.ClipsCount, res);
});

@@ -1127,6 +1216,6 @@ }

var _temp29 = function () {
if (cmd.name === CommandNames.ClipsCountCommand) {
return Promise.resolve(_this3.onClipsCount(cmd)).then(function (res) {
_exit9 = true;
return new TResponse(SynchronousCode.ClipsCount, res);
if (cmd.name === CommandNames.StopCommand) {
return Promise.resolve(_this3.onStop(cmd)).then(function () {
_exit8 = true;
return new TResponse(SynchronousCode.OK);
});

@@ -1140,5 +1229,5 @@ }

var _temp31 = function () {
if (cmd.name === CommandNames.StopCommand) {
return Promise.resolve(_this3.onStop(cmd)).then(function () {
_exit8 = true;
if (cmd.name === CommandNames.RecordCommand) {
return Promise.resolve(_this3.onRecord(cmd)).then(function () {
_exit7 = true;
return new TResponse(SynchronousCode.OK);

@@ -1153,5 +1242,5 @@ });

var _temp33 = function () {
if (cmd.name === CommandNames.RecordCommand) {
return Promise.resolve(_this3.onRecord(cmd)).then(function () {
_exit7 = true;
if (cmd.name === CommandNames.PlayrangeClearCommand) {
return Promise.resolve(_this3.onPlayrangeClear(cmd)).then(function () {
_exit6 = true;
return new TResponse(SynchronousCode.OK);

@@ -1166,5 +1255,5 @@ });

var _temp35 = function () {
if (cmd.name === CommandNames.PlayrangeClearCommand) {
return Promise.resolve(_this3.onPlayrangeClear(cmd)).then(function () {
_exit6 = true;
if (cmd.name === CommandNames.PlayrangeSetCommand) {
return Promise.resolve(_this3.onPlayrangeSet(cmd)).then(function () {
_exit5 = true;
return new TResponse(SynchronousCode.OK);

@@ -1179,5 +1268,5 @@ });

var _temp37 = function () {
if (cmd.name === CommandNames.PlayrangeSetCommand) {
return Promise.resolve(_this3.onPlayrangeSet(cmd)).then(function () {
_exit5 = true;
if (cmd.name === CommandNames.PlayCommand) {
return Promise.resolve(_this3.onPlay(cmd)).then(function () {
_exit4 = true;
return new TResponse(SynchronousCode.OK);

@@ -1192,5 +1281,5 @@ });

var _temp39 = function () {
if (cmd.name === CommandNames.PlayCommand) {
return Promise.resolve(_this3.onPlay(cmd)).then(function () {
_exit4 = true;
if (cmd.name === CommandNames.PreviewCommand) {
return Promise.resolve(_this3.onPreview(cmd)).then(function () {
_exit3 = true;
return new TResponse(SynchronousCode.OK);

@@ -1205,6 +1294,6 @@ });

var _temp41 = function () {
if (cmd.name === CommandNames.PreviewCommand) {
return Promise.resolve(_this3.onPreview(cmd)).then(function () {
_exit3 = true;
return new TResponse(SynchronousCode.OK);
if (cmd.name === CommandNames.DiskListCommand) {
return Promise.resolve(_this3.onDiskList(cmd)).then(function (res) {
_exit2 = true;
return new TResponse(SynchronousCode.DiskList, res);
});

@@ -1218,6 +1307,6 @@ }

var _temp43 = function () {
if (cmd.name === CommandNames.DiskListCommand) {
return Promise.resolve(_this3.onDiskList(cmd)).then(function (res) {
_exit2 = true;
return new TResponse(SynchronousCode.DiskList, res);
if (cmd.name === CommandNames.DeviceInfoCommand) {
return Promise.resolve(_this3.onDeviceInfo(cmd)).then(function (res) {
_exit = true;
return new TResponse(SynchronousCode.DeviceInfo, res);
});

@@ -1228,21 +1317,26 @@ }

return _temp43 && _temp43.then ? _temp43.then(_temp44) : _temp44(_temp43);
}
}, function (err) {
if (err instanceof UnimplementedError) {
_this3.logger.error({
cmd: cmd
}, 'unimplemented');
var _temp45 = function () {
if (cmd.name === CommandNames.DeviceInfoCommand) {
return Promise.resolve(_this3.onDeviceInfo(cmd)).then(function (res) {
_exit24 = true;
return new TResponse(SynchronousCode.DeviceInfo, res);
});
return new TResponse(ErrorCode.Unsupported);
}
}();
return _temp45 && _temp45.then ? _temp45.then(_temp46) : _temp46(_temp45);
}, function (err) {
if (err instanceof UnimplementedError) {
return new TResponse(ErrorCode.Unsupported);
}
if (err && typeof err.code === 'number' && ErrorCode[err.code] && err.msg) {
_this3.logger.error({
err: err
}, 'error with code');
return err && typeof err.code === 'number' && ErrorCode[err.code] && err.msg ? new ErrorResponse(err.code, err.msg) : new TResponse(ErrorCode.InternalError);
}));
return new ErrorResponse(err.code, err.msg);
}
_this3.logger.error({
cmd: cmd
}, 'internal error');
return new TResponse(ErrorCode.InternalError);
});
});
} catch (e) {

@@ -1256,3 +1350,3 @@ return Promise.reject(e);

export { AsynchronousCode, ErrorCode, FileFormats, HyperdeckServer, NotifyType, ResponseInterface, SynchronousCode, TransportStatus, VideoFormat };
export { AsynchronousCode, ErrorCode, FileFormats, HyperdeckServer, NotifyType, ResponseInterface, SlotStatus, SynchronousCode, Timecode, TransportStatus, VideoFormat };
//# sourceMappingURL=hyperdeck-emulator.esm.js.map
export * from './server';
export { ResponseInterface, ErrorCode, AsynchronousCode, NotifyType, SynchronousCode, FileFormats, VideoFormat, TransportStatus } from './types';
export { ResponseInterface, ErrorCode, AsynchronousCode, NotifyType, SynchronousCode, FileFormats, SlotStatus, VideoFormat, TransportStatus, Timecode } from './types';
//# sourceMappingURL=index.d.ts.map

@@ -0,2 +1,4 @@

/// <reference types="node" />
import { DeserializedCommand, DeserializedCommands, Hash, ResponseInterface } from './types';
import { Server } from 'net';
import pino from 'pino';

@@ -7,3 +9,3 @@ declare type Handler<C extends DeserializedCommand, R extends any> = (command: C) => Promise<R>;

private _sockets;
private _server;
readonly _server: Server;
onDeviceInfo: Handler<DeserializedCommand, ResponseInterface.DeviceInfo>;

@@ -27,3 +29,2 @@ onDiskList: Handler<DeserializedCommand, ResponseInterface.DiskList>;

onShuttle: Handler<DeserializedCommands.ShuttleCommand, void>;
onRemote: Handler<DeserializedCommands.RemoteCommand, void | Record<string, string>>;
onConfiguration: Handler<DeserializedCommands.ConfigurationCommand, ResponseInterface.Configuration>;

@@ -30,0 +31,0 @@ onUptime: Handler<DeserializedCommand, ResponseInterface.Uptime>;

/// <reference types="node" />
import { Socket } from 'net';
import type { Socket } from 'net';
import { EventEmitter } from 'events';

@@ -16,5 +16,5 @@ import { DeserializedCommand, NotifyType, Hash, Buildable } from './types';

private _onMessage;
sendResponse(res: Buildable): void;
sendResponse(res: Buildable, cmd?: DeserializedCommand): void;
notify(type: NotifyType, params: Hash<string>): void;
}
//# sourceMappingURL=socket.d.ts.map

@@ -19,9 +19,10 @@ import * as DeserializedCommands from './types/DeserializedCommands';

}
export declare class TResponse<P extends Record<string, any> = Record<string, any>> implements Buildable {
export declare class TResponse<T extends Record<string, any> = Record<string, any>> implements Buildable {
code: ResponseCode;
params?: P | undefined;
constructor(code: ResponseCode, params?: P | undefined);
params?: T | undefined;
constructor(code: ResponseCode, params?: T | undefined);
name: string;
build(): string;
build: () => string;
}
export declare const formatClipsGetResponse: (res: ResponseInterface.ClipsGet) => Record<string, string | number>;
export declare class ErrorResponse implements Buildable {

@@ -36,5 +37,3 @@ code: ResponseCode;

name: string;
parameters: {
[key: string]: string | undefined;
};
parameters: Record<string, string | undefined>;
}

@@ -118,2 +117,8 @@ export declare type ResponseCode = ErrorCode | SynchronousCode | AsynchronousCode;

export declare const responseNamesByCode: Record<ResponseCode, string>;
export declare class Timecode {
constructor(hh: number, mm: number, ss: number, ff: number);
private _timecode;
toString(): string;
}
export declare const messageForCode: (code: ResponseCode, params?: Record<string, unknown> | undefined) => string;
export declare const ParameterMap: {

@@ -120,0 +125,0 @@ help: never[];

@@ -1,2 +0,2 @@

import { Hash } from '../types';
import { Hash, Timecode } from '../types';
import { TransportStatus, VideoFormat, SlotStatus, AudioInputs, VideoInputs, FileFormats } from '../types';

@@ -14,5 +14,17 @@ export interface DeviceInfo {

}
export interface ClipsGet extends Hash<string> {
'clip count': string;
export interface ClipV1 {
name: string;
startT: Timecode;
duration: Timecode;
}
export interface ClipV2 {
startT: Timecode;
duration: number;
inT: Timecode;
outT: Timecode;
name: string;
}
export interface ClipsGet {
clips: ClipV1[];
}
export interface TransportInfo {

@@ -47,2 +59,6 @@ status: TransportStatus;

}
export interface RemoteInfoResponse {
enabled: boolean;
override: boolean;
}
//# sourceMappingURL=ResponseInterface.d.ts.map
{
"name": "@meyer/hyperdeck-emulator",
"version": "0.0.4-canary.24.60511e7",
"version": "0.0.4-canary.25.5372bb6",
"description": "Typescript Node.js library for emulating a Blackmagic Hyperdeck",

@@ -93,2 +93,3 @@ "main": "dist/index.js",

"@types/npm-packlist": "^1.1.1",
"@types/pino": "^6.3.0",
"@typescript-eslint/eslint-plugin": "^3.3.0",

@@ -106,2 +107,4 @@ "@typescript-eslint/parser": "^3.3.0",

"npm-packlist": "^2.1.2",
"pino": "^6.3.2",
"pino-pretty": "^4.0.0",
"prettier": "^2.0.5",

@@ -115,6 +118,4 @@ "rimraf": "^3.0.2",

"tslib": "^2.0.0",
"typescript": "^3.8.3",
"@types/pino": "^6.3.0",
"pino": "^6.3.2"
"typescript": "^3.8.3"
}
}

@@ -48,2 +48,4 @@ import packlist = require('npm-packlist')

- dist/index.js
- dist/invariant.d.ts
- dist/invariant.d.ts.map
- dist/parser.d.ts

@@ -62,3 +64,5 @@ - dist/parser.d.ts.map

- src/__tests__/meta.spec.ts
- src/__tests__/server.spec.ts
- src/index.ts
- src/invariant.ts
- src/parser.ts

@@ -65,0 +69,0 @@ - src/server.ts

@@ -10,4 +10,6 @@ export * from './server'

FileFormats,
SlotStatus,
VideoFormat,
TransportStatus
TransportStatus,
Timecode
} from './types'

@@ -9,3 +9,3 @@ import { DeserializedCommand, Hash, ParameterMap } from './types'

constructor(logger: Logger) {
this._log = logger.child({ source: 'MultilineParser' })
this._log = logger.child({ name: 'MultilineParser' })
}

@@ -12,0 +12,0 @@

@@ -13,3 +13,4 @@ import { HyperdeckSocket } from './socket'

ErrorResponse,
Buildable
Buildable,
formatClipsGetResponse
} from './types'

@@ -30,3 +31,3 @@ import { createServer, Server } from 'net'

private _sockets: { [id: string]: HyperdeckSocket } = {}
private _server: Server
public readonly _server: Server

@@ -51,3 +52,2 @@ onDeviceInfo: Handler<DeserializedCommand, ResponseInterface.DeviceInfo> = noop

onShuttle: Handler<DeserializedCommands.ShuttleCommand, void> = noop
onRemote: Handler<DeserializedCommands.RemoteCommand, void | Record<string, string>> = noop
onConfiguration: Handler<

@@ -63,13 +63,16 @@ DeserializedCommands.ConfigurationCommand,

constructor(ip?: string, logger = pino()) {
this.logger = logger.child({ source: 'HyperDeck Emulator' })
this.logger = logger.child({ name: 'HyperDeck Emulator' })
this._server = createServer((socket) => {
this.logger.debug('connection')
this.logger.info('connection')
const socketId = Math.random().toString(35).substr(-6)
this._sockets[socketId] = new HyperdeckSocket(
socket,
this.logger.child({ source: 'HyperDeck socket ' + socketId }),
(cmd) => this._receivedCommand(cmd)
const socketLogger = this.logger.child({ name: 'HyperDeck socket ' + socketId })
this._sockets[socketId] = new HyperdeckSocket(socket, socketLogger, (cmd) =>
this._receivedCommand(cmd)
)
this._sockets[socketId].on('disconnected', () => {
socketLogger.info('disconnected')
delete this._sockets[socketId]

@@ -105,3 +108,6 @@ })

private async _receivedCommand(cmd: DeserializedCommand): Promise<Buildable> {
this.logger.info({ cmd }, '_receivedCommand')
// TODO(meyer) more sophisticated debouncing
await new Promise((resolve) => setTimeout(() => resolve(), 200))
this.logger.info({ cmd }, '<-- ' + cmd.name)
try {

@@ -154,3 +160,3 @@ if (cmd.name === CommandNames.DeviceInfoCommand) {

if (cmd.name === CommandNames.ClipsGetCommand) {
const res = await this.onClipsGet(cmd)
const res = await this.onClipsGet(cmd).then(formatClipsGetResponse)
return new TResponse(SynchronousCode.ClipsInfo, res)

@@ -205,7 +211,6 @@ }

if (cmd.name === CommandNames.RemoteCommand) {
const res = await this.onRemote(cmd)
if (!res) {
return new TResponse(SynchronousCode.OK)
}
return new TResponse(SynchronousCode.Remote, res)
return new TResponse(SynchronousCode.Remote, {
enabled: true,
override: false
})
}

@@ -252,2 +257,3 @@

if (err instanceof UnimplementedError) {
this.logger.error({ cmd }, 'unimplemented')
return new TResponse(ErrorCode.Unsupported)

@@ -257,5 +263,7 @@ }

if (err && typeof err.code === 'number' && ErrorCode[err.code] && err.msg) {
this.logger.error({ err }, 'error with code')
return new ErrorResponse(err.code, err.msg)
}
this.logger.error({ cmd }, 'internal error')
return new TResponse(ErrorCode.InternalError)

@@ -262,0 +270,0 @@ }

@@ -1,2 +0,2 @@

import { Socket } from 'net'
import type { Socket } from 'net'
import { EventEmitter } from 'events'

@@ -26,3 +26,3 @@ import {

this._parser = new MultilineParser(this.logger)
this._parser = new MultilineParser(logger)

@@ -44,3 +44,3 @@ this._socket.setEncoding('utf-8')

new TResponse(AsynchronousCode.ConnectionInfo, {
'protocol version': '1.6',
'protocol version': '1.11',
model: 'NodeJS Hyperdeck Server Library'

@@ -64,3 +64,3 @@ })

private _onMessage(data: string): void {
this.logger.debug('onMessage(%s)', data)
this.logger.info({ data }, 'onMessage')

@@ -70,3 +70,3 @@ this._lastReceived = Date.now()

const cmds = this._parser.receivedString(data)
this.logger.debug('commands:', cmds)
this.logger.info({ cmds }, 'commands')

@@ -111,3 +111,3 @@ for (const cmd of cmds) {

}
this.sendResponse(new TResponse(SynchronousCode.Notify, settings))
this.sendResponse(new TResponse(SynchronousCode.Notify, settings), cmd)

@@ -119,11 +119,5 @@ continue

this._receivedCommand(cmd).then(
(res) => {
this.logger.info({ res }, '_receivedCommand response')
this.sendResponse(res)
},
() => {
this.logger.error({}, '_receivedCommand error response')
// not implemented by client code:
this.sendResponse(new TResponse(ErrorCode.Unsupported))
}
(res) => this.sendResponse(res, cmd),
// not implemented by client code:
() => this.sendResponse(new TResponse(ErrorCode.Unsupported), cmd)
)

@@ -133,9 +127,15 @@ }

sendResponse(res: Buildable): void {
const msg = res.build()
this._socket.write(msg)
sendResponse(res: Buildable, cmd?: DeserializedCommand): void {
const responseText = res.build()
const txt = '--> ' + (cmd?.name || 'sendResponse')
if (res instanceof TResponse && ErrorCode[res.code]) {
this.logger.error({ responseText }, txt)
} else {
this.logger.info({ responseText }, txt)
}
this._socket.write(responseText)
}
notify(type: NotifyType, params: Hash<string>): void {
this.logger.debug('notify:', type, params)
this.logger.info({ type, params }, 'notify')
if (type === NotifyType.Configuration && this._notifySettings.configuration) {

@@ -142,0 +142,0 @@ this.sendResponse(new TResponse(AsynchronousCode.ConfigurationInfo, params))

@@ -1,5 +0,4 @@

import * as util from 'util'
import * as DeserializedCommands from './types/DeserializedCommands'
import * as ResponseInterface from './types/ResponseInterface'
import { invariant } from './invariant'
export { DeserializedCommands, ResponseInterface }

@@ -27,4 +26,5 @@

export class TResponse<P extends Record<string, any> = Record<string, any>> implements Buildable {
constructor(public code: ResponseCode, public params?: P) {
export class TResponse<T extends Record<string, any> = Record<string, any>> implements Buildable {
constructor(public code: ResponseCode, public params?: T) {
invariant(responseNamesByCode.hasOwnProperty(code), 'Invalid code: `%o`', code)
this.name = responseNamesByCode[code]

@@ -35,25 +35,29 @@ }

public build(): string {
let data = util.format('%d %s', this.code, this.name)
public build = (): string => messageForCode(this.code, this.params)
}
if (this.params) {
data += ':' + CRLF
for (const [key, value] of Object.entries(this.params)) {
if (!value) {
continue
}
data += util.format('%s: %s', key, value) + CRLF
}
}
export const formatClipsGetResponse = (
res: ResponseInterface.ClipsGet
): Record<string, string | number> => {
const clipsCount = res.clips.length
data += CRLF
const response: Record<string, string | number> = {
clipsCount
}
return data
for (let idx = 0; idx < clipsCount; idx++) {
const clip = res.clips[idx]
const clipKey = (idx + 1).toString()
response[clipKey] = `${clip.name} ${clip.startT} ${clip.duration}`
}
return response
}
export class ErrorResponse implements Buildable {
constructor(public code: ResponseCode, public message: string) {}
constructor(public code: ResponseCode, public message: string) {
invariant(responseNamesByCode.hasOwnProperty(code), 'Invalid code: `%o`', code)
}
public build = (): string => util.format('%d %s', this.code, this.message)
public build = (): string => this.code + ' ' + this.message + CRLF
}

@@ -64,3 +68,3 @@

name: string
parameters: { [key: string]: string | undefined }
parameters: Record<string, string | undefined>
}

@@ -188,2 +192,62 @@

export class Timecode {
constructor(hh: number, mm: number, ss: number, ff: number) {
this._timecode = [hh, mm, ss, ff]
.map((code) => {
const codeInt = Math.floor(code)
if (codeInt !== code || code < 0 || code > 99) {
throw new Error('Timecode params must be an integer between 0 and 99')
}
// turn the integer into a potentially zero-prefixed string
return (codeInt + 100).toString().slice(-2)
})
.join(':')
}
private _timecode: string
public toString(): string {
return this._timecode
}
}
export const messageForCode = (code: ResponseCode, params?: Record<string, unknown>): string => {
const firstLine = `${code} ${responseNamesByCode[code]}`
// bail if no params
if (!params) {
return firstLine + CRLF
}
// filter out params with null/undefined values
const paramEntries = Object.entries(params).filter(([, value]) => value != null)
// bail if no params after filtering
if (paramEntries.length === 0) {
return firstLine + CRLF
}
// turn the params object into a key/value
return (
paramEntries.reduce<string>((prev, [key, value]) => {
let valueString: string
if (typeof value === 'string') {
valueString = value
} else if (typeof value === 'boolean') {
valueString = value ? 'true' : 'false'
} else if (typeof value === 'number') {
valueString = value.toString()
} else {
throw new Error('Unhandled value type: ' + typeof value)
}
// convert camelCase keys to space-separated words
const formattedKey = key.replace(/([a-z])([A-Z]+)/, '$1 $2').toLowerCase()
return prev + formattedKey + ': ' + valueString + CRLF
}, firstLine + ':' + CRLF) + CRLF
)
}
export const ParameterMap = {

@@ -190,0 +254,0 @@ help: [],

@@ -1,2 +0,2 @@

import { Hash } from '../types'
import { Hash, Timecode } from '../types'
import {

@@ -25,6 +25,20 @@ TransportStatus,

export interface ClipsGet extends Hash<string> {
'clip count': string
export interface ClipV1 {
name: string
startT: Timecode
duration: Timecode
}
export interface ClipV2 {
startT: Timecode
duration: number
inT: Timecode
outT: Timecode
name: string
}
export interface ClipsGet {
clips: ClipV1[]
}
export interface TransportInfo {

@@ -63,1 +77,6 @@ status: TransportStatus

}
export interface RemoteInfoResponse {
enabled: boolean
override: boolean
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc