@meyer/hyperdeck-emulator
Advanced tools
Comparing version 0.0.4-canary.25.5372bb6 to 0.0.4-canary.28.6476ee1
@@ -8,3 +8,2 @@ 'use strict'; | ||
var events = require('events'); | ||
var util = _interopDefault(require('util')); | ||
var net = require('net'); | ||
@@ -164,60 +163,6 @@ var pino = _interopDefault(require('pino')); | ||
var ResponseInterface = { | ||
__proto__: null | ||
}; | ||
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 = function TResponse(code, params) { | ||
var _this = this; | ||
this.code = code; | ||
this.params = params; | ||
var ErrorCode; | ||
this.build = function () { | ||
return messageForCode(_this.code, _this.params); | ||
}; | ||
!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 idx = 0; idx < clipsCount; idx++) { | ||
var clip = res.clips[idx]; | ||
var clipKey = (idx + 1).toString(); | ||
response[clipKey] = clip.name + " " + clip.startT + " " + clip.duration; | ||
} | ||
return response; | ||
}; | ||
var ErrorResponse = function ErrorResponse(code, message) { | ||
var _this2 = this; | ||
this.code = code; | ||
this.message = message; | ||
this.build = function () { | ||
return _this2.code + ' ' + _this2.message + CRLF; | ||
}; | ||
!responseNamesByCode.hasOwnProperty(code) ? invariant(false, 'Invalid code: `%o`', code) : void 0; | ||
}; | ||
(function (ErrorCode) { | ||
@@ -242,4 +187,6 @@ ErrorCode[ErrorCode["SyntaxError"] = 100] = "SyntaxError"; | ||
ErrorCode[ErrorCode["FormatNotPrepared"] = 162] = "FormatNotPrepared"; | ||
})(exports.ErrorCode || (exports.ErrorCode = {})); | ||
})(ErrorCode || (ErrorCode = {})); | ||
var SynchronousCode; | ||
(function (SynchronousCode) { | ||
@@ -258,4 +205,6 @@ SynchronousCode[SynchronousCode["OK"] = 200] = "OK"; | ||
SynchronousCode[SynchronousCode["FormatReady"] = 216] = "FormatReady"; | ||
})(exports.SynchronousCode || (exports.SynchronousCode = {})); | ||
})(SynchronousCode || (SynchronousCode = {})); | ||
var AsynchronousCode; | ||
(function (AsynchronousCode) { | ||
@@ -267,104 +216,35 @@ AsynchronousCode[AsynchronousCode["ConnectionInfo"] = 500] = "ConnectionInfo"; | ||
AsynchronousCode[AsynchronousCode["ConfigurationInfo"] = 511] = "ConfigurationInfo"; | ||
})(exports.AsynchronousCode || (exports.AsynchronousCode = {})); | ||
})(AsynchronousCode || (AsynchronousCode = {})); | ||
(function (NotifyType) { | ||
NotifyType[NotifyType["Slot"] = 0] = "Slot"; | ||
NotifyType[NotifyType["Transport"] = 1] = "Transport"; | ||
NotifyType[NotifyType["Remote"] = 2] = "Remote"; | ||
NotifyType[NotifyType["Configuration"] = 3] = "Configuration"; | ||
})(exports.NotifyType || (exports.NotifyType = {})); | ||
var responseNamesByCode = (_responseNamesByCode = {}, _responseNamesByCode[AsynchronousCode.ConfigurationInfo] = 'configuration info', _responseNamesByCode[AsynchronousCode.ConnectionInfo] = 'connection info', _responseNamesByCode[AsynchronousCode.RemoteInfo] = 'remote info', _responseNamesByCode[AsynchronousCode.SlotInfo] = 'slot info', _responseNamesByCode[AsynchronousCode.TransportInfo] = 'transport info', _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] = 'clips count', _responseNamesByCode[SynchronousCode.ClipsInfo] = 'clips info', _responseNamesByCode[SynchronousCode.Configuration] = 'configuration', _responseNamesByCode[SynchronousCode.DeviceInfo] = 'device info', _responseNamesByCode[SynchronousCode.DiskList] = 'disk list', _responseNamesByCode[SynchronousCode.FormatReady] = 'format ready', _responseNamesByCode[SynchronousCode.Notify] = 'notify', _responseNamesByCode[SynchronousCode.OK] = 'ok', _responseNamesByCode[SynchronousCode.Remote] = 'remote', _responseNamesByCode[SynchronousCode.SlotInfo] = 'slot info', _responseNamesByCode[SynchronousCode.TransportInfo] = 'transport info', _responseNamesByCode[SynchronousCode.Uptime] = 'uptime', _responseNamesByCode); | ||
var FileFormat; | ||
var CommandNames; | ||
(function (FileFormat) { | ||
FileFormat["QuickTimeUncompressed"] = "QuickTimeUncompressed"; | ||
FileFormat["QuickTimeProResHQ"] = "QuickTimeProResHQ"; | ||
FileFormat["QuickTimeProRes"] = "QuickTimeProRes"; | ||
FileFormat["QuickTimeProResLT"] = "QuickTimeProResLT"; | ||
FileFormat["QuickTimeProResProxy"] = "QuickTimeProResProxy"; | ||
FileFormat["QuickTimeDNxHR220"] = "QuickTimeDNxHR220"; | ||
FileFormat["DNxHR220"] = "DNxHR220"; | ||
})(FileFormat || (FileFormat = {})); | ||
(function (CommandNames) { | ||
CommandNames["DeviceInfoCommand"] = "device info"; | ||
CommandNames["DiskListCommand"] = "disk list"; | ||
CommandNames["PreviewCommand"] = "preview"; | ||
CommandNames["PlayCommand"] = "play"; | ||
CommandNames["PlayrangeSetCommand"] = "playrange set"; | ||
CommandNames["PlayrangeClearCommand"] = "playrange clear"; | ||
CommandNames["RecordCommand"] = "record"; | ||
CommandNames["StopCommand"] = "stop"; | ||
CommandNames["ClipsCountCommand"] = "clips count"; | ||
CommandNames["ClipsGetCommand"] = "clips get"; | ||
CommandNames["ClipsAddCommand"] = "clips add"; | ||
CommandNames["ClipsClearCommand"] = "clips clear"; | ||
CommandNames["TransportInfoCommand"] = "transport info"; | ||
CommandNames["SlotInfoCommand"] = "slot info"; | ||
CommandNames["SlotSelectCommand"] = "slot select"; | ||
CommandNames["NotifyCommand"] = "notify"; | ||
CommandNames["GoToCommand"] = "goto"; | ||
CommandNames["JogCommand"] = "jog"; | ||
CommandNames["ShuttleCommand"] = "shuttle"; | ||
CommandNames["RemoteCommand"] = "remote"; | ||
CommandNames["ConfigurationCommand"] = "configuration"; | ||
CommandNames["UptimeCommand"] = "uptime"; | ||
CommandNames["FormatCommand"] = "format"; | ||
CommandNames["IdentifyCommand"] = "identify"; | ||
CommandNames["WatchdogCommand"] = "watchdog"; | ||
CommandNames["PingCommand"] = "ping"; | ||
})(CommandNames || (CommandNames = {})); | ||
var AudioInput; | ||
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); | ||
(function (AudioInput) { | ||
AudioInput["embedded"] = "embedded"; | ||
AudioInput["XLR"] = "XLR"; | ||
AudioInput["RCA"] = "RCA"; | ||
})(AudioInput || (AudioInput = {})); | ||
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 | ||
var VideoInputs; | ||
(function (VideoInputs) { | ||
VideoInputs["SDI"] = "SDI"; | ||
VideoInputs["HDMI"] = "HDMI"; | ||
VideoInputs["component"] = "component"; | ||
})(VideoInputs || (VideoInputs = {})); | ||
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 = { | ||
var CRLF = '\r\n'; | ||
var parametersByCommandName = { | ||
help: [], | ||
@@ -401,76 +281,6 @@ commands: [], | ||
(function (SlotStatus) { | ||
SlotStatus["EMPTY"] = "empty"; | ||
SlotStatus["MOUNTING"] = "mounting"; | ||
SlotStatus["ERROR"] = "error"; | ||
SlotStatus["MOUNTED"] = "mounted"; | ||
})(exports.SlotStatus || (exports.SlotStatus = {})); | ||
(function (VideoFormat) { | ||
VideoFormat["NTSC"] = "NTSC"; | ||
VideoFormat["PAL"] = "PAL"; | ||
VideoFormat["NTSCp"] = "NTSCp"; | ||
VideoFormat["PALp"] = "PALp"; | ||
VideoFormat["_720p50"] = "720p50"; | ||
VideoFormat["_720p5994"] = "720p5994"; | ||
VideoFormat["_720p60"] = "720p60"; | ||
VideoFormat["_1080p23976"] = "1080p23976"; | ||
VideoFormat["_1080p24"] = "1080p24"; | ||
VideoFormat["_1080p25"] = "1080p25"; | ||
VideoFormat["_1080p2997"] = "1080p2997"; | ||
VideoFormat["_1080p30"] = "1080p30"; | ||
VideoFormat["_1080i50"] = "1080i50"; | ||
VideoFormat["_1080i5994"] = "1080i5994"; | ||
VideoFormat["_1080i60"] = "1080i60"; | ||
VideoFormat["_4Kp23976"] = "4Kp23976"; | ||
VideoFormat["_4Kp24"] = "4Kp24"; | ||
VideoFormat["_4Kp25"] = "4Kp25"; | ||
VideoFormat["_4Kp2997"] = "4Kp2997"; | ||
VideoFormat["_4Kp30"] = "4Kp30"; | ||
VideoFormat["_4Kp50"] = "4Kp50"; | ||
VideoFormat["_4Kp5994"] = "4Kp5994"; | ||
VideoFormat["_4Kp60"] = "4Kp60"; | ||
})(exports.VideoFormat || (exports.VideoFormat = {})); | ||
(function (TransportStatus) { | ||
TransportStatus["PREVIEW"] = "preview"; | ||
TransportStatus["STOPPED"] = "stopped"; | ||
TransportStatus["PLAY"] = "play"; | ||
TransportStatus["FORWARD"] = "forward"; | ||
TransportStatus["REWIND"] = "rewind"; | ||
TransportStatus["JOG"] = "jog"; | ||
TransportStatus["SHUTTLE"] = "shuttle"; | ||
TransportStatus["RECORD"] = "record"; | ||
})(exports.TransportStatus || (exports.TransportStatus = {})); | ||
(function (FileFormats) { | ||
FileFormats["QuickTimeUncompressed"] = "QuickTimeUncompressed"; | ||
FileFormats["QuickTimeProResHQ"] = "QuickTimeProResHQ"; | ||
FileFormats["QuickTimeProRes"] = "QuickTimeProRes"; | ||
FileFormats["QuickTimeProResLT"] = "QuickTimeProResLT"; | ||
FileFormats["QuickTimeProResProxy"] = "QuickTimeProResProxy"; | ||
FileFormats["QuickTimeDNxHR220"] = "QuickTimeDNxHR220"; | ||
FileFormats["DNxHR220"] = "DNxHR220"; | ||
})(exports.FileFormats || (exports.FileFormats = {})); | ||
var AudioInputs; | ||
(function (AudioInputs) { | ||
AudioInputs["embedded"] = "embedded"; | ||
AudioInputs["XLR"] = "XLR"; | ||
AudioInputs["RCA"] = "RCA"; | ||
})(AudioInputs || (AudioInputs = {})); | ||
var VideoInputs; | ||
(function (VideoInputs) { | ||
VideoInputs["SDI"] = "SDI"; | ||
VideoInputs["HDMI"] = "HDMI"; | ||
VideoInputs["component"] = "component"; | ||
})(VideoInputs || (VideoInputs = {})); | ||
var MultilineParser = /*#__PURE__*/function () { | ||
function MultilineParser(logger) { | ||
this._linesQueue = []; | ||
this._log = logger.child({ | ||
this.linesQueue = []; | ||
this.logger = logger.child({ | ||
name: 'MultilineParser' | ||
@@ -488,9 +298,8 @@ }); | ||
if (newLines.length > 0 && newLines[newLines.length - 1] === '') newLines.pop(); | ||
this._linesQueue = this._linesQueue.concat(newLines); | ||
this.linesQueue = this.linesQueue.concat(newLines); | ||
while (this._linesQueue.length > 0) { | ||
while (this.linesQueue.length > 0) { | ||
// skip any blank lines | ||
if (this._linesQueue[0] === '') { | ||
this._linesQueue.shift(); | ||
if (this.linesQueue[0] === '') { | ||
this.linesQueue.shift(); | ||
continue; | ||
@@ -500,4 +309,4 @@ } // if the first line has no colon, then it is a single line command | ||
if (this._linesQueue[0].indexOf(':') === -1 || this._linesQueue.length === 1 && this._linesQueue[0].indexOf(':') > 0) { | ||
var _r = this.parseResponse(this._linesQueue.splice(0, 1)); | ||
if (this.linesQueue[0].indexOf(':') === -1 || this.linesQueue.length === 1 && this.linesQueue[0].indexOf(':') > 0) { | ||
var _r = this.parseResponse(this.linesQueue.splice(0, 1)); | ||
@@ -511,3 +320,3 @@ if (_r) { | ||
var endLine = this._linesQueue.indexOf(''); | ||
var endLine = this.linesQueue.indexOf(''); | ||
@@ -519,4 +328,3 @@ if (endLine === -1) { | ||
var lines = this._linesQueue.splice(0, endLine + 1); | ||
var lines = this.linesQueue.splice(0, endLine + 1); | ||
var r = this.parseResponse(lines); | ||
@@ -539,3 +347,3 @@ if (r) res.push(r); | ||
var params = {}; | ||
var paramNames = new Set(ParameterMap[msg]); | ||
var paramNames = new Set(parametersByCommandName[msg]); | ||
var param = bits.shift(); | ||
@@ -574,6 +382,5 @@ if (!param) throw new Error('No named parameters found'); | ||
if (!headerMatch) { | ||
this._log.error({ | ||
this.logger.error({ | ||
header: lines[0] | ||
}, 'failed to parse header'); | ||
return null; | ||
@@ -589,6 +396,5 @@ } | ||
if (!lineMatch) { | ||
this._log.error({ | ||
this.logger.error({ | ||
line: lines[_i2] | ||
}, 'failed to parse line'); | ||
continue; | ||
@@ -612,15 +418,64 @@ } | ||
var HyperdeckSocket = /*#__PURE__*/function (_EventEmitter) { | ||
_inheritsLoose(HyperdeckSocket, _EventEmitter); | ||
var sanitiseMessage = function sanitiseMessage(input) { | ||
return input.replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/:/g, ''); | ||
}; | ||
/** For a given code, generate the response message that will be sent to the ATEM */ | ||
function HyperdeckSocket(_socket, logger, _receivedCommand) { | ||
var messageForCode = function messageForCode(code, params) { | ||
if (typeof params === 'string') { | ||
return code + ' ' + sanitiseMessage(params) + CRLF; | ||
} | ||
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 HyperDeckSocket = /*#__PURE__*/function (_EventEmitter) { | ||
_inheritsLoose(HyperDeckSocket, _EventEmitter); | ||
function HyperDeckSocket(socket, logger, receivedCommand) { | ||
var _this; | ||
_this = _EventEmitter.call(this) || this; | ||
_this._socket = _socket; | ||
_this.socket = socket; | ||
_this.logger = logger; | ||
_this._receivedCommand = _receivedCommand; | ||
_this._lastReceived = -1; | ||
_this._watchdogTimer = null; | ||
_this._notifySettings = { | ||
_this.receivedCommand = receivedCommand; | ||
_this.lastReceivedMS = -1; | ||
_this.watchdogTimer = null; | ||
_this.notifySettings = { | ||
slot: false, | ||
@@ -633,24 +488,26 @@ transport: false, | ||
}; | ||
_this._parser = new MultilineParser(logger); | ||
_this.parser = new MultilineParser(logger); | ||
_this._socket.setEncoding('utf-8'); | ||
_this.socket.setEncoding('utf-8'); | ||
_this._socket.on('data', function (data) { | ||
_this._onMessage(data); | ||
_this.socket.on('data', function (data) { | ||
_this.onMessage(data); | ||
}); | ||
_this._socket.on('error', function () { | ||
logger.info('error'); | ||
_this.socket.on('error', function (err) { | ||
logger.info({ | ||
err: err | ||
}, 'error'); | ||
_this._socket.destroy(); | ||
_this.socket.destroy(); | ||
_this.emit('disconnected'); | ||
logger.info('disconnected'); | ||
logger.info('manually disconnected'); | ||
}); | ||
_this.sendResponse(new TResponse(exports.AsynchronousCode.ConnectionInfo, { | ||
_this.sendResponse(AsynchronousCode.ConnectionInfo, { | ||
'protocol version': '1.11', | ||
model: 'NodeJS Hyperdeck Server Library' | ||
})); | ||
model: 'NodeJS HyperDeck Server Library' | ||
}); | ||
@@ -660,5 +517,5 @@ return _this; | ||
var _proto = HyperdeckSocket.prototype; | ||
var _proto = HyperDeckSocket.prototype; | ||
_proto._onMessage = function _onMessage(data) { | ||
_proto.onMessage = function onMessage(data) { | ||
var _this2 = this; | ||
@@ -668,10 +525,8 @@ | ||
data: data | ||
}, 'onMessage'); | ||
this._lastReceived = Date.now(); | ||
var cmds = this._parser.receivedString(data); | ||
}, '<-- received message from client'); | ||
this.lastReceivedMS = Date.now(); | ||
var cmds = this.parser.receivedString(data); | ||
this.logger.info({ | ||
cmds: cmds | ||
}, 'commands'); | ||
}, 'parsed commands'); | ||
@@ -682,15 +537,15 @@ var _loop = function _loop() { | ||
// special cases | ||
if (cmd.name === CommandNames.WatchdogCommand) { | ||
if (_this2._watchdogTimer) clearInterval(_this2._watchdogTimer); | ||
if (cmd.name === 'watchdog') { | ||
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(); | ||
_this2.watchdogTimer = setInterval(function () { | ||
if (Date.now() - _this2.lastReceivedMS > Number(watchdogCmd.parameters.period)) { | ||
_this2.socket.destroy(); | ||
_this2.emit('disconnected'); | ||
if (_this2._watchdogTimer) { | ||
clearInterval(_this2._watchdogTimer); | ||
if (_this2.watchdogTimer) { | ||
clearInterval(_this2.watchdogTimer); | ||
} | ||
@@ -700,3 +555,3 @@ } | ||
} | ||
} else if (cmd.name === CommandNames.NotifyCommand) { | ||
} else if (cmd.name === 'notify') { | ||
var notifyCmd = cmd; | ||
@@ -708,4 +563,4 @@ | ||
if (_this2._notifySettings[param] !== undefined) { | ||
_this2._notifySettings[param] = notifyCmd.parameters[param] === 'true'; | ||
if (_this2.notifySettings[param] !== undefined) { | ||
_this2.notifySettings[param] = notifyCmd.parameters[param] === 'true'; | ||
} | ||
@@ -716,8 +571,8 @@ } | ||
for (var _i2 = 0, _Object$keys2 = Object.keys(_this2._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] = _this2._notifySettings[key] ? 'true' : 'false'; | ||
settings[key] = _this2.notifySettings[key] ? 'true' : 'false'; | ||
} | ||
_this2.sendResponse(new TResponse(exports.SynchronousCode.Notify, settings), cmd); | ||
_this2.sendResponse(SynchronousCode.Notify, settings, cmd); | ||
@@ -728,7 +583,24 @@ return "continue"; | ||
_this2._receivedCommand(cmd).then(function (res) { | ||
return _this2.sendResponse(res, cmd); | ||
_this2.receivedCommand(cmd).then(function (codeOrObj) { | ||
if (typeof codeOrObj === 'object') { | ||
var _code = codeOrObj.code; | ||
var paramsOrMessage = 'params' in codeOrObj && codeOrObj.params || 'message' in codeOrObj && codeOrObj.message || undefined; | ||
return _this2.sendResponse(_code, paramsOrMessage, cmd); | ||
} | ||
var code = codeOrObj; | ||
if (typeof code === 'number' && (ErrorCode[code] || SynchronousCode[code] || AsynchronousCode[code])) { | ||
return _this2.sendResponse(code, undefined, cmd); | ||
} | ||
_this2.logger.error({ | ||
cmd: cmd, | ||
codeOrObj: codeOrObj | ||
}, 'codeOrObj was neither a ResponseCode nor a response object'); | ||
_this2.sendResponse(ErrorCode.InternalError, undefined, cmd); | ||
}, // not implemented by client code: | ||
function () { | ||
return _this2.sendResponse(new TResponse(exports.ErrorCode.Unsupported), cmd); | ||
return _this2.sendResponse(ErrorCode.Unsupported, undefined, cmd); | ||
}); | ||
@@ -744,17 +616,10 @@ }; | ||
_proto.sendResponse = function sendResponse(res, cmd) { | ||
var responseText = res.build(); | ||
var txt = '--> ' + ((cmd === null || cmd === void 0 ? void 0 : cmd.name) || 'sendResponse'); | ||
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.sendResponse = function sendResponse(code, paramsOrMessage, cmd) { | ||
var responseText = messageForCode(code, paramsOrMessage); | ||
var method = ErrorCode[code] ? 'error' : 'info'; | ||
this.logger[method]({ | ||
responseText: responseText, | ||
cmd: cmd | ||
}, '--> send response to client'); | ||
this.socket.write(responseText); | ||
}; | ||
@@ -768,16 +633,36 @@ | ||
if (type === exports.NotifyType.Configuration && this._notifySettings.configuration) { | ||
this.sendResponse(new TResponse(exports.AsynchronousCode.ConfigurationInfo, params)); | ||
} else if (type === exports.NotifyType.Remote && this._notifySettings.remote) { | ||
this.sendResponse(new TResponse(exports.AsynchronousCode.RemoteInfo, params)); | ||
} else if (type === exports.NotifyType.Slot && this._notifySettings.slot) { | ||
this.sendResponse(new TResponse(exports.AsynchronousCode.SlotInfo, params)); | ||
} else if (type === exports.NotifyType.Transport && this._notifySettings.transport) { | ||
this.sendResponse(new TResponse(exports.AsynchronousCode.TransportInfo, params)); | ||
if (type === 'configuration' && this.notifySettings.configuration) { | ||
this.sendResponse(AsynchronousCode.ConfigurationInfo, params); | ||
} else if (type === 'remote' && this.notifySettings.remote) { | ||
this.sendResponse(AsynchronousCode.RemoteInfo, params); | ||
} else if (type === 'slot' && this.notifySettings.slot) { | ||
this.sendResponse(AsynchronousCode.SlotInfo, params); | ||
} else if (type === 'transport' && this.notifySettings.transport) { | ||
this.sendResponse(AsynchronousCode.TransportInfo, params); | ||
} else { | ||
this.logger.error({ | ||
type: type, | ||
params: params | ||
}, 'unhandled notify type'); | ||
} | ||
}; | ||
return HyperdeckSocket; | ||
return HyperDeckSocket; | ||
}(events.EventEmitter); | ||
var formatClipsGetResponse = function formatClipsGetResponse(res) { | ||
var clipsCount = res.clips.length; | ||
var response = { | ||
clipsCount: clipsCount | ||
}; | ||
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; | ||
} | ||
return response; | ||
}; | ||
var UnimplementedError = /*#__PURE__*/function (_Error) { | ||
@@ -801,4 +686,6 @@ _inheritsLoose(UnimplementedError, _Error); | ||
var HyperdeckServer = /*#__PURE__*/function () { | ||
function HyperdeckServer(ip, logger) { | ||
var HyperDeckServer = /*#__PURE__*/function () { | ||
function HyperDeckServer(ip, logger) { | ||
var _this2 = this; | ||
var _this = this; | ||
@@ -810,3 +697,3 @@ | ||
this._sockets = {}; | ||
this.sockets = {}; | ||
this.onDeviceInfo = noop; | ||
@@ -835,185 +722,143 @@ this.onDiskList = noop; | ||
this.onWatchdog = noop; | ||
this.logger = logger.child({ | ||
name: 'HyperDeck Emulator' | ||
}); | ||
this._server = net.createServer(function (socket) { | ||
_this.logger.info('connection'); | ||
var socketId = Math.random().toString(35).substr(-6); | ||
this.receivedCommand = function (cmd) { | ||
try { | ||
// TODO(meyer) more sophisticated debouncing | ||
return Promise.resolve(new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
return resolve(); | ||
}, 200); | ||
})).then(function () { | ||
var _exit = false; | ||
var socketLogger = _this.logger.child({ | ||
name: 'HyperDeck socket ' + socketId | ||
}); | ||
_this.logger.info({ | ||
cmd: cmd | ||
}, '<-- ' + cmd.name); | ||
_this._sockets[socketId] = new HyperdeckSocket(socket, socketLogger, function (cmd) { | ||
return _this._receivedCommand(cmd); | ||
}); | ||
return _catch(function () { | ||
function _temp44(_result) { | ||
var _exit2 = false; | ||
if (_exit) return _result; | ||
_this._sockets[socketId].on('disconnected', function () { | ||
socketLogger.info('disconnected'); | ||
delete _this._sockets[socketId]; | ||
}); | ||
}); | ||
function _temp42(_result2) { | ||
var _exit3 = false; | ||
if (_exit2) return _result2; | ||
this._server.on('listening', function () { | ||
return _this.logger.info('listening'); | ||
}); | ||
function _temp40(_result3) { | ||
var _exit4 = false; | ||
if (_exit3) return _result3; | ||
this._server.on('close', function () { | ||
return _this.logger.info('connection closed'); | ||
}); | ||
function _temp38(_result4) { | ||
var _exit5 = false; | ||
if (_exit4) return _result4; | ||
this._server.on('error', function (err) { | ||
return _this.logger.error('server error:', err); | ||
}); | ||
function _temp36(_result5) { | ||
var _exit6 = false; | ||
if (_exit5) return _result5; | ||
this._server.maxConnections = 1; | ||
function _temp34(_result6) { | ||
var _exit7 = false; | ||
if (_exit6) return _result6; | ||
this._server.listen(9993, ip); | ||
} | ||
function _temp32(_result7) { | ||
var _exit8 = false; | ||
if (_exit7) return _result7; | ||
var _proto = HyperdeckServer.prototype; | ||
function _temp30(_result8) { | ||
var _exit9 = false; | ||
if (_exit8) return _result8; | ||
_proto.close = function close() { | ||
this._server.unref(); | ||
}; | ||
function _temp28(_result9) { | ||
var _exit10 = false; | ||
if (_exit9) return _result9; | ||
_proto.notifySlot = function notifySlot(params) { | ||
this._notify(exports.NotifyType.Slot, params); | ||
}; | ||
function _temp26(_result10) { | ||
var _exit11 = false; | ||
if (_exit10) return _result10; | ||
_proto.notifyTransport = function notifyTransport(params) { | ||
this._notify(exports.NotifyType.Transport, params); | ||
}; | ||
function _temp24(_result11) { | ||
var _exit12 = false; | ||
if (_exit11) return _result11; | ||
_proto._notify = function _notify(type, params) { | ||
for (var _i = 0, _Object$keys = Object.keys(this._sockets); _i < _Object$keys.length; _i++) { | ||
var id = _Object$keys[_i]; | ||
function _temp22(_result12) { | ||
var _exit13 = false; | ||
if (_exit12) return _result12; | ||
this._sockets[id].notify(type, params); | ||
} | ||
}; | ||
function _temp20(_result13) { | ||
var _exit14 = false; | ||
if (_exit13) return _result13; | ||
_proto._receivedCommand = function _receivedCommand(cmd) { | ||
try { | ||
var _this3 = this; | ||
function _temp18(_result14) { | ||
var _exit15 = false; | ||
if (_exit14) return _result14; | ||
// TODO(meyer) more sophisticated debouncing | ||
return Promise.resolve(new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
return resolve(); | ||
}, 200); | ||
})).then(function () { | ||
var _exit = false; | ||
function _temp16(_result15) { | ||
var _exit16 = false; | ||
if (_exit15) return _result15; | ||
_this3.logger.info({ | ||
cmd: cmd | ||
}, '<-- ' + cmd.name); | ||
function _temp14(_result16) { | ||
var _exit17 = false; | ||
if (_exit16) return _result16; | ||
return _catch(function () { | ||
function _temp44(_result) { | ||
var _exit2 = false; | ||
if (_exit) return _result; | ||
function _temp12(_result17) { | ||
var _exit18 = false; | ||
if (_exit17) return _result17; | ||
function _temp42(_result2) { | ||
var _exit3 = false; | ||
if (_exit2) return _result2; | ||
function _temp10(_result18) { | ||
var _exit19 = false; | ||
if (_exit18) return _result18; | ||
function _temp40(_result3) { | ||
var _exit4 = false; | ||
if (_exit3) return _result3; | ||
function _temp8(_result19) { | ||
var _exit20 = false; | ||
if (_exit19) return _result19; | ||
function _temp38(_result4) { | ||
var _exit5 = false; | ||
if (_exit4) return _result4; | ||
function _temp6(_result20) { | ||
var _exit21 = false; | ||
if (_exit20) return _result20; | ||
function _temp36(_result5) { | ||
var _exit6 = false; | ||
if (_exit5) return _result5; | ||
function _temp4(_result21) { | ||
var _exit22 = false; | ||
if (_exit21) return _result21; | ||
function _temp34(_result6) { | ||
var _exit7 = false; | ||
if (_exit6) return _result6; | ||
function _temp2(_result22) { | ||
if (_exit22) return _result22; | ||
function _temp32(_result7) { | ||
var _exit8 = false; | ||
if (_exit7) return _result7; | ||
if (cmd.name === 'watchdog') { | ||
// implemented in socket.ts | ||
return SynchronousCode.OK; | ||
} | ||
function _temp30(_result8) { | ||
var _exit9 = false; | ||
if (_exit8) return _result8; | ||
if (cmd.name === 'ping') { | ||
// implemented in socket.ts | ||
return SynchronousCode.OK; | ||
} | ||
function _temp28(_result9) { | ||
var _exit10 = false; | ||
if (_exit9) return _result9; | ||
function _temp26(_result10) { | ||
var _exit11 = false; | ||
if (_exit10) return _result10; | ||
function _temp24(_result11) { | ||
var _exit12 = false; | ||
if (_exit11) return _result11; | ||
function _temp22(_result12) { | ||
var _exit13 = false; | ||
if (_exit12) return _result12; | ||
function _temp20(_result13) { | ||
var _exit14 = false; | ||
if (_exit13) return _result13; | ||
function _temp18(_result14) { | ||
var _exit15 = false; | ||
if (_exit14) return _result14; | ||
function _temp16(_result15) { | ||
var _exit16 = false; | ||
if (_exit15) return _result15; | ||
function _temp14(_result16) { | ||
var _exit17 = false; | ||
if (_exit16) return _result16; | ||
function _temp12(_result17) { | ||
var _exit18 = false; | ||
if (_exit17) return _result17; | ||
function _temp10(_result18) { | ||
var _exit19 = false; | ||
if (_exit18) return _result18; | ||
function _temp8(_result19) { | ||
var _exit20 = false; | ||
if (_exit19) return _result19; | ||
function _temp6(_result20) { | ||
var _exit21 = false; | ||
if (_exit20) return _result20; | ||
function _temp4(_result21) { | ||
var _exit22 = false; | ||
if (_exit21) return _result21; | ||
function _temp2(_result22) { | ||
if (_exit22) return _result22; | ||
if (cmd.name === CommandNames.WatchdogCommand) { | ||
// implemented in socket.ts | ||
return new TResponse(exports.SynchronousCode.OK); | ||
throw new Error('Unhandled command name: ' + cmd.name); | ||
} | ||
if (cmd.name === CommandNames.PingCommand) { | ||
// implemented in socket.ts | ||
return new TResponse(exports.SynchronousCode.OK); | ||
} | ||
var _temp = function () { | ||
if (cmd.name === 'identify') { | ||
return Promise.resolve(_this.onIdentify(cmd)).then(function () { | ||
_exit22 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
} | ||
}(); | ||
throw new Error('Unhandled command name: ' + cmd.name); | ||
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp); | ||
} | ||
var _temp = function () { | ||
if (cmd.name === CommandNames.IdentifyCommand) { | ||
return Promise.resolve(_this3.onIdentify(cmd)).then(function () { | ||
_exit22 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp3 = function () { | ||
if (cmd.name === 'format') { | ||
return Promise.resolve(_this.onFormat(cmd)).then(function (res) { | ||
if (res) { | ||
_exit21 = true; | ||
return { | ||
code: SynchronousCode.FormatReady, | ||
params: res | ||
}; | ||
} | ||
_exit21 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1023,15 +868,13 @@ } | ||
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp); | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
} | ||
var _temp3 = function () { | ||
if (cmd.name === CommandNames.FormatCommand) { | ||
return Promise.resolve(_this3.onFormat(cmd)).then(function (res) { | ||
if (res) { | ||
_exit21 = true; | ||
return new TResponse(exports.SynchronousCode.FormatReady, res); | ||
} | ||
_exit21 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp5 = function () { | ||
if (cmd.name === 'uptime') { | ||
return Promise.resolve(_this.onUptime(cmd)).then(function (res) { | ||
_exit20 = true; | ||
return { | ||
code: SynchronousCode.Uptime, | ||
params: res | ||
}; | ||
}); | ||
@@ -1041,10 +884,28 @@ } | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); | ||
} | ||
var _temp5 = function () { | ||
if (cmd.name === CommandNames.UptimeCommand) { | ||
return Promise.resolve(_this3.onUptime(cmd)).then(function (res) { | ||
_exit20 = true; | ||
return new TResponse(exports.SynchronousCode.Uptime, res); | ||
if (cmd.name === 'remote') { | ||
return { | ||
code: SynchronousCode.Remote, | ||
params: { | ||
enabled: true, | ||
override: false | ||
} | ||
}; | ||
} | ||
var _temp7 = function () { | ||
if (cmd.name === 'configuration') { | ||
return Promise.resolve(_this.onConfiguration(cmd)).then(function (res) { | ||
if (res) { | ||
_exit19 = true; | ||
return { | ||
code: SynchronousCode.Configuration, | ||
params: res | ||
}; | ||
} | ||
_exit19 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1054,22 +915,10 @@ } | ||
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); | ||
return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); | ||
} | ||
if (cmd.name === CommandNames.RemoteCommand) { | ||
return new TResponse(exports.SynchronousCode.Remote, { | ||
enabled: true, | ||
override: false | ||
}); | ||
} | ||
var _temp7 = function () { | ||
if (cmd.name === CommandNames.ConfigurationCommand) { | ||
return Promise.resolve(_this3.onConfiguration(cmd)).then(function (res) { | ||
if (res) { | ||
_exit19 = true; | ||
return new TResponse(exports.SynchronousCode.Configuration, res); | ||
} | ||
_exit19 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp9 = function () { | ||
if (cmd.name === 'shuttle') { | ||
return Promise.resolve(_this.onShuttle(cmd)).then(function () { | ||
_exit18 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1079,10 +928,10 @@ } | ||
return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); | ||
return _temp9 && _temp9.then ? _temp9.then(_temp10) : _temp10(_temp9); | ||
} | ||
var _temp9 = function () { | ||
if (cmd.name === CommandNames.ShuttleCommand) { | ||
return Promise.resolve(_this3.onShuttle(cmd)).then(function () { | ||
_exit18 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp11 = function () { | ||
if (cmd.name === 'jog') { | ||
return Promise.resolve(_this.onJog(cmd)).then(function () { | ||
_exit17 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1092,10 +941,15 @@ } | ||
return _temp9 && _temp9.then ? _temp9.then(_temp10) : _temp10(_temp9); | ||
return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11); | ||
} | ||
var _temp11 = function () { | ||
if (cmd.name === CommandNames.JogCommand) { | ||
return Promise.resolve(_this3.onJog(cmd)).then(function () { | ||
_exit17 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
if (cmd.name === 'notify') { | ||
// implemented in socket.ts | ||
return SynchronousCode.OK; | ||
} | ||
var _temp13 = function () { | ||
if (cmd.name === 'go to') { | ||
return Promise.resolve(_this.onGoTo(cmd)).then(function () { | ||
_exit16 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1105,15 +959,10 @@ } | ||
return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11); | ||
return _temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13); | ||
} | ||
if (cmd.name === CommandNames.NotifyCommand) { | ||
// implemented in socket.ts | ||
return new TResponse(exports.SynchronousCode.OK); | ||
} | ||
var _temp13 = function () { | ||
if (cmd.name === CommandNames.GoToCommand) { | ||
return Promise.resolve(_this3.onGoTo(cmd)).then(function () { | ||
_exit16 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp15 = function () { | ||
if (cmd.name === 'slot select') { | ||
return Promise.resolve(_this.onSlotSelect(cmd)).then(function () { | ||
_exit15 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1123,10 +972,13 @@ } | ||
return _temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13); | ||
return _temp15 && _temp15.then ? _temp15.then(_temp16) : _temp16(_temp15); | ||
} | ||
var _temp15 = function () { | ||
if (cmd.name === CommandNames.SlotSelectCommand) { | ||
return Promise.resolve(_this3.onSlotSelect(cmd)).then(function () { | ||
_exit15 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp17 = function () { | ||
if (cmd.name === 'slot info') { | ||
return Promise.resolve(_this.onSlotInfo(cmd)).then(function (res) { | ||
_exit14 = true; | ||
return { | ||
code: SynchronousCode.SlotInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1136,10 +988,13 @@ } | ||
return _temp15 && _temp15.then ? _temp15.then(_temp16) : _temp16(_temp15); | ||
return _temp17 && _temp17.then ? _temp17.then(_temp18) : _temp18(_temp17); | ||
} | ||
var _temp17 = function () { | ||
if (cmd.name === CommandNames.SlotInfoCommand) { | ||
return Promise.resolve(_this3.onSlotInfo(cmd)).then(function (res) { | ||
_exit14 = true; | ||
return new TResponse(exports.SynchronousCode.SlotInfo, res); | ||
var _temp19 = function () { | ||
if (cmd.name === 'transport info') { | ||
return Promise.resolve(_this.onTransportInfo(cmd)).then(function (res) { | ||
_exit13 = true; | ||
return { | ||
code: SynchronousCode.TransportInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1149,10 +1004,10 @@ } | ||
return _temp17 && _temp17.then ? _temp17.then(_temp18) : _temp18(_temp17); | ||
return _temp19 && _temp19.then ? _temp19.then(_temp20) : _temp20(_temp19); | ||
} | ||
var _temp19 = function () { | ||
if (cmd.name === CommandNames.TransportInfoCommand) { | ||
return Promise.resolve(_this3.onTransportInfo(cmd)).then(function (res) { | ||
_exit13 = true; | ||
return new TResponse(exports.SynchronousCode.TransportInfo, res); | ||
var _temp21 = function () { | ||
if (cmd.name === 'clips clear') { | ||
return Promise.resolve(_this.onClipsClear(cmd)).then(function () { | ||
_exit12 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1162,10 +1017,10 @@ } | ||
return _temp19 && _temp19.then ? _temp19.then(_temp20) : _temp20(_temp19); | ||
return _temp21 && _temp21.then ? _temp21.then(_temp22) : _temp22(_temp21); | ||
} | ||
var _temp21 = function () { | ||
if (cmd.name === CommandNames.ClipsClearCommand) { | ||
return Promise.resolve(_this3.onClipsClear(cmd)).then(function () { | ||
_exit12 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp23 = function () { | ||
if (cmd.name === 'clips add') { | ||
return Promise.resolve(_this.onClipsAdd(cmd)).then(function () { | ||
_exit11 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1175,10 +1030,13 @@ } | ||
return _temp21 && _temp21.then ? _temp21.then(_temp22) : _temp22(_temp21); | ||
return _temp23 && _temp23.then ? _temp23.then(_temp24) : _temp24(_temp23); | ||
} | ||
var _temp23 = function () { | ||
if (cmd.name === CommandNames.ClipsAddCommand) { | ||
return Promise.resolve(_this3.onClipsAdd(cmd)).then(function () { | ||
_exit11 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp25 = function () { | ||
if (cmd.name === 'clips get') { | ||
return Promise.resolve(_this.onClipsGet(cmd).then(formatClipsGetResponse)).then(function (res) { | ||
_exit10 = true; | ||
return { | ||
code: SynchronousCode.ClipsInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1188,10 +1046,13 @@ } | ||
return _temp23 && _temp23.then ? _temp23.then(_temp24) : _temp24(_temp23); | ||
return _temp25 && _temp25.then ? _temp25.then(_temp26) : _temp26(_temp25); | ||
} | ||
var _temp25 = function () { | ||
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); | ||
var _temp27 = function () { | ||
if (cmd.name === 'clips count') { | ||
return Promise.resolve(_this.onClipsCount(cmd)).then(function (res) { | ||
_exit9 = true; | ||
return { | ||
code: SynchronousCode.ClipsCount, | ||
params: res | ||
}; | ||
}); | ||
@@ -1201,10 +1062,10 @@ } | ||
return _temp25 && _temp25.then ? _temp25.then(_temp26) : _temp26(_temp25); | ||
return _temp27 && _temp27.then ? _temp27.then(_temp28) : _temp28(_temp27); | ||
} | ||
var _temp27 = function () { | ||
if (cmd.name === CommandNames.ClipsCountCommand) { | ||
return Promise.resolve(_this3.onClipsCount(cmd)).then(function (res) { | ||
_exit9 = true; | ||
return new TResponse(exports.SynchronousCode.ClipsCount, res); | ||
var _temp29 = function () { | ||
if (cmd.name === 'stop') { | ||
return Promise.resolve(_this.onStop(cmd)).then(function () { | ||
_exit8 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1214,10 +1075,10 @@ } | ||
return _temp27 && _temp27.then ? _temp27.then(_temp28) : _temp28(_temp27); | ||
return _temp29 && _temp29.then ? _temp29.then(_temp30) : _temp30(_temp29); | ||
} | ||
var _temp29 = function () { | ||
if (cmd.name === CommandNames.StopCommand) { | ||
return Promise.resolve(_this3.onStop(cmd)).then(function () { | ||
_exit8 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp31 = function () { | ||
if (cmd.name === 'record') { | ||
return Promise.resolve(_this.onRecord(cmd)).then(function () { | ||
_exit7 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1227,10 +1088,10 @@ } | ||
return _temp29 && _temp29.then ? _temp29.then(_temp30) : _temp30(_temp29); | ||
return _temp31 && _temp31.then ? _temp31.then(_temp32) : _temp32(_temp31); | ||
} | ||
var _temp31 = function () { | ||
if (cmd.name === CommandNames.RecordCommand) { | ||
return Promise.resolve(_this3.onRecord(cmd)).then(function () { | ||
_exit7 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp33 = function () { | ||
if (cmd.name === 'playrange clear') { | ||
return Promise.resolve(_this.onPlayrangeClear(cmd)).then(function () { | ||
_exit6 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1240,10 +1101,10 @@ } | ||
return _temp31 && _temp31.then ? _temp31.then(_temp32) : _temp32(_temp31); | ||
return _temp33 && _temp33.then ? _temp33.then(_temp34) : _temp34(_temp33); | ||
} | ||
var _temp33 = function () { | ||
if (cmd.name === CommandNames.PlayrangeClearCommand) { | ||
return Promise.resolve(_this3.onPlayrangeClear(cmd)).then(function () { | ||
_exit6 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp35 = function () { | ||
if (cmd.name === 'playrange set') { | ||
return Promise.resolve(_this.onPlayrangeSet(cmd)).then(function () { | ||
_exit5 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1253,10 +1114,10 @@ } | ||
return _temp33 && _temp33.then ? _temp33.then(_temp34) : _temp34(_temp33); | ||
return _temp35 && _temp35.then ? _temp35.then(_temp36) : _temp36(_temp35); | ||
} | ||
var _temp35 = function () { | ||
if (cmd.name === CommandNames.PlayrangeSetCommand) { | ||
return Promise.resolve(_this3.onPlayrangeSet(cmd)).then(function () { | ||
_exit5 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp37 = function () { | ||
if (cmd.name === 'play') { | ||
return Promise.resolve(_this.onPlay(cmd)).then(function () { | ||
_exit4 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1266,10 +1127,10 @@ } | ||
return _temp35 && _temp35.then ? _temp35.then(_temp36) : _temp36(_temp35); | ||
return _temp37 && _temp37.then ? _temp37.then(_temp38) : _temp38(_temp37); | ||
} | ||
var _temp37 = function () { | ||
if (cmd.name === CommandNames.PlayCommand) { | ||
return Promise.resolve(_this3.onPlay(cmd)).then(function () { | ||
_exit4 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp39 = function () { | ||
if (cmd.name === 'preview') { | ||
return Promise.resolve(_this.onPreview(cmd)).then(function () { | ||
_exit3 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1279,10 +1140,13 @@ } | ||
return _temp37 && _temp37.then ? _temp37.then(_temp38) : _temp38(_temp37); | ||
return _temp39 && _temp39.then ? _temp39.then(_temp40) : _temp40(_temp39); | ||
} | ||
var _temp39 = function () { | ||
if (cmd.name === CommandNames.PreviewCommand) { | ||
return Promise.resolve(_this3.onPreview(cmd)).then(function () { | ||
_exit3 = true; | ||
return new TResponse(exports.SynchronousCode.OK); | ||
var _temp41 = function () { | ||
if (cmd.name === 'disk list') { | ||
return Promise.resolve(_this.onDiskList(cmd)).then(function (res) { | ||
_exit2 = true; | ||
return { | ||
code: SynchronousCode.DiskList, | ||
params: res | ||
}; | ||
}); | ||
@@ -1292,10 +1156,13 @@ } | ||
return _temp39 && _temp39.then ? _temp39.then(_temp40) : _temp40(_temp39); | ||
return _temp41 && _temp41.then ? _temp41.then(_temp42) : _temp42(_temp41); | ||
} | ||
var _temp41 = function () { | ||
if (cmd.name === CommandNames.DiskListCommand) { | ||
return Promise.resolve(_this3.onDiskList(cmd)).then(function (res) { | ||
_exit2 = true; | ||
return new TResponse(exports.SynchronousCode.DiskList, res); | ||
var _temp43 = function () { | ||
if (cmd.name === 'device info') { | ||
return Promise.resolve(_this.onDeviceInfo(cmd)).then(function (res) { | ||
_exit = true; | ||
return { | ||
code: SynchronousCode.DeviceInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1305,50 +1172,109 @@ } | ||
return _temp41 && _temp41.then ? _temp41.then(_temp42) : _temp42(_temp41); | ||
} | ||
return _temp43 && _temp43.then ? _temp43.then(_temp44) : _temp44(_temp43); | ||
}, function (err) { | ||
if (err instanceof UnimplementedError) { | ||
_this.logger.error({ | ||
cmd: cmd | ||
}, 'unimplemented'); | ||
var _temp43 = function () { | ||
if (cmd.name === CommandNames.DeviceInfoCommand) { | ||
return Promise.resolve(_this3.onDeviceInfo(cmd)).then(function (res) { | ||
_exit = true; | ||
return new TResponse(exports.SynchronousCode.DeviceInfo, res); | ||
}); | ||
return ErrorCode.Unsupported; | ||
} | ||
}(); | ||
return _temp43 && _temp43.then ? _temp43.then(_temp44) : _temp44(_temp43); | ||
}, function (err) { | ||
if (err instanceof UnimplementedError) { | ||
_this3.logger.error({ | ||
cmd: cmd | ||
}, 'unimplemented'); | ||
_this.logger.error({ | ||
cmd: cmd, | ||
err: err.message | ||
}, 'unhandled command name'); | ||
return new TResponse(exports.ErrorCode.Unsupported); | ||
} | ||
return ErrorCode.InternalError; | ||
}); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
if (err && typeof err.code === 'number' && exports.ErrorCode[err.code] && err.msg) { | ||
_this3.logger.error({ | ||
err: err | ||
}, 'error with code'); | ||
this.logger = logger.child({ | ||
name: 'HyperDeck Emulator' | ||
}); | ||
this.server = net.createServer(function (socket) { | ||
_this2.logger.info('connection'); | ||
return new ErrorResponse(err.code, err.msg); | ||
} | ||
var socketId = Math.random().toString(35).substr(-6); | ||
_this3.logger.error({ | ||
cmd: cmd | ||
}, 'internal error'); | ||
var socketLogger = _this2.logger.child({ | ||
name: 'HyperDeck socket ' + socketId | ||
}); | ||
return new TResponse(exports.ErrorCode.InternalError); | ||
}); | ||
_this2.sockets[socketId] = new HyperDeckSocket(socket, socketLogger, function (cmd) { | ||
return _this2.receivedCommand(cmd); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
_this2.sockets[socketId].on('disconnected', function () { | ||
socketLogger.info('disconnected'); | ||
delete _this2.sockets[socketId]; | ||
}); | ||
}); | ||
this.server.on('listening', function () { | ||
return _this2.logger.info('listening'); | ||
}); | ||
this.server.on('close', function () { | ||
return _this2.logger.info('connection closed'); | ||
}); | ||
this.server.on('error', function (err) { | ||
return _this2.logger.error('server error:', err); | ||
}); | ||
this.server.maxConnections = 1; | ||
this.server.listen(9993, ip); | ||
} | ||
var _proto = HyperDeckServer.prototype; | ||
_proto.close = function close() { | ||
this.server.unref(); | ||
}; | ||
_proto.notifySlot = function notifySlot(params) { | ||
this.notify('slot', params); | ||
}; | ||
_proto.notifyTransport = function notifyTransport(params) { | ||
this.notify('transport', params); | ||
}; | ||
_proto.notify = function notify(type, params) { | ||
for (var _i = 0, _Object$keys = Object.keys(this.sockets); _i < _Object$keys.length; _i++) { | ||
var id = _Object$keys[_i]; | ||
this.sockets[id].notify(type, params); | ||
} | ||
}; | ||
return HyperdeckServer; | ||
return HyperDeckServer; | ||
}(); | ||
exports.HyperdeckServer = HyperdeckServer; | ||
var Timecode = function Timecode(hh, mm, ss, ff) { | ||
var 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(':'); | ||
this.toString = function () { | ||
return timecode; | ||
}; | ||
}; | ||
var ResponseInterface = { | ||
__proto__: null | ||
}; | ||
exports.HyperDeckServer = HyperDeckServer; | ||
exports.ResponseInterface = ResponseInterface; | ||
exports.Timecode = Timecode; | ||
//# sourceMappingURL=hyperdeck-emulator.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"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; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,n,t,r,o,i=require("events"),s=require("net"),a=(e=require("pino"))&&"object"==typeof e&&"default"in e?e.default:e;function u(e,n){e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e.__proto__=n}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e,n){return(c=Object.setPrototypeOf||function(e,n){return e.__proto__=n,e})(e,n)}function l(){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 p(e,n,t){return(p=l()?Reflect.construct:function(e,n,t){var r=[null];r.push.apply(r,n);var o=new(Function.bind.apply(e,r));return t&&c(o,t.prototype),o}).apply(null,arguments)}function m(e){var n="function"==typeof Map?new Map:void 0;return(m=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,t)}function t(){return p(e,arguments,f(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),c(t,e)})(e)}function d(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator"))),function(e){e[e.SyntaxError=100]="SyntaxError",e[e.UnsupportedParameter=101]="UnsupportedParameter",e[e.InvalidValue=102]="InvalidValue",e[e.Unsupported=103]="Unsupported",e[e.DiskFull=104]="DiskFull",e[e.NoDisk=105]="NoDisk",e[e.DiskError=106]="DiskError",e[e.TimelineEmpty=107]="TimelineEmpty",e[e.InternalError=108]="InternalError",e[e.OutOfRange=109]="OutOfRange",e[e.NoInput=110]="NoInput",e[e.RemoteControlDisabled=111]="RemoteControlDisabled",e[e.ConnectionRejected=120]="ConnectionRejected",e[e.InvalidState=150]="InvalidState",e[e.InvalidCodec=151]="InvalidCodec",e[e.InvalidFormat=160]="InvalidFormat",e[e.InvalidToken=161]="InvalidToken",e[e.FormatNotPrepared=162]="FormatNotPrepared"}(t||(t={})),function(e){e[e.OK=200]="OK",e[e.SlotInfo=202]="SlotInfo",e[e.DeviceInfo=204]="DeviceInfo",e[e.ClipsInfo=205]="ClipsInfo",e[e.DiskList=206]="DiskList",e[e.TransportInfo=208]="TransportInfo",e[e.Notify=209]="Notify",e[e.Remote=210]="Remote",e[e.Configuration=211]="Configuration",e[e.ClipsCount=214]="ClipsCount",e[e.Uptime=215]="Uptime",e[e.FormatReady=216]="FormatReady"}(r||(r={})),function(e){e[e.ConnectionInfo=500]="ConnectionInfo",e[e.SlotInfo=502]="SlotInfo",e[e.TransportInfo=508]="TransportInfo",e[e.RemoteInfo=510]="RemoteInfo",e[e.ConfigurationInfo=511]="ConfigurationInfo"}(o||(o={}));var h,v,g,y=((n={})[o.ConfigurationInfo]="configuration info",n[o.ConnectionInfo]="connection info",n[o.RemoteInfo]="remote info",n[o.SlotInfo]="slot info",n[o.TransportInfo]="transport info",n[t.ConnectionRejected]="connection rejected",n[t.DiskError]="disk error",n[t.DiskFull]="disk full",n[t.FormatNotPrepared]="format not prepared",n[t.InternalError]="internal error",n[t.InvalidCodec]="invalid codec",n[t.InvalidFormat]="invalid format",n[t.InvalidState]="invalid state",n[t.InvalidToken]="invalid token",n[t.InvalidValue]="invalid value",n[t.NoDisk]="no disk",n[t.NoInput]="no input",n[t.OutOfRange]="out of range",n[t.RemoteControlDisabled]="remote control disabled",n[t.SyntaxError]="syntax error",n[t.TimelineEmpty]="timeline empty",n[t.Unsupported]="unsupported",n[t.UnsupportedParameter]="unsupported parameter",n[r.ClipsCount]="clips count",n[r.ClipsInfo]="clips info",n[r.Configuration]="configuration",n[r.DeviceInfo]="device info",n[r.DiskList]="disk list",n[r.FormatReady]="format ready",n[r.Notify]="notify",n[r.OK]="ok",n[r.Remote]="remote",n[r.SlotInfo]="slot info",n[r.TransportInfo]="transport info",n[r.Uptime]="uptime",n);!function(e){e.QuickTimeUncompressed="QuickTimeUncompressed",e.QuickTimeProResHQ="QuickTimeProResHQ",e.QuickTimeProRes="QuickTimeProRes",e.QuickTimeProResLT="QuickTimeProResLT",e.QuickTimeProResProxy="QuickTimeProResProxy",e.QuickTimeDNxHR220="QuickTimeDNxHR220",e.DNxHR220="DNxHR220"}(h||(h={})),function(e){e.embedded="embedded",e.XLR="XLR",e.RCA="RCA"}(v||(v={})),function(e){e.SDI="SDI",e.HDMI="HDMI",e.component="component"}(g||(g={}));var I={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"]},S=function(){function e(e){this.linesQueue=[],this.logger=e.child({name:"MultilineParser"})}var n=e.prototype;return n.receivedString=function(e){var n=[],t=e.split("\r\n");for(t.length>0&&""===t[t.length-1]&&t.pop(),this.linesQueue=this.linesQueue.concat(t);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 o=this.linesQueue.indexOf("");if(-1===o)break;var i=this.linesQueue.splice(0,o+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(": "),t=n.shift();if(!t)throw new Error("Unrecognised command");var r={},o=new Set(I[t]),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="",f=a.length-1;f>=0&&(u=(a.pop()+" "+u).trim(),!o.has(u));f--);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:t,parameters:r}}var c=e[0].match(/(.+?)(:|)$/im);if(!c)return this.logger.error({header:e[0]},"failed to parse header"),null;for(var l=c[1],p={},m=1;m<e.length;m++){var d=e[m].match(/^(.*?): (.*)$/im);d?p[d[1]]=d[2]:this.logger.error({line:e[m]},"failed to parse line")}return{raw:e.join("\r\n"),name:l,parameters:p}},e}(),b=function(e){function n(n,t,r){var i;return(i=e.call(this)||this).socket=n,i.logger=t,i.receivedCommand=r,i.lastReceivedMS=-1,i.watchdogTimer=null,i.notifySettings={slot:!1,transport:!1,remote:!1,configuration:!1,"dropped frames":!1},i.parser=new S(t),i.socket.setEncoding("utf-8"),i.socket.on("data",(function(e){i.onMessage(e)})),i.socket.on("error",(function(e){t.info({err:e},"error"),i.socket.destroy(),i.emit("disconnected"),t.info("manually disconnected")})),i.sendResponse(o.ConnectionInfo,{"protocol version":"1.11",model:"NodeJS HyperDeck Server Library"}),i}u(n,e);var i=n.prototype;return i.onMessage=function(e){var n=this;this.logger.info({data:e},"<-- received message from client"),this.lastReceivedMS=Date.now();var i=this.parser.receivedString(e);this.logger.info({cmds:i},"parsed commands");for(var s,a=function(){var e=s.value;if("watchdog"===e.name){n.watchdogTimer&&clearInterval(n.watchdogTimer);var i=e;i.parameters.period&&(n.watchdogTimer=setInterval((function(){Date.now()-n.lastReceivedMS>Number(i.parameters.period)&&(n.socket.destroy(),n.emit("disconnected"),n.watchdogTimer&&clearInterval(n.watchdogTimer))}),1e3*Number(i.parameters.period)))}else if("notify"===e.name){var a=e;if(!(Object.keys(a.parameters).length>0)){for(var u={},f=0,c=Object.keys(n.notifySettings);f<c.length;f++){var l=c[f];u[l]=n.notifySettings[l]?"true":"false"}return n.sendResponse(r.Notify,u,e),"continue"}for(var p=0,m=Object.keys(a.parameters);p<m.length;p++){var d=m[p];void 0!==n.notifySettings[d]&&(n.notifySettings[d]="true"===a.parameters[d])}}n.receivedCommand(e).then((function(i){return"object"==typeof i?n.sendResponse(i.code,"params"in i&&i.params||"message"in i&&i.message||void 0,e):"number"==typeof i&&(t[i]||r[i]||o[i])?n.sendResponse(i,void 0,e):(n.logger.error({cmd:e,codeOrObj:i},"codeOrObj was neither a ResponseCode nor a response object"),void n.sendResponse(t.InternalError,void 0,e))}),(function(){return n.sendResponse(t.Unsupported,void 0,e)}))},u=function(e,n){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return d(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?d(e,void 0):void 0}}(e))){t&&(e=t);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(t=e[Symbol.iterator]()).next.bind(t)}(i);!(s=u()).done;)a()},i.sendResponse=function(e,n,r){var o=function(e,n){if("string"==typeof n)return e+" "+n.replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/:/g,"")+"\r\n";var t=e+" "+y[e];if(!n)return t+"\r\n";var r=Object.entries(n).filter((function(e){return null!=e[1]}));return 0===r.length?t+"\r\n":r.reduce((function(e,n){var t,r=n[0],o=n[1];if("string"==typeof o)t=o;else if("boolean"==typeof o)t=o?"true":"false";else{if("number"!=typeof o)throw new Error("Unhandled value type: "+typeof o);t=o.toString()}return e+r.replace(/([a-z])([A-Z]+)/,"$1 $2").toLowerCase()+": "+t+"\r\n"}),t+":\r\n")+"\r\n"}(e,n);this.logger[t[e]?"error":"info"]({responseText:o,cmd:r},"--\x3e send response to client"),this.socket.write(o)},i.notify=function(e,n){this.logger.info({type:e,params:n},"notify"),"configuration"===e&&this.notifySettings.configuration?this.sendResponse(o.ConfigurationInfo,n):"remote"===e&&this.notifySettings.remote?this.sendResponse(o.RemoteInfo,n):"slot"===e&&this.notifySettings.slot?this.sendResponse(o.SlotInfo,n):"transport"===e&&this.notifySettings.transport?this.sendResponse(o.TransportInfo,n):this.logger.error({type:e,params:n},"unhandled notify type")},n}(i.EventEmitter),R=function(e){for(var n=e.clips.length,t={clipsCount:n},r=0;r<n;r++){var o=e.clips[r];t[(r+1).toString()]=o.name+" "+o.startT+" "+o.duration}return t},k=function(e){function n(){return e.apply(this,arguments)||this}return u(n,e),n}(m(Error)),C=function(){try{throw new k}catch(e){return Promise.reject(e)}};exports.HyperDeckServer=function(){function e(e,n){var o=this,i=this;void 0===n&&(n=a()),this.sockets={},this.onDeviceInfo=C,this.onDiskList=C,this.onPreview=C,this.onPlay=C,this.onPlayrangeSet=C,this.onPlayrangeClear=C,this.onRecord=C,this.onStop=C,this.onClipsCount=C,this.onClipsGet=C,this.onClipsAdd=C,this.onClipsClear=C,this.onTransportInfo=C,this.onSlotInfo=C,this.onSlotSelect=C,this.onGoTo=C,this.onJog=C,this.onShuttle=C,this.onConfiguration=C,this.onUptime=C,this.onFormat=C,this.onIdentify=C,this.onWatchdog=C,this.receivedCommand=function(e){try{return Promise.resolve(new Promise((function(e){return setTimeout((function(){return e()}),200)}))).then((function(){var n=!1;return i.logger.info({cmd:e},"<-- "+e.name),function(t,o){try{var s=function(){function t(t){var o=!1;if(n)return t;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){var t=!1;if(o)return n;function s(n){var o=!1;if(t)return n;function s(n){if(o)return n;if("watchdog"===e.name)return r.OK;if("ping"===e.name)return r.OK;throw new Error("Unhandled command name: "+e.name)}var a=function(){if("identify"===e.name)return Promise.resolve(i.onIdentify(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("format"===e.name)return Promise.resolve(i.onFormat(e)).then((function(e){return e?(t=!0,{code:r.FormatReady,params:e}):(t=!0,r.OK)}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("uptime"===e.name)return Promise.resolve(i.onUptime(e)).then((function(e){return o=!0,{code:r.Uptime,params:e}}))}();return a&&a.then?a.then(s):s(a)}if("remote"===e.name)return{code:r.Remote,params:{enabled:!0,override:!1}};var a=function(){if("configuration"===e.name)return Promise.resolve(i.onConfiguration(e)).then((function(e){return e?(t=!0,{code:r.Configuration,params:e}):(t=!0,r.OK)}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("shuttle"===e.name)return Promise.resolve(i.onShuttle(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("jog"===e.name)return Promise.resolve(i.onJog(e)).then((function(){return t=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}if("notify"===e.name)return r.OK;var a=function(){if("go to"===e.name)return Promise.resolve(i.onGoTo(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("slot select"===e.name)return Promise.resolve(i.onSlotSelect(e)).then((function(){return t=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("slot info"===e.name)return Promise.resolve(i.onSlotInfo(e)).then((function(e){return o=!0,{code:r.SlotInfo,params:e}}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("transport info"===e.name)return Promise.resolve(i.onTransportInfo(e)).then((function(e){return t=!0,{code:r.TransportInfo,params:e}}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("clips clear"===e.name)return Promise.resolve(i.onClipsClear(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("clips add"===e.name)return Promise.resolve(i.onClipsAdd(e)).then((function(){return t=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("clips get"===e.name)return Promise.resolve(i.onClipsGet(e).then(R)).then((function(e){return o=!0,{code:r.ClipsInfo,params:e}}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("clips count"===e.name)return Promise.resolve(i.onClipsCount(e)).then((function(e){return t=!0,{code:r.ClipsCount,params:e}}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("stop"===e.name)return Promise.resolve(i.onStop(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("record"===e.name)return Promise.resolve(i.onRecord(e)).then((function(){return t=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("playrange clear"===e.name)return Promise.resolve(i.onPlayrangeClear(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("playrange set"===e.name)return Promise.resolve(i.onPlayrangeSet(e)).then((function(){return t=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("play"===e.name)return Promise.resolve(i.onPlay(e)).then((function(){return o=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("preview"===e.name)return Promise.resolve(i.onPreview(e)).then((function(){return t=!0,r.OK}))}();return a&&a.then?a.then(s):s(a)}var a=function(){if("disk list"===e.name)return Promise.resolve(i.onDiskList(e)).then((function(e){return o=!0,{code:r.DiskList,params:e}}))}();return a&&a.then?a.then(s):s(a)}var o=function(){if("device info"===e.name)return Promise.resolve(i.onDeviceInfo(e)).then((function(e){return n=!0,{code:r.DeviceInfo,params:e}}))}();return o&&o.then?o.then(t):t(o)}()}catch(e){return o(e)}return s&&s.then?s.then(void 0,o):s}(0,(function(n){return n instanceof k?(i.logger.error({cmd:e},"unimplemented"),t.Unsupported):(i.logger.error({cmd:e,err:n.message},"unhandled command name"),t.InternalError)}))}))}catch(e){return Promise.reject(e)}},this.logger=n.child({name:"HyperDeck Emulator"}),this.server=s.createServer((function(e){o.logger.info("connection");var n=Math.random().toString(35).substr(-6),t=o.logger.child({name:"HyperDeck socket "+n});o.sockets[n]=new b(e,t,(function(e){return o.receivedCommand(e)})),o.sockets[n].on("disconnected",(function(){t.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("slot",e)},n.notifyTransport=function(e){this.notify("transport",e)},n.notify=function(e,n){for(var t=0,r=Object.keys(this.sockets);t<r.length;t++)this.sockets[r[t]].notify(e,n)},e}(),exports.ResponseInterface={__proto__:null},exports.Timecode=function(e,n,t,r){var o=[e,n,t,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(":");this.toString=function(){return o}}; | ||
//# sourceMappingURL=hyperdeck-emulator.cjs.production.min.js.map |
import { EventEmitter } from 'events'; | ||
import util from 'util'; | ||
import { createServer } from 'net'; | ||
@@ -157,59 +156,4 @@ import pino from 'pino'; | ||
var ResponseInterface = { | ||
__proto__: null | ||
}; | ||
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 = function TResponse(code, params) { | ||
var _this = this; | ||
this.code = code; | ||
this.params = params; | ||
this.build = function () { | ||
return messageForCode(_this.code, _this.params); | ||
}; | ||
!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 idx = 0; idx < clipsCount; idx++) { | ||
var clip = res.clips[idx]; | ||
var clipKey = (idx + 1).toString(); | ||
response[clipKey] = clip.name + " " + clip.startT + " " + clip.duration; | ||
} | ||
return response; | ||
}; | ||
var ErrorResponse = function ErrorResponse(code, message) { | ||
var _this2 = this; | ||
this.code = code; | ||
this.message = message; | ||
this.build = function () { | ||
return _this2.code + ' ' + _this2.message + CRLF; | ||
}; | ||
!responseNamesByCode.hasOwnProperty(code) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Invalid code: `%o`', code) : invariant(false) : void 0; | ||
}; | ||
var ErrorCode; | ||
@@ -265,104 +209,33 @@ | ||
var NotifyType; | ||
var responseNamesByCode = (_responseNamesByCode = {}, _responseNamesByCode[AsynchronousCode.ConfigurationInfo] = 'configuration info', _responseNamesByCode[AsynchronousCode.ConnectionInfo] = 'connection info', _responseNamesByCode[AsynchronousCode.RemoteInfo] = 'remote info', _responseNamesByCode[AsynchronousCode.SlotInfo] = 'slot info', _responseNamesByCode[AsynchronousCode.TransportInfo] = 'transport info', _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] = 'clips count', _responseNamesByCode[SynchronousCode.ClipsInfo] = 'clips info', _responseNamesByCode[SynchronousCode.Configuration] = 'configuration', _responseNamesByCode[SynchronousCode.DeviceInfo] = 'device info', _responseNamesByCode[SynchronousCode.DiskList] = 'disk list', _responseNamesByCode[SynchronousCode.FormatReady] = 'format ready', _responseNamesByCode[SynchronousCode.Notify] = 'notify', _responseNamesByCode[SynchronousCode.OK] = 'ok', _responseNamesByCode[SynchronousCode.Remote] = 'remote', _responseNamesByCode[SynchronousCode.SlotInfo] = 'slot info', _responseNamesByCode[SynchronousCode.TransportInfo] = 'transport info', _responseNamesByCode[SynchronousCode.Uptime] = 'uptime', _responseNamesByCode); | ||
var FileFormat; | ||
(function (NotifyType) { | ||
NotifyType[NotifyType["Slot"] = 0] = "Slot"; | ||
NotifyType[NotifyType["Transport"] = 1] = "Transport"; | ||
NotifyType[NotifyType["Remote"] = 2] = "Remote"; | ||
NotifyType[NotifyType["Configuration"] = 3] = "Configuration"; | ||
})(NotifyType || (NotifyType = {})); | ||
(function (FileFormat) { | ||
FileFormat["QuickTimeUncompressed"] = "QuickTimeUncompressed"; | ||
FileFormat["QuickTimeProResHQ"] = "QuickTimeProResHQ"; | ||
FileFormat["QuickTimeProRes"] = "QuickTimeProRes"; | ||
FileFormat["QuickTimeProResLT"] = "QuickTimeProResLT"; | ||
FileFormat["QuickTimeProResProxy"] = "QuickTimeProResProxy"; | ||
FileFormat["QuickTimeDNxHR220"] = "QuickTimeDNxHR220"; | ||
FileFormat["DNxHR220"] = "DNxHR220"; | ||
})(FileFormat || (FileFormat = {})); | ||
var CommandNames; | ||
var AudioInput; | ||
(function (CommandNames) { | ||
CommandNames["DeviceInfoCommand"] = "device info"; | ||
CommandNames["DiskListCommand"] = "disk list"; | ||
CommandNames["PreviewCommand"] = "preview"; | ||
CommandNames["PlayCommand"] = "play"; | ||
CommandNames["PlayrangeSetCommand"] = "playrange set"; | ||
CommandNames["PlayrangeClearCommand"] = "playrange clear"; | ||
CommandNames["RecordCommand"] = "record"; | ||
CommandNames["StopCommand"] = "stop"; | ||
CommandNames["ClipsCountCommand"] = "clips count"; | ||
CommandNames["ClipsGetCommand"] = "clips get"; | ||
CommandNames["ClipsAddCommand"] = "clips add"; | ||
CommandNames["ClipsClearCommand"] = "clips clear"; | ||
CommandNames["TransportInfoCommand"] = "transport info"; | ||
CommandNames["SlotInfoCommand"] = "slot info"; | ||
CommandNames["SlotSelectCommand"] = "slot select"; | ||
CommandNames["NotifyCommand"] = "notify"; | ||
CommandNames["GoToCommand"] = "goto"; | ||
CommandNames["JogCommand"] = "jog"; | ||
CommandNames["ShuttleCommand"] = "shuttle"; | ||
CommandNames["RemoteCommand"] = "remote"; | ||
CommandNames["ConfigurationCommand"] = "configuration"; | ||
CommandNames["UptimeCommand"] = "uptime"; | ||
CommandNames["FormatCommand"] = "format"; | ||
CommandNames["IdentifyCommand"] = "identify"; | ||
CommandNames["WatchdogCommand"] = "watchdog"; | ||
CommandNames["PingCommand"] = "ping"; | ||
})(CommandNames || (CommandNames = {})); | ||
(function (AudioInput) { | ||
AudioInput["embedded"] = "embedded"; | ||
AudioInput["XLR"] = "XLR"; | ||
AudioInput["RCA"] = "RCA"; | ||
})(AudioInput || (AudioInput = {})); | ||
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); | ||
var VideoInputs; | ||
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 | ||
(function (VideoInputs) { | ||
VideoInputs["SDI"] = "SDI"; | ||
VideoInputs["HDMI"] = "HDMI"; | ||
VideoInputs["component"] = "component"; | ||
})(VideoInputs || (VideoInputs = {})); | ||
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 = { | ||
var CRLF = '\r\n'; | ||
var parametersByCommandName = { | ||
help: [], | ||
@@ -398,84 +271,7 @@ commands: [], | ||
}; | ||
var SlotStatus; | ||
(function (SlotStatus) { | ||
SlotStatus["EMPTY"] = "empty"; | ||
SlotStatus["MOUNTING"] = "mounting"; | ||
SlotStatus["ERROR"] = "error"; | ||
SlotStatus["MOUNTED"] = "mounted"; | ||
})(SlotStatus || (SlotStatus = {})); | ||
var VideoFormat; | ||
(function (VideoFormat) { | ||
VideoFormat["NTSC"] = "NTSC"; | ||
VideoFormat["PAL"] = "PAL"; | ||
VideoFormat["NTSCp"] = "NTSCp"; | ||
VideoFormat["PALp"] = "PALp"; | ||
VideoFormat["_720p50"] = "720p50"; | ||
VideoFormat["_720p5994"] = "720p5994"; | ||
VideoFormat["_720p60"] = "720p60"; | ||
VideoFormat["_1080p23976"] = "1080p23976"; | ||
VideoFormat["_1080p24"] = "1080p24"; | ||
VideoFormat["_1080p25"] = "1080p25"; | ||
VideoFormat["_1080p2997"] = "1080p2997"; | ||
VideoFormat["_1080p30"] = "1080p30"; | ||
VideoFormat["_1080i50"] = "1080i50"; | ||
VideoFormat["_1080i5994"] = "1080i5994"; | ||
VideoFormat["_1080i60"] = "1080i60"; | ||
VideoFormat["_4Kp23976"] = "4Kp23976"; | ||
VideoFormat["_4Kp24"] = "4Kp24"; | ||
VideoFormat["_4Kp25"] = "4Kp25"; | ||
VideoFormat["_4Kp2997"] = "4Kp2997"; | ||
VideoFormat["_4Kp30"] = "4Kp30"; | ||
VideoFormat["_4Kp50"] = "4Kp50"; | ||
VideoFormat["_4Kp5994"] = "4Kp5994"; | ||
VideoFormat["_4Kp60"] = "4Kp60"; | ||
})(VideoFormat || (VideoFormat = {})); | ||
var TransportStatus; | ||
(function (TransportStatus) { | ||
TransportStatus["PREVIEW"] = "preview"; | ||
TransportStatus["STOPPED"] = "stopped"; | ||
TransportStatus["PLAY"] = "play"; | ||
TransportStatus["FORWARD"] = "forward"; | ||
TransportStatus["REWIND"] = "rewind"; | ||
TransportStatus["JOG"] = "jog"; | ||
TransportStatus["SHUTTLE"] = "shuttle"; | ||
TransportStatus["RECORD"] = "record"; | ||
})(TransportStatus || (TransportStatus = {})); | ||
var FileFormats; | ||
(function (FileFormats) { | ||
FileFormats["QuickTimeUncompressed"] = "QuickTimeUncompressed"; | ||
FileFormats["QuickTimeProResHQ"] = "QuickTimeProResHQ"; | ||
FileFormats["QuickTimeProRes"] = "QuickTimeProRes"; | ||
FileFormats["QuickTimeProResLT"] = "QuickTimeProResLT"; | ||
FileFormats["QuickTimeProResProxy"] = "QuickTimeProResProxy"; | ||
FileFormats["QuickTimeDNxHR220"] = "QuickTimeDNxHR220"; | ||
FileFormats["DNxHR220"] = "DNxHR220"; | ||
})(FileFormats || (FileFormats = {})); | ||
var AudioInputs; | ||
(function (AudioInputs) { | ||
AudioInputs["embedded"] = "embedded"; | ||
AudioInputs["XLR"] = "XLR"; | ||
AudioInputs["RCA"] = "RCA"; | ||
})(AudioInputs || (AudioInputs = {})); | ||
var VideoInputs; | ||
(function (VideoInputs) { | ||
VideoInputs["SDI"] = "SDI"; | ||
VideoInputs["HDMI"] = "HDMI"; | ||
VideoInputs["component"] = "component"; | ||
})(VideoInputs || (VideoInputs = {})); | ||
var MultilineParser = /*#__PURE__*/function () { | ||
function MultilineParser(logger) { | ||
this._linesQueue = []; | ||
this._log = logger.child({ | ||
this.linesQueue = []; | ||
this.logger = logger.child({ | ||
name: 'MultilineParser' | ||
@@ -493,9 +289,8 @@ }); | ||
if (newLines.length > 0 && newLines[newLines.length - 1] === '') newLines.pop(); | ||
this._linesQueue = this._linesQueue.concat(newLines); | ||
this.linesQueue = this.linesQueue.concat(newLines); | ||
while (this._linesQueue.length > 0) { | ||
while (this.linesQueue.length > 0) { | ||
// skip any blank lines | ||
if (this._linesQueue[0] === '') { | ||
this._linesQueue.shift(); | ||
if (this.linesQueue[0] === '') { | ||
this.linesQueue.shift(); | ||
continue; | ||
@@ -505,4 +300,4 @@ } // if the first line has no colon, then it is a single line command | ||
if (this._linesQueue[0].indexOf(':') === -1 || this._linesQueue.length === 1 && this._linesQueue[0].indexOf(':') > 0) { | ||
var _r = this.parseResponse(this._linesQueue.splice(0, 1)); | ||
if (this.linesQueue[0].indexOf(':') === -1 || this.linesQueue.length === 1 && this.linesQueue[0].indexOf(':') > 0) { | ||
var _r = this.parseResponse(this.linesQueue.splice(0, 1)); | ||
@@ -516,3 +311,3 @@ if (_r) { | ||
var endLine = this._linesQueue.indexOf(''); | ||
var endLine = this.linesQueue.indexOf(''); | ||
@@ -524,4 +319,3 @@ if (endLine === -1) { | ||
var lines = this._linesQueue.splice(0, endLine + 1); | ||
var lines = this.linesQueue.splice(0, endLine + 1); | ||
var r = this.parseResponse(lines); | ||
@@ -544,3 +338,3 @@ if (r) res.push(r); | ||
var params = {}; | ||
var paramNames = new Set(ParameterMap[msg]); | ||
var paramNames = new Set(parametersByCommandName[msg]); | ||
var param = bits.shift(); | ||
@@ -579,6 +373,5 @@ if (!param) throw new Error('No named parameters found'); | ||
if (!headerMatch) { | ||
this._log.error({ | ||
this.logger.error({ | ||
header: lines[0] | ||
}, 'failed to parse header'); | ||
return null; | ||
@@ -594,6 +387,5 @@ } | ||
if (!lineMatch) { | ||
this._log.error({ | ||
this.logger.error({ | ||
line: lines[_i2] | ||
}, 'failed to parse line'); | ||
continue; | ||
@@ -617,15 +409,64 @@ } | ||
var HyperdeckSocket = /*#__PURE__*/function (_EventEmitter) { | ||
_inheritsLoose(HyperdeckSocket, _EventEmitter); | ||
var sanitiseMessage = function sanitiseMessage(input) { | ||
return input.replace(/\r/g, '\\r').replace(/\n/g, '\\n').replace(/:/g, ''); | ||
}; | ||
/** For a given code, generate the response message that will be sent to the ATEM */ | ||
function HyperdeckSocket(_socket, logger, _receivedCommand) { | ||
var messageForCode = function messageForCode(code, params) { | ||
if (typeof params === 'string') { | ||
return code + ' ' + sanitiseMessage(params) + CRLF; | ||
} | ||
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 HyperDeckSocket = /*#__PURE__*/function (_EventEmitter) { | ||
_inheritsLoose(HyperDeckSocket, _EventEmitter); | ||
function HyperDeckSocket(socket, logger, receivedCommand) { | ||
var _this; | ||
_this = _EventEmitter.call(this) || this; | ||
_this._socket = _socket; | ||
_this.socket = socket; | ||
_this.logger = logger; | ||
_this._receivedCommand = _receivedCommand; | ||
_this._lastReceived = -1; | ||
_this._watchdogTimer = null; | ||
_this._notifySettings = { | ||
_this.receivedCommand = receivedCommand; | ||
_this.lastReceivedMS = -1; | ||
_this.watchdogTimer = null; | ||
_this.notifySettings = { | ||
slot: false, | ||
@@ -638,24 +479,26 @@ transport: false, | ||
}; | ||
_this._parser = new MultilineParser(logger); | ||
_this.parser = new MultilineParser(logger); | ||
_this._socket.setEncoding('utf-8'); | ||
_this.socket.setEncoding('utf-8'); | ||
_this._socket.on('data', function (data) { | ||
_this._onMessage(data); | ||
_this.socket.on('data', function (data) { | ||
_this.onMessage(data); | ||
}); | ||
_this._socket.on('error', function () { | ||
logger.info('error'); | ||
_this.socket.on('error', function (err) { | ||
logger.info({ | ||
err: err | ||
}, 'error'); | ||
_this._socket.destroy(); | ||
_this.socket.destroy(); | ||
_this.emit('disconnected'); | ||
logger.info('disconnected'); | ||
logger.info('manually disconnected'); | ||
}); | ||
_this.sendResponse(new TResponse(AsynchronousCode.ConnectionInfo, { | ||
_this.sendResponse(AsynchronousCode.ConnectionInfo, { | ||
'protocol version': '1.11', | ||
model: 'NodeJS Hyperdeck Server Library' | ||
})); | ||
model: 'NodeJS HyperDeck Server Library' | ||
}); | ||
@@ -665,5 +508,5 @@ return _this; | ||
var _proto = HyperdeckSocket.prototype; | ||
var _proto = HyperDeckSocket.prototype; | ||
_proto._onMessage = function _onMessage(data) { | ||
_proto.onMessage = function onMessage(data) { | ||
var _this2 = this; | ||
@@ -673,10 +516,8 @@ | ||
data: data | ||
}, 'onMessage'); | ||
this._lastReceived = Date.now(); | ||
var cmds = this._parser.receivedString(data); | ||
}, '<-- received message from client'); | ||
this.lastReceivedMS = Date.now(); | ||
var cmds = this.parser.receivedString(data); | ||
this.logger.info({ | ||
cmds: cmds | ||
}, 'commands'); | ||
}, 'parsed commands'); | ||
@@ -687,15 +528,15 @@ var _loop = function _loop() { | ||
// special cases | ||
if (cmd.name === CommandNames.WatchdogCommand) { | ||
if (_this2._watchdogTimer) clearInterval(_this2._watchdogTimer); | ||
if (cmd.name === 'watchdog') { | ||
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(); | ||
_this2.watchdogTimer = setInterval(function () { | ||
if (Date.now() - _this2.lastReceivedMS > Number(watchdogCmd.parameters.period)) { | ||
_this2.socket.destroy(); | ||
_this2.emit('disconnected'); | ||
if (_this2._watchdogTimer) { | ||
clearInterval(_this2._watchdogTimer); | ||
if (_this2.watchdogTimer) { | ||
clearInterval(_this2.watchdogTimer); | ||
} | ||
@@ -705,3 +546,3 @@ } | ||
} | ||
} else if (cmd.name === CommandNames.NotifyCommand) { | ||
} else if (cmd.name === 'notify') { | ||
var notifyCmd = cmd; | ||
@@ -713,4 +554,4 @@ | ||
if (_this2._notifySettings[param] !== undefined) { | ||
_this2._notifySettings[param] = notifyCmd.parameters[param] === 'true'; | ||
if (_this2.notifySettings[param] !== undefined) { | ||
_this2.notifySettings[param] = notifyCmd.parameters[param] === 'true'; | ||
} | ||
@@ -721,8 +562,8 @@ } | ||
for (var _i2 = 0, _Object$keys2 = Object.keys(_this2._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] = _this2._notifySettings[key] ? 'true' : 'false'; | ||
settings[key] = _this2.notifySettings[key] ? 'true' : 'false'; | ||
} | ||
_this2.sendResponse(new TResponse(SynchronousCode.Notify, settings), cmd); | ||
_this2.sendResponse(SynchronousCode.Notify, settings, cmd); | ||
@@ -733,7 +574,24 @@ return "continue"; | ||
_this2._receivedCommand(cmd).then(function (res) { | ||
return _this2.sendResponse(res, cmd); | ||
_this2.receivedCommand(cmd).then(function (codeOrObj) { | ||
if (typeof codeOrObj === 'object') { | ||
var _code = codeOrObj.code; | ||
var paramsOrMessage = 'params' in codeOrObj && codeOrObj.params || 'message' in codeOrObj && codeOrObj.message || undefined; | ||
return _this2.sendResponse(_code, paramsOrMessage, cmd); | ||
} | ||
var code = codeOrObj; | ||
if (typeof code === 'number' && (ErrorCode[code] || SynchronousCode[code] || AsynchronousCode[code])) { | ||
return _this2.sendResponse(code, undefined, cmd); | ||
} | ||
_this2.logger.error({ | ||
cmd: cmd, | ||
codeOrObj: codeOrObj | ||
}, 'codeOrObj was neither a ResponseCode nor a response object'); | ||
_this2.sendResponse(ErrorCode.InternalError, undefined, cmd); | ||
}, // not implemented by client code: | ||
function () { | ||
return _this2.sendResponse(new TResponse(ErrorCode.Unsupported), cmd); | ||
return _this2.sendResponse(ErrorCode.Unsupported, undefined, cmd); | ||
}); | ||
@@ -749,17 +607,10 @@ }; | ||
_proto.sendResponse = function sendResponse(res, cmd) { | ||
var responseText = res.build(); | ||
var txt = '--> ' + ((cmd === null || cmd === void 0 ? void 0 : cmd.name) || 'sendResponse'); | ||
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.sendResponse = function sendResponse(code, paramsOrMessage, cmd) { | ||
var responseText = messageForCode(code, paramsOrMessage); | ||
var method = ErrorCode[code] ? 'error' : 'info'; | ||
this.logger[method]({ | ||
responseText: responseText, | ||
cmd: cmd | ||
}, '--> send response to client'); | ||
this.socket.write(responseText); | ||
}; | ||
@@ -773,16 +624,36 @@ | ||
if (type === NotifyType.Configuration && this._notifySettings.configuration) { | ||
this.sendResponse(new TResponse(AsynchronousCode.ConfigurationInfo, params)); | ||
} else if (type === NotifyType.Remote && this._notifySettings.remote) { | ||
this.sendResponse(new TResponse(AsynchronousCode.RemoteInfo, params)); | ||
} else if (type === NotifyType.Slot && this._notifySettings.slot) { | ||
this.sendResponse(new TResponse(AsynchronousCode.SlotInfo, params)); | ||
} else if (type === NotifyType.Transport && this._notifySettings.transport) { | ||
this.sendResponse(new TResponse(AsynchronousCode.TransportInfo, params)); | ||
if (type === 'configuration' && this.notifySettings.configuration) { | ||
this.sendResponse(AsynchronousCode.ConfigurationInfo, params); | ||
} else if (type === 'remote' && this.notifySettings.remote) { | ||
this.sendResponse(AsynchronousCode.RemoteInfo, params); | ||
} else if (type === 'slot' && this.notifySettings.slot) { | ||
this.sendResponse(AsynchronousCode.SlotInfo, params); | ||
} else if (type === 'transport' && this.notifySettings.transport) { | ||
this.sendResponse(AsynchronousCode.TransportInfo, params); | ||
} else { | ||
this.logger.error({ | ||
type: type, | ||
params: params | ||
}, 'unhandled notify type'); | ||
} | ||
}; | ||
return HyperdeckSocket; | ||
return HyperDeckSocket; | ||
}(EventEmitter); | ||
var formatClipsGetResponse = function formatClipsGetResponse(res) { | ||
var clipsCount = res.clips.length; | ||
var response = { | ||
clipsCount: clipsCount | ||
}; | ||
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; | ||
} | ||
return response; | ||
}; | ||
var UnimplementedError = /*#__PURE__*/function (_Error) { | ||
@@ -806,4 +677,6 @@ _inheritsLoose(UnimplementedError, _Error); | ||
var HyperdeckServer = /*#__PURE__*/function () { | ||
function HyperdeckServer(ip, logger) { | ||
var HyperDeckServer = /*#__PURE__*/function () { | ||
function HyperDeckServer(ip, logger) { | ||
var _this2 = this; | ||
var _this = this; | ||
@@ -815,3 +688,3 @@ | ||
this._sockets = {}; | ||
this.sockets = {}; | ||
this.onDeviceInfo = noop; | ||
@@ -840,185 +713,143 @@ this.onDiskList = noop; | ||
this.onWatchdog = noop; | ||
this.logger = logger.child({ | ||
name: 'HyperDeck Emulator' | ||
}); | ||
this._server = createServer(function (socket) { | ||
_this.logger.info('connection'); | ||
var socketId = Math.random().toString(35).substr(-6); | ||
this.receivedCommand = function (cmd) { | ||
try { | ||
// TODO(meyer) more sophisticated debouncing | ||
return Promise.resolve(new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
return resolve(); | ||
}, 200); | ||
})).then(function () { | ||
var _exit = false; | ||
var socketLogger = _this.logger.child({ | ||
name: 'HyperDeck socket ' + socketId | ||
}); | ||
_this.logger.info({ | ||
cmd: cmd | ||
}, '<-- ' + cmd.name); | ||
_this._sockets[socketId] = new HyperdeckSocket(socket, socketLogger, function (cmd) { | ||
return _this._receivedCommand(cmd); | ||
}); | ||
return _catch(function () { | ||
function _temp44(_result) { | ||
var _exit2 = false; | ||
if (_exit) return _result; | ||
_this._sockets[socketId].on('disconnected', function () { | ||
socketLogger.info('disconnected'); | ||
delete _this._sockets[socketId]; | ||
}); | ||
}); | ||
function _temp42(_result2) { | ||
var _exit3 = false; | ||
if (_exit2) return _result2; | ||
this._server.on('listening', function () { | ||
return _this.logger.info('listening'); | ||
}); | ||
function _temp40(_result3) { | ||
var _exit4 = false; | ||
if (_exit3) return _result3; | ||
this._server.on('close', function () { | ||
return _this.logger.info('connection closed'); | ||
}); | ||
function _temp38(_result4) { | ||
var _exit5 = false; | ||
if (_exit4) return _result4; | ||
this._server.on('error', function (err) { | ||
return _this.logger.error('server error:', err); | ||
}); | ||
function _temp36(_result5) { | ||
var _exit6 = false; | ||
if (_exit5) return _result5; | ||
this._server.maxConnections = 1; | ||
function _temp34(_result6) { | ||
var _exit7 = false; | ||
if (_exit6) return _result6; | ||
this._server.listen(9993, ip); | ||
} | ||
function _temp32(_result7) { | ||
var _exit8 = false; | ||
if (_exit7) return _result7; | ||
var _proto = HyperdeckServer.prototype; | ||
function _temp30(_result8) { | ||
var _exit9 = false; | ||
if (_exit8) return _result8; | ||
_proto.close = function close() { | ||
this._server.unref(); | ||
}; | ||
function _temp28(_result9) { | ||
var _exit10 = false; | ||
if (_exit9) return _result9; | ||
_proto.notifySlot = function notifySlot(params) { | ||
this._notify(NotifyType.Slot, params); | ||
}; | ||
function _temp26(_result10) { | ||
var _exit11 = false; | ||
if (_exit10) return _result10; | ||
_proto.notifyTransport = function notifyTransport(params) { | ||
this._notify(NotifyType.Transport, params); | ||
}; | ||
function _temp24(_result11) { | ||
var _exit12 = false; | ||
if (_exit11) return _result11; | ||
_proto._notify = function _notify(type, params) { | ||
for (var _i = 0, _Object$keys = Object.keys(this._sockets); _i < _Object$keys.length; _i++) { | ||
var id = _Object$keys[_i]; | ||
function _temp22(_result12) { | ||
var _exit13 = false; | ||
if (_exit12) return _result12; | ||
this._sockets[id].notify(type, params); | ||
} | ||
}; | ||
function _temp20(_result13) { | ||
var _exit14 = false; | ||
if (_exit13) return _result13; | ||
_proto._receivedCommand = function _receivedCommand(cmd) { | ||
try { | ||
var _this3 = this; | ||
function _temp18(_result14) { | ||
var _exit15 = false; | ||
if (_exit14) return _result14; | ||
// TODO(meyer) more sophisticated debouncing | ||
return Promise.resolve(new Promise(function (resolve) { | ||
return setTimeout(function () { | ||
return resolve(); | ||
}, 200); | ||
})).then(function () { | ||
var _exit = false; | ||
function _temp16(_result15) { | ||
var _exit16 = false; | ||
if (_exit15) return _result15; | ||
_this3.logger.info({ | ||
cmd: cmd | ||
}, '<-- ' + cmd.name); | ||
function _temp14(_result16) { | ||
var _exit17 = false; | ||
if (_exit16) return _result16; | ||
return _catch(function () { | ||
function _temp44(_result) { | ||
var _exit2 = false; | ||
if (_exit) return _result; | ||
function _temp12(_result17) { | ||
var _exit18 = false; | ||
if (_exit17) return _result17; | ||
function _temp42(_result2) { | ||
var _exit3 = false; | ||
if (_exit2) return _result2; | ||
function _temp10(_result18) { | ||
var _exit19 = false; | ||
if (_exit18) return _result18; | ||
function _temp40(_result3) { | ||
var _exit4 = false; | ||
if (_exit3) return _result3; | ||
function _temp8(_result19) { | ||
var _exit20 = false; | ||
if (_exit19) return _result19; | ||
function _temp38(_result4) { | ||
var _exit5 = false; | ||
if (_exit4) return _result4; | ||
function _temp6(_result20) { | ||
var _exit21 = false; | ||
if (_exit20) return _result20; | ||
function _temp36(_result5) { | ||
var _exit6 = false; | ||
if (_exit5) return _result5; | ||
function _temp4(_result21) { | ||
var _exit22 = false; | ||
if (_exit21) return _result21; | ||
function _temp34(_result6) { | ||
var _exit7 = false; | ||
if (_exit6) return _result6; | ||
function _temp2(_result22) { | ||
if (_exit22) return _result22; | ||
function _temp32(_result7) { | ||
var _exit8 = false; | ||
if (_exit7) return _result7; | ||
if (cmd.name === 'watchdog') { | ||
// implemented in socket.ts | ||
return SynchronousCode.OK; | ||
} | ||
function _temp30(_result8) { | ||
var _exit9 = false; | ||
if (_exit8) return _result8; | ||
if (cmd.name === 'ping') { | ||
// implemented in socket.ts | ||
return SynchronousCode.OK; | ||
} | ||
function _temp28(_result9) { | ||
var _exit10 = false; | ||
if (_exit9) return _result9; | ||
function _temp26(_result10) { | ||
var _exit11 = false; | ||
if (_exit10) return _result10; | ||
function _temp24(_result11) { | ||
var _exit12 = false; | ||
if (_exit11) return _result11; | ||
function _temp22(_result12) { | ||
var _exit13 = false; | ||
if (_exit12) return _result12; | ||
function _temp20(_result13) { | ||
var _exit14 = false; | ||
if (_exit13) return _result13; | ||
function _temp18(_result14) { | ||
var _exit15 = false; | ||
if (_exit14) return _result14; | ||
function _temp16(_result15) { | ||
var _exit16 = false; | ||
if (_exit15) return _result15; | ||
function _temp14(_result16) { | ||
var _exit17 = false; | ||
if (_exit16) return _result16; | ||
function _temp12(_result17) { | ||
var _exit18 = false; | ||
if (_exit17) return _result17; | ||
function _temp10(_result18) { | ||
var _exit19 = false; | ||
if (_exit18) return _result18; | ||
function _temp8(_result19) { | ||
var _exit20 = false; | ||
if (_exit19) return _result19; | ||
function _temp6(_result20) { | ||
var _exit21 = false; | ||
if (_exit20) return _result20; | ||
function _temp4(_result21) { | ||
var _exit22 = false; | ||
if (_exit21) return _result21; | ||
function _temp2(_result22) { | ||
if (_exit22) return _result22; | ||
if (cmd.name === CommandNames.WatchdogCommand) { | ||
// implemented in socket.ts | ||
return new TResponse(SynchronousCode.OK); | ||
throw new Error('Unhandled command name: ' + cmd.name); | ||
} | ||
if (cmd.name === CommandNames.PingCommand) { | ||
// implemented in socket.ts | ||
return new TResponse(SynchronousCode.OK); | ||
} | ||
var _temp = function () { | ||
if (cmd.name === 'identify') { | ||
return Promise.resolve(_this.onIdentify(cmd)).then(function () { | ||
_exit22 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
} | ||
}(); | ||
throw new Error('Unhandled command name: ' + cmd.name); | ||
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp); | ||
} | ||
var _temp = function () { | ||
if (cmd.name === CommandNames.IdentifyCommand) { | ||
return Promise.resolve(_this3.onIdentify(cmd)).then(function () { | ||
_exit22 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp3 = function () { | ||
if (cmd.name === 'format') { | ||
return Promise.resolve(_this.onFormat(cmd)).then(function (res) { | ||
if (res) { | ||
_exit21 = true; | ||
return { | ||
code: SynchronousCode.FormatReady, | ||
params: res | ||
}; | ||
} | ||
_exit21 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1028,15 +859,13 @@ } | ||
return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp); | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
} | ||
var _temp3 = function () { | ||
if (cmd.name === CommandNames.FormatCommand) { | ||
return Promise.resolve(_this3.onFormat(cmd)).then(function (res) { | ||
if (res) { | ||
_exit21 = true; | ||
return new TResponse(SynchronousCode.FormatReady, res); | ||
} | ||
_exit21 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp5 = function () { | ||
if (cmd.name === 'uptime') { | ||
return Promise.resolve(_this.onUptime(cmd)).then(function (res) { | ||
_exit20 = true; | ||
return { | ||
code: SynchronousCode.Uptime, | ||
params: res | ||
}; | ||
}); | ||
@@ -1046,10 +875,28 @@ } | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); | ||
} | ||
var _temp5 = function () { | ||
if (cmd.name === CommandNames.UptimeCommand) { | ||
return Promise.resolve(_this3.onUptime(cmd)).then(function (res) { | ||
_exit20 = true; | ||
return new TResponse(SynchronousCode.Uptime, res); | ||
if (cmd.name === 'remote') { | ||
return { | ||
code: SynchronousCode.Remote, | ||
params: { | ||
enabled: true, | ||
override: false | ||
} | ||
}; | ||
} | ||
var _temp7 = function () { | ||
if (cmd.name === 'configuration') { | ||
return Promise.resolve(_this.onConfiguration(cmd)).then(function (res) { | ||
if (res) { | ||
_exit19 = true; | ||
return { | ||
code: SynchronousCode.Configuration, | ||
params: res | ||
}; | ||
} | ||
_exit19 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1059,22 +906,10 @@ } | ||
return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5); | ||
return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); | ||
} | ||
if (cmd.name === CommandNames.RemoteCommand) { | ||
return new TResponse(SynchronousCode.Remote, { | ||
enabled: true, | ||
override: false | ||
}); | ||
} | ||
var _temp7 = function () { | ||
if (cmd.name === CommandNames.ConfigurationCommand) { | ||
return Promise.resolve(_this3.onConfiguration(cmd)).then(function (res) { | ||
if (res) { | ||
_exit19 = true; | ||
return new TResponse(SynchronousCode.Configuration, res); | ||
} | ||
_exit19 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp9 = function () { | ||
if (cmd.name === 'shuttle') { | ||
return Promise.resolve(_this.onShuttle(cmd)).then(function () { | ||
_exit18 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1084,10 +919,10 @@ } | ||
return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7); | ||
return _temp9 && _temp9.then ? _temp9.then(_temp10) : _temp10(_temp9); | ||
} | ||
var _temp9 = function () { | ||
if (cmd.name === CommandNames.ShuttleCommand) { | ||
return Promise.resolve(_this3.onShuttle(cmd)).then(function () { | ||
_exit18 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp11 = function () { | ||
if (cmd.name === 'jog') { | ||
return Promise.resolve(_this.onJog(cmd)).then(function () { | ||
_exit17 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1097,10 +932,15 @@ } | ||
return _temp9 && _temp9.then ? _temp9.then(_temp10) : _temp10(_temp9); | ||
return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11); | ||
} | ||
var _temp11 = function () { | ||
if (cmd.name === CommandNames.JogCommand) { | ||
return Promise.resolve(_this3.onJog(cmd)).then(function () { | ||
_exit17 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
if (cmd.name === 'notify') { | ||
// implemented in socket.ts | ||
return SynchronousCode.OK; | ||
} | ||
var _temp13 = function () { | ||
if (cmd.name === 'go to') { | ||
return Promise.resolve(_this.onGoTo(cmd)).then(function () { | ||
_exit16 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1110,15 +950,10 @@ } | ||
return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11); | ||
return _temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13); | ||
} | ||
if (cmd.name === CommandNames.NotifyCommand) { | ||
// implemented in socket.ts | ||
return new TResponse(SynchronousCode.OK); | ||
} | ||
var _temp13 = function () { | ||
if (cmd.name === CommandNames.GoToCommand) { | ||
return Promise.resolve(_this3.onGoTo(cmd)).then(function () { | ||
_exit16 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp15 = function () { | ||
if (cmd.name === 'slot select') { | ||
return Promise.resolve(_this.onSlotSelect(cmd)).then(function () { | ||
_exit15 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1128,10 +963,13 @@ } | ||
return _temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13); | ||
return _temp15 && _temp15.then ? _temp15.then(_temp16) : _temp16(_temp15); | ||
} | ||
var _temp15 = function () { | ||
if (cmd.name === CommandNames.SlotSelectCommand) { | ||
return Promise.resolve(_this3.onSlotSelect(cmd)).then(function () { | ||
_exit15 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp17 = function () { | ||
if (cmd.name === 'slot info') { | ||
return Promise.resolve(_this.onSlotInfo(cmd)).then(function (res) { | ||
_exit14 = true; | ||
return { | ||
code: SynchronousCode.SlotInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1141,10 +979,13 @@ } | ||
return _temp15 && _temp15.then ? _temp15.then(_temp16) : _temp16(_temp15); | ||
return _temp17 && _temp17.then ? _temp17.then(_temp18) : _temp18(_temp17); | ||
} | ||
var _temp17 = function () { | ||
if (cmd.name === CommandNames.SlotInfoCommand) { | ||
return Promise.resolve(_this3.onSlotInfo(cmd)).then(function (res) { | ||
_exit14 = true; | ||
return new TResponse(SynchronousCode.SlotInfo, res); | ||
var _temp19 = function () { | ||
if (cmd.name === 'transport info') { | ||
return Promise.resolve(_this.onTransportInfo(cmd)).then(function (res) { | ||
_exit13 = true; | ||
return { | ||
code: SynchronousCode.TransportInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1154,10 +995,10 @@ } | ||
return _temp17 && _temp17.then ? _temp17.then(_temp18) : _temp18(_temp17); | ||
return _temp19 && _temp19.then ? _temp19.then(_temp20) : _temp20(_temp19); | ||
} | ||
var _temp19 = function () { | ||
if (cmd.name === CommandNames.TransportInfoCommand) { | ||
return Promise.resolve(_this3.onTransportInfo(cmd)).then(function (res) { | ||
_exit13 = true; | ||
return new TResponse(SynchronousCode.TransportInfo, res); | ||
var _temp21 = function () { | ||
if (cmd.name === 'clips clear') { | ||
return Promise.resolve(_this.onClipsClear(cmd)).then(function () { | ||
_exit12 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1167,10 +1008,10 @@ } | ||
return _temp19 && _temp19.then ? _temp19.then(_temp20) : _temp20(_temp19); | ||
return _temp21 && _temp21.then ? _temp21.then(_temp22) : _temp22(_temp21); | ||
} | ||
var _temp21 = function () { | ||
if (cmd.name === CommandNames.ClipsClearCommand) { | ||
return Promise.resolve(_this3.onClipsClear(cmd)).then(function () { | ||
_exit12 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp23 = function () { | ||
if (cmd.name === 'clips add') { | ||
return Promise.resolve(_this.onClipsAdd(cmd)).then(function () { | ||
_exit11 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1180,10 +1021,13 @@ } | ||
return _temp21 && _temp21.then ? _temp21.then(_temp22) : _temp22(_temp21); | ||
return _temp23 && _temp23.then ? _temp23.then(_temp24) : _temp24(_temp23); | ||
} | ||
var _temp23 = function () { | ||
if (cmd.name === CommandNames.ClipsAddCommand) { | ||
return Promise.resolve(_this3.onClipsAdd(cmd)).then(function () { | ||
_exit11 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp25 = function () { | ||
if (cmd.name === 'clips get') { | ||
return Promise.resolve(_this.onClipsGet(cmd).then(formatClipsGetResponse)).then(function (res) { | ||
_exit10 = true; | ||
return { | ||
code: SynchronousCode.ClipsInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1193,10 +1037,13 @@ } | ||
return _temp23 && _temp23.then ? _temp23.then(_temp24) : _temp24(_temp23); | ||
return _temp25 && _temp25.then ? _temp25.then(_temp26) : _temp26(_temp25); | ||
} | ||
var _temp25 = function () { | ||
if (cmd.name === CommandNames.ClipsGetCommand) { | ||
return Promise.resolve(_this3.onClipsGet(cmd).then(formatClipsGetResponse)).then(function (res) { | ||
_exit10 = true; | ||
return new TResponse(SynchronousCode.ClipsInfo, res); | ||
var _temp27 = function () { | ||
if (cmd.name === 'clips count') { | ||
return Promise.resolve(_this.onClipsCount(cmd)).then(function (res) { | ||
_exit9 = true; | ||
return { | ||
code: SynchronousCode.ClipsCount, | ||
params: res | ||
}; | ||
}); | ||
@@ -1206,10 +1053,10 @@ } | ||
return _temp25 && _temp25.then ? _temp25.then(_temp26) : _temp26(_temp25); | ||
return _temp27 && _temp27.then ? _temp27.then(_temp28) : _temp28(_temp27); | ||
} | ||
var _temp27 = function () { | ||
if (cmd.name === CommandNames.ClipsCountCommand) { | ||
return Promise.resolve(_this3.onClipsCount(cmd)).then(function (res) { | ||
_exit9 = true; | ||
return new TResponse(SynchronousCode.ClipsCount, res); | ||
var _temp29 = function () { | ||
if (cmd.name === 'stop') { | ||
return Promise.resolve(_this.onStop(cmd)).then(function () { | ||
_exit8 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1219,10 +1066,10 @@ } | ||
return _temp27 && _temp27.then ? _temp27.then(_temp28) : _temp28(_temp27); | ||
return _temp29 && _temp29.then ? _temp29.then(_temp30) : _temp30(_temp29); | ||
} | ||
var _temp29 = function () { | ||
if (cmd.name === CommandNames.StopCommand) { | ||
return Promise.resolve(_this3.onStop(cmd)).then(function () { | ||
_exit8 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp31 = function () { | ||
if (cmd.name === 'record') { | ||
return Promise.resolve(_this.onRecord(cmd)).then(function () { | ||
_exit7 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1232,10 +1079,10 @@ } | ||
return _temp29 && _temp29.then ? _temp29.then(_temp30) : _temp30(_temp29); | ||
return _temp31 && _temp31.then ? _temp31.then(_temp32) : _temp32(_temp31); | ||
} | ||
var _temp31 = function () { | ||
if (cmd.name === CommandNames.RecordCommand) { | ||
return Promise.resolve(_this3.onRecord(cmd)).then(function () { | ||
_exit7 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp33 = function () { | ||
if (cmd.name === 'playrange clear') { | ||
return Promise.resolve(_this.onPlayrangeClear(cmd)).then(function () { | ||
_exit6 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1245,10 +1092,10 @@ } | ||
return _temp31 && _temp31.then ? _temp31.then(_temp32) : _temp32(_temp31); | ||
return _temp33 && _temp33.then ? _temp33.then(_temp34) : _temp34(_temp33); | ||
} | ||
var _temp33 = function () { | ||
if (cmd.name === CommandNames.PlayrangeClearCommand) { | ||
return Promise.resolve(_this3.onPlayrangeClear(cmd)).then(function () { | ||
_exit6 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp35 = function () { | ||
if (cmd.name === 'playrange set') { | ||
return Promise.resolve(_this.onPlayrangeSet(cmd)).then(function () { | ||
_exit5 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1258,10 +1105,10 @@ } | ||
return _temp33 && _temp33.then ? _temp33.then(_temp34) : _temp34(_temp33); | ||
return _temp35 && _temp35.then ? _temp35.then(_temp36) : _temp36(_temp35); | ||
} | ||
var _temp35 = function () { | ||
if (cmd.name === CommandNames.PlayrangeSetCommand) { | ||
return Promise.resolve(_this3.onPlayrangeSet(cmd)).then(function () { | ||
_exit5 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp37 = function () { | ||
if (cmd.name === 'play') { | ||
return Promise.resolve(_this.onPlay(cmd)).then(function () { | ||
_exit4 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1271,10 +1118,10 @@ } | ||
return _temp35 && _temp35.then ? _temp35.then(_temp36) : _temp36(_temp35); | ||
return _temp37 && _temp37.then ? _temp37.then(_temp38) : _temp38(_temp37); | ||
} | ||
var _temp37 = function () { | ||
if (cmd.name === CommandNames.PlayCommand) { | ||
return Promise.resolve(_this3.onPlay(cmd)).then(function () { | ||
_exit4 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp39 = function () { | ||
if (cmd.name === 'preview') { | ||
return Promise.resolve(_this.onPreview(cmd)).then(function () { | ||
_exit3 = true; | ||
return SynchronousCode.OK; | ||
}); | ||
@@ -1284,10 +1131,13 @@ } | ||
return _temp37 && _temp37.then ? _temp37.then(_temp38) : _temp38(_temp37); | ||
return _temp39 && _temp39.then ? _temp39.then(_temp40) : _temp40(_temp39); | ||
} | ||
var _temp39 = function () { | ||
if (cmd.name === CommandNames.PreviewCommand) { | ||
return Promise.resolve(_this3.onPreview(cmd)).then(function () { | ||
_exit3 = true; | ||
return new TResponse(SynchronousCode.OK); | ||
var _temp41 = function () { | ||
if (cmd.name === 'disk list') { | ||
return Promise.resolve(_this.onDiskList(cmd)).then(function (res) { | ||
_exit2 = true; | ||
return { | ||
code: SynchronousCode.DiskList, | ||
params: res | ||
}; | ||
}); | ||
@@ -1297,10 +1147,13 @@ } | ||
return _temp39 && _temp39.then ? _temp39.then(_temp40) : _temp40(_temp39); | ||
return _temp41 && _temp41.then ? _temp41.then(_temp42) : _temp42(_temp41); | ||
} | ||
var _temp41 = function () { | ||
if (cmd.name === CommandNames.DiskListCommand) { | ||
return Promise.resolve(_this3.onDiskList(cmd)).then(function (res) { | ||
_exit2 = true; | ||
return new TResponse(SynchronousCode.DiskList, res); | ||
var _temp43 = function () { | ||
if (cmd.name === 'device info') { | ||
return Promise.resolve(_this.onDeviceInfo(cmd)).then(function (res) { | ||
_exit = true; | ||
return { | ||
code: SynchronousCode.DeviceInfo, | ||
params: res | ||
}; | ||
}); | ||
@@ -1310,48 +1163,107 @@ } | ||
return _temp41 && _temp41.then ? _temp41.then(_temp42) : _temp42(_temp41); | ||
} | ||
return _temp43 && _temp43.then ? _temp43.then(_temp44) : _temp44(_temp43); | ||
}, function (err) { | ||
if (err instanceof UnimplementedError) { | ||
_this.logger.error({ | ||
cmd: cmd | ||
}, 'unimplemented'); | ||
var _temp43 = function () { | ||
if (cmd.name === CommandNames.DeviceInfoCommand) { | ||
return Promise.resolve(_this3.onDeviceInfo(cmd)).then(function (res) { | ||
_exit = true; | ||
return new TResponse(SynchronousCode.DeviceInfo, res); | ||
}); | ||
return ErrorCode.Unsupported; | ||
} | ||
}(); | ||
return _temp43 && _temp43.then ? _temp43.then(_temp44) : _temp44(_temp43); | ||
}, function (err) { | ||
if (err instanceof UnimplementedError) { | ||
_this3.logger.error({ | ||
cmd: cmd | ||
}, 'unimplemented'); | ||
_this.logger.error({ | ||
cmd: cmd, | ||
err: err.message | ||
}, 'unhandled command name'); | ||
return new TResponse(ErrorCode.Unsupported); | ||
} | ||
return ErrorCode.InternalError; | ||
}); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
if (err && typeof err.code === 'number' && ErrorCode[err.code] && err.msg) { | ||
_this3.logger.error({ | ||
err: err | ||
}, 'error with code'); | ||
this.logger = logger.child({ | ||
name: 'HyperDeck Emulator' | ||
}); | ||
this.server = createServer(function (socket) { | ||
_this2.logger.info('connection'); | ||
return new ErrorResponse(err.code, err.msg); | ||
} | ||
var socketId = Math.random().toString(35).substr(-6); | ||
_this3.logger.error({ | ||
cmd: cmd | ||
}, 'internal error'); | ||
var socketLogger = _this2.logger.child({ | ||
name: 'HyperDeck socket ' + socketId | ||
}); | ||
return new TResponse(ErrorCode.InternalError); | ||
}); | ||
_this2.sockets[socketId] = new HyperDeckSocket(socket, socketLogger, function (cmd) { | ||
return _this2.receivedCommand(cmd); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
_this2.sockets[socketId].on('disconnected', function () { | ||
socketLogger.info('disconnected'); | ||
delete _this2.sockets[socketId]; | ||
}); | ||
}); | ||
this.server.on('listening', function () { | ||
return _this2.logger.info('listening'); | ||
}); | ||
this.server.on('close', function () { | ||
return _this2.logger.info('connection closed'); | ||
}); | ||
this.server.on('error', function (err) { | ||
return _this2.logger.error('server error:', err); | ||
}); | ||
this.server.maxConnections = 1; | ||
this.server.listen(9993, ip); | ||
} | ||
var _proto = HyperDeckServer.prototype; | ||
_proto.close = function close() { | ||
this.server.unref(); | ||
}; | ||
_proto.notifySlot = function notifySlot(params) { | ||
this.notify('slot', params); | ||
}; | ||
_proto.notifyTransport = function notifyTransport(params) { | ||
this.notify('transport', params); | ||
}; | ||
_proto.notify = function notify(type, params) { | ||
for (var _i = 0, _Object$keys = Object.keys(this.sockets); _i < _Object$keys.length; _i++) { | ||
var id = _Object$keys[_i]; | ||
this.sockets[id].notify(type, params); | ||
} | ||
}; | ||
return HyperdeckServer; | ||
return HyperDeckServer; | ||
}(); | ||
export { AsynchronousCode, ErrorCode, FileFormats, HyperdeckServer, NotifyType, ResponseInterface, SlotStatus, SynchronousCode, Timecode, TransportStatus, VideoFormat }; | ||
var Timecode = function Timecode(hh, mm, ss, ff) { | ||
var 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(':'); | ||
this.toString = function () { | ||
return timecode; | ||
}; | ||
}; | ||
var ResponseInterface = { | ||
__proto__: null | ||
}; | ||
export { HyperDeckServer, ResponseInterface, Timecode }; | ||
//# sourceMappingURL=hyperdeck-emulator.esm.js.map |
@@ -1,3 +0,4 @@ | ||
export * from './server'; | ||
export { ResponseInterface, ErrorCode, AsynchronousCode, NotifyType, SynchronousCode, FileFormats, SlotStatus, VideoFormat, TransportStatus, Timecode } from './types'; | ||
export * from './HyperDeckServer'; | ||
export * from './Timecode'; | ||
export * as ResponseInterface from './types/ResponseInterface'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,8 +0,1 @@ | ||
import * as DeserializedCommands from './types/DeserializedCommands'; | ||
import * as ResponseInterface from './types/ResponseInterface'; | ||
export { DeserializedCommands, ResponseInterface }; | ||
export declare const CRLF = "\r\n"; | ||
export interface Hash<T> { | ||
[key: string]: T; | ||
} | ||
export interface NotificationConfig { | ||
@@ -14,21 +7,2 @@ transport: boolean; | ||
} | ||
/** @deprecated Misspelt, use `NotificationConfig` instead */ | ||
export declare type NotififcationConfig = NotificationConfig; | ||
export interface Buildable { | ||
build(): string; | ||
} | ||
export declare class TResponse<T extends Record<string, any> = Record<string, any>> implements Buildable { | ||
code: ResponseCode; | ||
params?: T | undefined; | ||
constructor(code: ResponseCode, params?: T | undefined); | ||
name: string; | ||
build: () => string; | ||
} | ||
export declare const formatClipsGetResponse: (res: ResponseInterface.ClipsGet) => Record<string, string | number>; | ||
export declare class ErrorResponse implements Buildable { | ||
code: ResponseCode; | ||
message: string; | ||
constructor(code: ResponseCode, message: string); | ||
build: () => string; | ||
} | ||
export interface DeserializedCommand { | ||
@@ -81,117 +55,52 @@ raw: string; | ||
} | ||
export declare enum NotifyType { | ||
Slot = 0, | ||
Transport = 1, | ||
Remote = 2, | ||
Configuration = 3 | ||
} | ||
export declare enum CommandNames { | ||
DeviceInfoCommand = "device info", | ||
DiskListCommand = "disk list", | ||
PreviewCommand = "preview", | ||
PlayCommand = "play", | ||
PlayrangeSetCommand = "playrange set", | ||
PlayrangeClearCommand = "playrange clear", | ||
RecordCommand = "record", | ||
StopCommand = "stop", | ||
ClipsCountCommand = "clips count", | ||
ClipsGetCommand = "clips get", | ||
ClipsAddCommand = "clips add", | ||
ClipsClearCommand = "clips clear", | ||
TransportInfoCommand = "transport info", | ||
SlotInfoCommand = "slot info", | ||
SlotSelectCommand = "slot select", | ||
NotifyCommand = "notify", | ||
GoToCommand = "goto", | ||
JogCommand = "jog", | ||
ShuttleCommand = "shuttle", | ||
RemoteCommand = "remote", | ||
ConfigurationCommand = "configuration", | ||
UptimeCommand = "uptime", | ||
FormatCommand = "format", | ||
IdentifyCommand = "identify", | ||
WatchdogCommand = "watchdog", | ||
PingCommand = "ping" | ||
} | ||
export declare type NotifyType = 'slot' | 'transport' | 'remote' | 'configuration'; | ||
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: { | ||
help: never[]; | ||
commands: never[]; | ||
'device info': never[]; | ||
'disk list': string[]; | ||
quit: never[]; | ||
ping: never[]; | ||
preview: string[]; | ||
play: string[]; | ||
'playrange set': string[]; | ||
'playrange clear': never[]; | ||
record: string[]; | ||
stop: never[]; | ||
'clips count': never[]; | ||
'clips get': string[]; | ||
'clips add': string[]; | ||
'clips clear': never[]; | ||
'transport info': never[]; | ||
'slot info': string[]; | ||
'slot select': string[]; | ||
notify: string[]; | ||
goto: string[]; | ||
jog: string[]; | ||
shuttle: string[]; | ||
remote: string[]; | ||
configuration: string[]; | ||
uptime: never[]; | ||
format: string[]; | ||
identify: string[]; | ||
watchdog: string[]; | ||
export declare const slotStatus: { | ||
empty: boolean; | ||
mounting: boolean; | ||
error: boolean; | ||
mounted: boolean; | ||
}; | ||
export declare type Response = Hash<string> | ResponseInterface.DeviceInfo | ResponseInterface.DiskList | ResponseInterface.ClipsCount | ResponseInterface.ClipsGet | ResponseInterface.TransportInfo | ResponseInterface.SlotInfo | ResponseInterface.Configuration | ResponseInterface.Uptime | ResponseInterface.Format; | ||
export declare enum SlotStatus { | ||
EMPTY = "empty", | ||
MOUNTING = "mounting", | ||
ERROR = "error", | ||
MOUNTED = "mounted" | ||
} | ||
export declare enum VideoFormat { | ||
NTSC = "NTSC", | ||
PAL = "PAL", | ||
NTSCp = "NTSCp", | ||
PALp = "PALp", | ||
_720p50 = "720p50", | ||
_720p5994 = "720p5994", | ||
_720p60 = "720p60", | ||
_1080p23976 = "1080p23976", | ||
_1080p24 = "1080p24", | ||
_1080p25 = "1080p25", | ||
_1080p2997 = "1080p2997", | ||
_1080p30 = "1080p30", | ||
_1080i50 = "1080i50", | ||
_1080i5994 = "1080i5994", | ||
_1080i60 = "1080i60", | ||
_4Kp23976 = "4Kp23976", | ||
_4Kp24 = "4Kp24", | ||
_4Kp25 = "4Kp25", | ||
_4Kp2997 = "4Kp2997", | ||
_4Kp30 = "4Kp30", | ||
_4Kp50 = "4Kp50", | ||
_4Kp5994 = "4Kp5994", | ||
_4Kp60 = "4Kp60" | ||
} | ||
export declare enum TransportStatus { | ||
PREVIEW = "preview", | ||
STOPPED = "stopped", | ||
PLAY = "play", | ||
FORWARD = "forward", | ||
REWIND = "rewind", | ||
JOG = "jog", | ||
SHUTTLE = "shuttle", | ||
RECORD = "record" | ||
} | ||
export declare enum FileFormats { | ||
export declare type SlotStatus = keyof typeof slotStatus; | ||
export declare const isSlotStatus: (value: any) => value is "empty" | "mounting" | "error" | "mounted"; | ||
export declare const videoFormats: { | ||
NTSC: boolean; | ||
PAL: boolean; | ||
NTSCp: boolean; | ||
PALp: boolean; | ||
'720p50': boolean; | ||
'720p5994': boolean; | ||
'720p60': boolean; | ||
'1080p23976': boolean; | ||
'1080p24': boolean; | ||
'1080p25': boolean; | ||
'1080p2997': boolean; | ||
'1080p30': boolean; | ||
'1080i50': boolean; | ||
'1080i5994': boolean; | ||
'1080i60': boolean; | ||
'4Kp23976': boolean; | ||
'4Kp24': boolean; | ||
'4Kp25': boolean; | ||
'4Kp2997': boolean; | ||
'4Kp30': boolean; | ||
'4Kp50': boolean; | ||
'4Kp5994': boolean; | ||
'4Kp60': boolean; | ||
}; | ||
export declare type VideoFormat = keyof typeof videoFormats; | ||
export declare const isVideoFormat: (value: any) => value is "NTSC" | "PAL" | "NTSCp" | "PALp" | "720p50" | "720p5994" | "720p60" | "1080p23976" | "1080p24" | "1080p25" | "1080p2997" | "1080p30" | "1080i50" | "1080i5994" | "1080i60" | "4Kp23976" | "4Kp24" | "4Kp25" | "4Kp2997" | "4Kp30" | "4Kp50" | "4Kp5994" | "4Kp60"; | ||
export declare const transportStatus: { | ||
preview: boolean; | ||
stopped: boolean; | ||
play: boolean; | ||
forward: boolean; | ||
rewind: boolean; | ||
jog: boolean; | ||
shuttle: boolean; | ||
record: boolean; | ||
}; | ||
export declare type TransportStatus = keyof typeof transportStatus; | ||
export declare const isTransportStatus: (value: any) => value is "preview" | "stopped" | "play" | "forward" | "rewind" | "jog" | "shuttle" | "record"; | ||
export declare enum FileFormat { | ||
QuickTimeUncompressed = "QuickTimeUncompressed", | ||
@@ -205,3 +114,3 @@ QuickTimeProResHQ = "QuickTimeProResHQ", | ||
} | ||
export declare enum AudioInputs { | ||
export declare enum AudioInput { | ||
embedded = "embedded", | ||
@@ -208,0 +117,0 @@ XLR = "XLR", |
@@ -1,2 +0,2 @@ | ||
import { DeserializedCommand } from '../types'; | ||
import type { DeserializedCommand } from '../types'; | ||
export interface PreviewCommand extends DeserializedCommand { | ||
@@ -3,0 +3,0 @@ parameters: { |
@@ -1,3 +0,3 @@ | ||
import { Hash, Timecode } from '../types'; | ||
import { TransportStatus, VideoFormat, SlotStatus, AudioInputs, VideoInputs, FileFormats } from '../types'; | ||
import type { Timecode } from '../Timecode'; | ||
import type { TransportStatus, VideoFormat, SlotStatus, AudioInput, VideoInputs, FileFormat } from '../types'; | ||
export interface DeviceInfo { | ||
@@ -8,3 +8,3 @@ 'protocol version': string; | ||
} | ||
export interface DiskList extends Hash<string> { | ||
export interface DiskList extends Record<string, string> { | ||
'slot id': string; | ||
@@ -49,5 +49,5 @@ } | ||
export interface Configuration { | ||
'audio input': AudioInputs; | ||
'audio input': AudioInput; | ||
'video input': VideoInputs; | ||
'file format': FileFormats; | ||
'file format': FileFormat; | ||
} | ||
@@ -54,0 +54,0 @@ export interface Uptime { |
{ | ||
"name": "@meyer/hyperdeck-emulator", | ||
"version": "0.0.4-canary.25.5372bb6", | ||
"version": "0.0.4-canary.28.6476ee1", | ||
"description": "Typescript Node.js library for emulating a Blackmagic Hyperdeck", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -39,2 +39,8 @@ import packlist = require('npm-packlist') | ||
- README.md | ||
- dist/__tests__/utils.d.ts | ||
- dist/__tests__/utils.d.ts.map | ||
- dist/constants.d.ts | ||
- dist/constants.d.ts.map | ||
- dist/formatClipsGetResponse.d.ts | ||
- dist/formatClipsGetResponse.d.ts.map | ||
- dist/hyperdeck-emulator.cjs.development.js | ||
@@ -46,2 +52,6 @@ - dist/hyperdeck-emulator.cjs.development.js.map | ||
- dist/hyperdeck-emulator.esm.js.map | ||
- dist/HyperDeckServer.d.ts | ||
- dist/HyperDeckServer.d.ts.map | ||
- dist/HyperDeckSocket.d.ts | ||
- dist/HyperDeckSocket.d.ts.map | ||
- dist/index.d.ts | ||
@@ -52,8 +62,8 @@ - dist/index.d.ts.map | ||
- dist/invariant.d.ts.map | ||
- dist/parser.d.ts | ||
- dist/parser.d.ts.map | ||
- dist/server.d.ts | ||
- dist/server.d.ts.map | ||
- dist/socket.d.ts | ||
- dist/socket.d.ts.map | ||
- dist/messageForCode.d.ts | ||
- dist/messageForCode.d.ts.map | ||
- dist/MultilineParser.d.ts | ||
- dist/MultilineParser.d.ts.map | ||
- dist/Timecode.d.ts | ||
- dist/Timecode.d.ts.map | ||
- dist/types.d.ts | ||
@@ -65,9 +75,16 @@ - dist/types.d.ts.map | ||
- dist/types/ResponseInterface.d.ts.map | ||
- src/__tests__/HyperDeckServer.spec.ts | ||
- src/__tests__/messageForCode.spec.ts | ||
- src/__tests__/meta.spec.ts | ||
- src/__tests__/server.spec.ts | ||
- src/__tests__/MultilineParser.spec.ts | ||
- src/__tests__/utils.ts | ||
- src/constants.ts | ||
- src/formatClipsGetResponse.ts | ||
- src/HyperDeckServer.ts | ||
- src/HyperDeckSocket.ts | ||
- src/index.ts | ||
- src/invariant.ts | ||
- src/parser.ts | ||
- src/server.ts | ||
- src/socket.ts | ||
- src/messageForCode.ts | ||
- src/MultilineParser.ts | ||
- src/Timecode.ts | ||
- src/types.ts | ||
@@ -74,0 +91,0 @@ - src/types/DeserializedCommands.ts |
@@ -1,14 +0,3 @@ | ||
export * from './server' | ||
export { | ||
ResponseInterface, | ||
ErrorCode, | ||
AsynchronousCode, | ||
NotifyType, | ||
SynchronousCode, | ||
FileFormats, | ||
SlotStatus, | ||
VideoFormat, | ||
TransportStatus, | ||
Timecode | ||
} from './types' | ||
export * from './HyperDeckServer' | ||
export * from './Timecode' | ||
export * as ResponseInterface from './types/ResponseInterface' |
299
src/types.ts
@@ -1,12 +0,1 @@ | ||
import * as DeserializedCommands from './types/DeserializedCommands' | ||
import * as ResponseInterface from './types/ResponseInterface' | ||
import { invariant } from './invariant' | ||
export { DeserializedCommands, ResponseInterface } | ||
export const CRLF = '\r\n' | ||
export interface Hash<T> { | ||
[key: string]: T | ||
} | ||
export interface NotificationConfig { | ||
@@ -19,46 +8,2 @@ transport: boolean | ||
/** @deprecated Misspelt, use `NotificationConfig` instead */ | ||
export type NotififcationConfig = NotificationConfig | ||
export interface Buildable { | ||
build(): string | ||
} | ||
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] | ||
} | ||
public name: string | ||
public build = (): string => messageForCode(this.code, this.params) | ||
} | ||
export const formatClipsGetResponse = ( | ||
res: ResponseInterface.ClipsGet | ||
): Record<string, string | number> => { | ||
const clipsCount = res.clips.length | ||
const response: Record<string, string | number> = { | ||
clipsCount | ||
} | ||
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) { | ||
invariant(responseNamesByCode.hasOwnProperty(code), 'Invalid code: `%o`', code) | ||
} | ||
public build = (): string => this.code + ' ' + this.message + CRLF | ||
} | ||
export interface DeserializedCommand { | ||
@@ -116,38 +61,4 @@ raw: string | ||
export enum NotifyType { | ||
Slot, | ||
Transport, | ||
Remote, | ||
Configuration | ||
} | ||
export type NotifyType = 'slot' | 'transport' | 'remote' | 'configuration' | ||
export enum CommandNames { | ||
DeviceInfoCommand = 'device info', | ||
DiskListCommand = 'disk list', | ||
PreviewCommand = 'preview', | ||
PlayCommand = 'play', | ||
PlayrangeSetCommand = 'playrange set', | ||
PlayrangeClearCommand = 'playrange clear', | ||
RecordCommand = 'record', | ||
StopCommand = 'stop', | ||
ClipsCountCommand = 'clips count', | ||
ClipsGetCommand = 'clips get', | ||
ClipsAddCommand = 'clips add', | ||
ClipsClearCommand = 'clips clear', | ||
TransportInfoCommand = 'transport info', | ||
SlotInfoCommand = 'slot info', | ||
SlotSelectCommand = 'slot select', | ||
NotifyCommand = 'notify', | ||
GoToCommand = 'goto', | ||
JogCommand = 'jog', | ||
ShuttleCommand = 'shuttle', | ||
RemoteCommand = 'remote', | ||
ConfigurationCommand = 'configuration', | ||
UptimeCommand = 'uptime', | ||
FormatCommand = 'format', | ||
IdentifyCommand = 'identify', | ||
WatchdogCommand = 'watchdog', | ||
PingCommand = 'ping' | ||
} | ||
export const responseNamesByCode: Record<ResponseCode, string> = { | ||
@@ -157,4 +68,4 @@ [AsynchronousCode.ConfigurationInfo]: 'configuration info', | ||
[AsynchronousCode.RemoteInfo]: 'remote info', | ||
[AsynchronousCode.SlotInfo]: CommandNames.SlotInfoCommand, | ||
[AsynchronousCode.TransportInfo]: CommandNames.TransportInfoCommand, | ||
[AsynchronousCode.SlotInfo]: 'slot info', | ||
[AsynchronousCode.TransportInfo]: 'transport info', | ||
[ErrorCode.ConnectionRejected]: 'connection rejected', | ||
@@ -178,165 +89,79 @@ [ErrorCode.DiskError]: 'disk error', | ||
[ErrorCode.UnsupportedParameter]: 'unsupported parameter', | ||
[SynchronousCode.ClipsCount]: CommandNames.ClipsCountCommand, | ||
[SynchronousCode.ClipsCount]: 'clips count', | ||
[SynchronousCode.ClipsInfo]: 'clips info', | ||
[SynchronousCode.Configuration]: CommandNames.ConfigurationCommand, | ||
[SynchronousCode.DeviceInfo]: CommandNames.DeviceInfoCommand, | ||
[SynchronousCode.DiskList]: CommandNames.DiskListCommand, | ||
[SynchronousCode.Configuration]: 'configuration', | ||
[SynchronousCode.DeviceInfo]: 'device info', | ||
[SynchronousCode.DiskList]: 'disk list', | ||
[SynchronousCode.FormatReady]: 'format ready', | ||
[SynchronousCode.Notify]: CommandNames.NotifyCommand, | ||
[SynchronousCode.Notify]: 'notify', | ||
[SynchronousCode.OK]: 'ok', | ||
[SynchronousCode.Remote]: CommandNames.RemoteCommand, | ||
[SynchronousCode.SlotInfo]: CommandNames.SlotInfoCommand, | ||
[SynchronousCode.TransportInfo]: CommandNames.TransportInfoCommand, | ||
[SynchronousCode.Uptime]: CommandNames.UptimeCommand | ||
[SynchronousCode.Remote]: 'remote', | ||
[SynchronousCode.SlotInfo]: 'slot info', | ||
[SynchronousCode.TransportInfo]: 'transport info', | ||
[SynchronousCode.Uptime]: 'uptime' | ||
} | ||
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 slotStatus = { | ||
empty: true, | ||
mounting: true, | ||
error: true, | ||
mounted: true | ||
} | ||
export const messageForCode = (code: ResponseCode, params?: Record<string, unknown>): string => { | ||
const firstLine = `${code} ${responseNamesByCode[code]}` | ||
export type SlotStatus = keyof typeof slotStatus | ||
// 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 isSlotStatus = (value: any): value is SlotStatus => { | ||
return typeof value === 'string' && slotStatus.hasOwnProperty(value) | ||
} | ||
export const ParameterMap = { | ||
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'] | ||
export const videoFormats = { | ||
NTSC: true, | ||
PAL: true, | ||
NTSCp: true, | ||
PALp: true, | ||
'720p50': true, | ||
'720p5994': true, | ||
'720p60': true, | ||
'1080p23976': true, | ||
'1080p24': true, | ||
'1080p25': true, | ||
'1080p2997': true, | ||
'1080p30': true, | ||
'1080i50': true, | ||
'1080i5994': true, | ||
'1080i60': true, | ||
'4Kp23976': true, | ||
'4Kp24': true, | ||
'4Kp25': true, | ||
'4Kp2997': true, | ||
'4Kp30': true, | ||
'4Kp50': true, | ||
'4Kp5994': true, | ||
'4Kp60': true | ||
} | ||
export type Response = | ||
| Hash<string> | ||
| ResponseInterface.DeviceInfo | ||
| ResponseInterface.DiskList | ||
| ResponseInterface.ClipsCount | ||
| ResponseInterface.ClipsGet | ||
| ResponseInterface.TransportInfo | ||
| ResponseInterface.SlotInfo | ||
| ResponseInterface.Configuration | ||
| ResponseInterface.Uptime | ||
| ResponseInterface.Format | ||
export type VideoFormat = keyof typeof videoFormats | ||
export enum SlotStatus { | ||
EMPTY = 'empty', | ||
MOUNTING = 'mounting', | ||
ERROR = 'error', | ||
MOUNTED = 'mounted' | ||
export const isVideoFormat = (value: any): value is VideoFormat => { | ||
return typeof value === 'string' && videoFormats.hasOwnProperty(value) | ||
} | ||
export enum VideoFormat { | ||
NTSC = 'NTSC', | ||
PAL = 'PAL', | ||
NTSCp = 'NTSCp', | ||
PALp = 'PALp', | ||
_720p50 = '720p50', | ||
_720p5994 = '720p5994', | ||
_720p60 = '720p60', | ||
_1080p23976 = '1080p23976', | ||
_1080p24 = '1080p24', | ||
_1080p25 = '1080p25', | ||
_1080p2997 = '1080p2997', | ||
_1080p30 = '1080p30', | ||
_1080i50 = '1080i50', | ||
_1080i5994 = '1080i5994', | ||
_1080i60 = '1080i60', | ||
_4Kp23976 = '4Kp23976', | ||
_4Kp24 = '4Kp24', | ||
_4Kp25 = '4Kp25', | ||
_4Kp2997 = '4Kp2997', | ||
_4Kp30 = '4Kp30', | ||
_4Kp50 = '4Kp50', | ||
_4Kp5994 = '4Kp5994', | ||
_4Kp60 = '4Kp60' | ||
export const transportStatus = { | ||
preview: true, | ||
stopped: true, | ||
play: true, | ||
forward: true, | ||
rewind: true, | ||
jog: true, | ||
shuttle: true, | ||
record: true | ||
} | ||
export enum TransportStatus { | ||
PREVIEW = 'preview', | ||
STOPPED = 'stopped', | ||
PLAY = 'play', | ||
FORWARD = 'forward', | ||
REWIND = 'rewind', | ||
JOG = 'jog', | ||
SHUTTLE = 'shuttle', | ||
RECORD = 'record' | ||
export type TransportStatus = keyof typeof transportStatus | ||
export const isTransportStatus = (value: any): value is TransportStatus => { | ||
return typeof value === 'string' && transportStatus.hasOwnProperty(value) | ||
} | ||
export enum FileFormats { | ||
export enum FileFormat { | ||
QuickTimeUncompressed = 'QuickTimeUncompressed', | ||
@@ -351,3 +176,3 @@ QuickTimeProResHQ = 'QuickTimeProResHQ', | ||
export enum AudioInputs { | ||
export enum AudioInput { | ||
embedded = 'embedded', | ||
@@ -354,0 +179,0 @@ XLR = 'XLR', |
@@ -1,2 +0,2 @@ | ||
import { DeserializedCommand } from '../types' | ||
import type { DeserializedCommand } from '../types' | ||
@@ -3,0 +3,0 @@ export interface PreviewCommand extends DeserializedCommand { |
@@ -1,9 +0,9 @@ | ||
import { Hash, Timecode } from '../types' | ||
import { | ||
import type { Timecode } from '../Timecode' | ||
import type { | ||
TransportStatus, | ||
VideoFormat, | ||
SlotStatus, | ||
AudioInputs, | ||
AudioInput, | ||
VideoInputs, | ||
FileFormats | ||
FileFormat | ||
} from '../types' | ||
@@ -17,3 +17,3 @@ | ||
export interface DiskList extends Hash<string> { | ||
export interface DiskList extends Record<string, string> { | ||
'slot id': string | ||
@@ -65,5 +65,5 @@ } | ||
export interface Configuration { | ||
'audio input': AudioInputs | ||
'audio input': AudioInput | ||
'video input': VideoInputs | ||
'file format': FileFormats | ||
'file format': FileFormat | ||
} | ||
@@ -70,0 +70,0 @@ |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54
3861
2
400737
4