videomail-client 9.2.1 → 9.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,7 @@
11
11
  ],
12
12
  "cSpell.words": [
13
13
  "animitter",
14
+ "autobuffer",
14
15
  "bytediff",
15
16
  "classlist",
16
17
  "cssnano",
@@ -23,6 +24,7 @@
23
24
  "keymirror",
24
25
  "Mbit",
25
26
  "packagejson",
27
+ "playsinline",
26
28
  "plusplus",
27
29
  "preend",
28
30
  "rubberband",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "videomail-client",
3
- "version": "9.2.1",
3
+ "version": "9.2.3",
4
4
  "description": "A wicked npm package to record videos directly in the browser, wohooo!",
5
5
  "keywords": [
6
6
  "webcam",
@@ -112,7 +112,7 @@
112
112
  "prettier": "3.3.3",
113
113
  "prettier-plugin-curly": "0.2.2",
114
114
  "prettier-plugin-organize-imports": "4.0.0",
115
- "prettier-plugin-packagejson": "2.5.1",
115
+ "prettier-plugin-packagejson": "2.5.2",
116
116
  "prettier-plugin-sh": "0.14.0",
117
117
  "router": "1.3.8",
118
118
  "tape": "5.8.1",
@@ -0,0 +1,23 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>videomail-client examples</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1" />
6
+ </head>
7
+ <body>
8
+ <h1>Attempt to get a snapshot of a non-existing videomail</h1>
9
+ <p>This is how error responses are processed:</p>
10
+ <div id="videomail"></div>
11
+ <pre><code id="error"></code></pre>
12
+ <script src="/js/videomail-client.js"></script>
13
+ <script>
14
+ var videomailClient = new VideomailClient.default();
15
+
16
+ // This showcases how the packError fn works
17
+ videomailClient.get("i do not exist", function (err, videomail) {
18
+ var errorEl = document.getElementById("error");
19
+ errorEl.innerHTML = JSON.stringify(err, null, 4);
20
+ });
21
+ </script>
22
+ </body>
23
+ </html>
@@ -499,6 +499,12 @@
499
499
  ><span class="size">2710</span><span class="date">2019-9-13 11:11:53</span></a
500
500
  >
501
501
  </li>
502
+ <li>
503
+ <a href="/error_handling.html" class="" title="error_handling.html"
504
+ ><span class="name">error_handling.html</span><span class="size">???</span
505
+ ><span class="date">???</span></a
506
+ >
507
+ </li>
502
508
  </ul>
503
509
  </div>
504
510
  </body>
@@ -17267,7 +17267,7 @@ function wrappy (fn, cb) {
17267
17267
  },{}],116:[function(_dereq_,module,exports){
17268
17268
  module.exports={
17269
17269
  "name": "videomail-client",
17270
- "version": "9.2.1",
17270
+ "version": "9.2.3",
17271
17271
  "description": "A wicked npm package to record videos directly in the browser, wohooo!",
17272
17272
  "keywords": [
17273
17273
  "webcam",
@@ -17379,7 +17379,7 @@ module.exports={
17379
17379
  "prettier": "3.3.3",
17380
17380
  "prettier-plugin-curly": "0.2.2",
17381
17381
  "prettier-plugin-organize-imports": "4.0.0",
17382
- "prettier-plugin-packagejson": "2.5.1",
17382
+ "prettier-plugin-packagejson": "2.5.2",
17383
17383
  "prettier-plugin-sh": "0.14.0",
17384
17384
  "router": "1.3.8",
17385
17385
  "tape": "5.8.1",
@@ -17415,7 +17415,6 @@ var _collectLogger = _interopRequireDefault(_dereq_("./util/collectLogger"));
17415
17415
  var _eventEmitter = _interopRequireDefault(_dereq_("./util/eventEmitter"));
17416
17416
  var _container = _interopRequireDefault(_dereq_("./wrappers/container"));
17417
17417
  var _optionsWrapper = _interopRequireDefault(_dereq_("./wrappers/optionsWrapper"));
17418
- var _replay = _interopRequireDefault(_dereq_("./wrappers/visuals/replay"));
17419
17418
  var collectLogger;
17420
17419
  var browser;
17421
17420
  function adjustOptions() {
@@ -17441,7 +17440,6 @@ var VideomailClient = function VideomailClient(options) {
17441
17440
  var localOptions = adjustOptions(options);
17442
17441
  var container = new _container.default(localOptions);
17443
17442
  var debug = localOptions.debug;
17444
- var replay;
17445
17443
  this.events = _events.default;
17446
17444
  _eventEmitter.default.call(this, localOptions, "VideomailClient");
17447
17445
  this.build = function () {
@@ -17466,47 +17464,31 @@ var VideomailClient = function VideomailClient(options) {
17466
17464
  };
17467
17465
 
17468
17466
  /*
17469
- * automatically adds a <video> element inside the given parentElement and loads
17470
- * it with the videomail
17467
+ * Automatically adds a <video> element inside the given parentElement and
17468
+ * loads it with the videomail
17471
17469
  */
17472
- this.replay = function (videomail, parentElement) {
17473
- function buildReplay() {
17474
- if (typeof parentElement === "string") {
17475
- parentElement = document.getElementById(parentElement);
17476
- }
17477
- if (!parentElement) {
17478
- if (!container.isBuilt()) {
17479
- // this will try build all over again
17480
- container.build(true);
17481
- }
17482
- if (!container.hasElement()) {
17483
- throw new Error("Unable to replay video without a container nor parent element.");
17484
- }
17485
- } else if (container.isOutsideElementOf(parentElement)) {
17486
- replay = new _replay.default(parentElement, localOptions);
17487
- replay.build();
17488
- }
17489
- if (!replay) {
17490
- replay = container.getReplay();
17491
- }
17492
- if (!parentElement) {
17493
- parentElement = replay.getParentElement();
17494
- }
17495
- if (videomail) {
17496
- videomail = container.addPlayerDimensions(videomail, parentElement);
17497
- }
17498
- container.buildForm(videomail);
17499
- container.loadForm(videomail);
17500
-
17501
- // slight delay needed to avoid HTTP 416 errors (request range unavailable)
17502
- setTimeout(function () {
17503
- replay.setVideomail(videomail);
17504
- container.showReplayOnly();
17505
- }, 10e1); // not sure, but probably can be reduced a bit
17470
+ this.replay = function (videomail, replayParentElement) {
17471
+ if (!container.isBuilt()) {
17472
+ container.build(true, replayParentElement);
17473
+ }
17474
+ if (!container.hasElement()) {
17475
+ throw new Error("Unable to replay video without a container nor parent element.");
17476
+ }
17477
+ if (videomail) {
17478
+ videomail = container.addPlayerDimensions(videomail);
17506
17479
  }
17507
- buildReplay();
17480
+ container.buildForm();
17481
+ container.loadForm(videomail);
17482
+
17483
+ // slight delay needed to avoid HTTP 416 errors (request range unavailable)
17484
+ setTimeout(function () {
17485
+ var replay = container.getReplay();
17486
+ replay.setVideomail(videomail);
17487
+ container.showReplayOnly();
17488
+ }, 50); // not sure, but probably can be reduced a bit
17508
17489
  };
17509
17490
  this.startOver = function (params) {
17491
+ var replay = container.getReplay();
17510
17492
  if (replay) {
17511
17493
  replay.hide();
17512
17494
  replay.reset();
@@ -17574,7 +17556,7 @@ Object.keys(_constants.default.public).forEach(function (name) {
17574
17556
  VideomailClient.Events = _events.default;
17575
17557
  var _default = exports.default = VideomailClient;
17576
17558
 
17577
- },{"./constants":118,"./events":119,"./options":120,"./resource":121,"./util/browser":123,"./util/collectLogger":124,"./util/eventEmitter":125,"./wrappers/container":132,"./wrappers/optionsWrapper":135,"./wrappers/visuals/replay":145,"@babel/runtime/helpers/interopRequireDefault":4,"deepmerge":28,"inherits":66}],118:[function(_dereq_,module,exports){
17559
+ },{"./constants":118,"./events":119,"./options":120,"./resource":121,"./util/browser":123,"./util/collectLogger":124,"./util/eventEmitter":125,"./wrappers/container":132,"./wrappers/optionsWrapper":135,"@babel/runtime/helpers/interopRequireDefault":4,"deepmerge":28,"inherits":66}],118:[function(_dereq_,module,exports){
17578
17560
  "use strict";
17579
17561
 
17580
17562
  Object.defineProperty(exports, "__esModule", {
@@ -17922,23 +17904,37 @@ function _default(options) {
17922
17904
  }
17923
17905
  return videomail;
17924
17906
  }
17907
+ function setProperty(packedError, property, value) {
17908
+ Object.defineProperty(packedError, property, {
17909
+ value: value,
17910
+ enumerable: true,
17911
+ configurable: true,
17912
+ writable: true
17913
+ });
17914
+ }
17925
17915
  function packError(err, res) {
17926
17916
  if (res && res.body && res.body.error) {
17927
- // use the server generated text instead of the superagent's default text
17928
- err = res.body.error;
17929
- if (!err.message && res.text) {
17930
- err.message = res.text;
17931
- }
17917
+ var originalError = res.body.error;
17918
+ var packedError = new Error();
17919
+ setProperty(packedError, "name", originalError.name);
17920
+ setProperty(packedError, "message", originalError.message || res.statusText);
17921
+ setProperty(packedError, "cause", originalError.cause);
17922
+ setProperty(packedError, "status", originalError.status);
17923
+ setProperty(packedError, "code", originalError.code);
17924
+ setProperty(packedError, "errno", originalError.errno);
17925
+ setProperty(packedError, "details", originalError.details);
17926
+ setProperty(packedError, "stack", originalError.stack);
17927
+ return packedError;
17932
17928
  }
17933
17929
  return err;
17934
17930
  }
17935
17931
  function fetch(identifierName, identifierValue, cb) {
17936
17932
  var url = "".concat(options.baseUrl, "/videomail/").concat(identifierName, "/").concat(identifierValue, "/snapshot");
17937
17933
  var request = (0, _superagent.default)("get", url);
17938
- request.set("Accept", "application/json").set("Timezone-Id", timezoneId).set(_constants.default.SITE_NAME_LABEL, options.siteName).timeout(options.timeouts.connection).end(function (err, res) {
17939
- err = packError(err, res);
17934
+ request.type("json").set("Accept", "application/json").set("Timezone-Id", timezoneId).set(_constants.default.SITE_NAME_LABEL, options.siteName).timeout(options.timeouts.connection).end(function (err, res) {
17940
17935
  if (err) {
17941
- cb(err);
17936
+ var prettyError = packError(err, res);
17937
+ cb(prettyError);
17942
17938
  } else {
17943
17939
  var videomail = res.body ? res.body : null;
17944
17940
  cb(null, videomail);
@@ -17958,9 +17954,9 @@ function _default(options) {
17958
17954
  var request = (0, _superagent.default)(method, url);
17959
17955
  queryParams[_constants.default.SITE_NAME_LABEL] = options.siteName;
17960
17956
  request.query(queryParams).set("Timezone-Id", timezoneId).send(videomail).timeout(options.timeout).end(function (err, res) {
17961
- err = packError(err, res);
17962
17957
  if (err) {
17963
- cb(err);
17958
+ var prettyError = packError(err, res);
17959
+ cb(prettyError);
17964
17960
  } else {
17965
17961
  var returnedVideomail = res.body && res.body.videomail ? res.body.videomail : null;
17966
17962
  cb(null, returnedVideomail, res.body);
@@ -17979,9 +17975,9 @@ function _default(options) {
17979
17975
  var request = (0, _superagent.default)("post", url);
17980
17976
  queryParams[_constants.default.SITE_NAME_LABEL] = options.siteName;
17981
17977
  request.query(queryParams).send(err).timeout(options.timeout).end(function (err, res) {
17982
- err = packError(err, res);
17983
17978
  if (err) {
17984
- cb && cb(err);
17979
+ var prettyError = packError(err, res);
17980
+ cb && cb(prettyError);
17985
17981
  } else {
17986
17982
  cb && cb();
17987
17983
  }
@@ -18027,9 +18023,9 @@ function _default(options) {
18027
18023
  }
18028
18024
  if (formType) {
18029
18025
  _superagent.default.post(url).type(formType).set("Timezone-Id", timezoneId).send(formData).timeout(options.timeout).end(function (err, res) {
18030
- err = packError(err, res);
18031
18026
  if (err) {
18032
- cb(err);
18027
+ var prettyError = packError(err, res);
18028
+ cb(prettyError);
18033
18029
  } else {
18034
18030
  cb(null, res);
18035
18031
  }
@@ -19752,6 +19748,7 @@ var Container = function Container(options) {
19752
19748
  var containerElement;
19753
19749
  var built;
19754
19750
  var form;
19751
+ validateOptions();
19755
19752
  function prependDefaultCss() {
19756
19753
  (0, _insertCss.default)(_mainMinCss.default, {
19757
19754
  prepend: true
@@ -19779,7 +19776,6 @@ var Container = function Container(options) {
19779
19776
  }
19780
19777
  var formElement = getFormElement();
19781
19778
  if (formElement) {
19782
- debug("Container: buildForm()");
19783
19779
  form = new _form.default(self, formElement, options);
19784
19780
  var submitButton = form.findSubmitButton();
19785
19781
  if (submitButton) {
@@ -19790,7 +19786,8 @@ var Container = function Container(options) {
19790
19786
  };
19791
19787
  function buildChildren() {
19792
19788
  var playerOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
19793
- debug("Container: buildChildren (playerOnly = ".concat(playerOnly, ")"));
19789
+ var replayParentElement = arguments.length > 1 ? arguments[1] : undefined;
19790
+ debug("Container: buildChildren (playerOnly = ".concat(playerOnly).concat(replayParentElement ? ", replayParentElement=\"".concat(replayParentElement, "\"") : "", ")"));
19794
19791
  if (!containerElement.classList) {
19795
19792
  self.emit(_events.default.ERROR, _videomailError.default.create("Sorry, your browser is too old!", options));
19796
19793
  } else {
@@ -19798,7 +19795,7 @@ var Container = function Container(options) {
19798
19795
  if (!playerOnly) {
19799
19796
  buttons.build();
19800
19797
  }
19801
- visuals.build(playerOnly);
19798
+ visuals.build(playerOnly, replayParentElement);
19802
19799
  }
19803
19800
  }
19804
19801
  function processError(err) {
@@ -19889,7 +19886,7 @@ var Container = function Container(options) {
19889
19886
  }
19890
19887
 
19891
19888
  /*
19892
- * this will just set the width but not the height because
19889
+ * This will just set the width but not the height because
19893
19890
  * it can be a form with more inputs elements
19894
19891
  */
19895
19892
  function correctDimensions() {
@@ -19987,13 +19984,18 @@ var Container = function Container(options) {
19987
19984
  }
19988
19985
  }
19989
19986
  }
19990
- this.addPlayerDimensions = function (videomail, element) {
19987
+ this.addPlayerDimensions = function (videomail) {
19991
19988
  try {
19989
+ if (!videomail) {
19990
+ throw new Error("Videomail data is missing for attaching player dimensions");
19991
+ }
19992
+ var replay = self.getReplay();
19993
+ var replayParentElement = replay.getParentElement();
19992
19994
  videomail.playerHeight = self.calculateHeight({
19993
19995
  responsive: true,
19994
19996
  videoWidth: videomail.width,
19995
19997
  ratio: videomail.height / videomail.width
19996
- }, element);
19998
+ }, replayParentElement);
19997
19999
  videomail.playerWidth = self.calculateWidth({
19998
20000
  responsive: true,
19999
20001
  videoHeight: videomail.playerHeight,
@@ -20032,24 +20034,24 @@ var Container = function Container(options) {
20032
20034
  };
20033
20035
  this.build = function () {
20034
20036
  var playerOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20035
- debug("Container: build (playerOnly = ".concat(playerOnly, ")"));
20037
+ var replayParentElement = arguments.length > 1 ? arguments[1] : undefined;
20038
+ debug("Container: build (playerOnly = ".concat(playerOnly).concat(replayParentElement ? ", replayParentElement=\"".concat(replayParentElement, "\"") : "", ")"));
20036
20039
  try {
20037
20040
  containerElement = document.getElementById(options.selectors.containerId);
20038
20041
 
20039
20042
  /*
20040
- * only build when a container element hast been found, otherwise
20041
- * be silent and do nothing
20043
+ * Only build when a container element hast been found,
20044
+ * otherwise be silent and do nothing
20042
20045
  */
20043
20046
  if (containerElement) {
20044
20047
  options.insertCss && prependDefaultCss();
20045
20048
  !built && initEvents(playerOnly);
20046
- validateOptions();
20047
20049
  correctDimensions();
20048
20050
 
20049
20051
  // Building form also applies for when `playerOnly` because of
20050
20052
  // correcting mode on Videomail. This function will skip if there is no form. Easy.
20051
20053
  self.buildForm();
20052
- buildChildren(playerOnly);
20054
+ buildChildren(playerOnly, replayParentElement);
20053
20055
  if (!hasError) {
20054
20056
  debug("Container: built.");
20055
20057
  built = true;
@@ -20059,16 +20061,12 @@ var Container = function Container(options) {
20059
20061
  }
20060
20062
  } else {
20061
20063
  /*
20062
- * commented out since it does too much noise on videomail's view page which is fine
20064
+ * Commented out since it does too much noise on videomail's view page which is fine
20063
20065
  * debug('Container: no container element with ID ' + options.selectors.containerId + ' found. Do nothing.')
20064
20066
  */
20065
20067
  }
20066
20068
  } catch (exc) {
20067
- if (visuals.isNotifierBuilt()) {
20068
- self.emit(_events.default.ERROR, exc);
20069
- } else {
20070
- throw exc;
20071
- }
20069
+ self.emit(_events.default.ERROR, exc);
20072
20070
  }
20073
20071
  };
20074
20072
  this.getSubmitButton = function () {
@@ -20206,9 +20204,6 @@ var Container = function Container(options) {
20206
20204
  }
20207
20205
  if (!valid) {
20208
20206
  whyInvalid = "Don't forget to record a video 😉";
20209
- invalidData = {
20210
- key: undefined
20211
- };
20212
20207
  }
20213
20208
  }
20214
20209
  } else {
@@ -20272,8 +20267,10 @@ var Container = function Container(options) {
20272
20267
  }
20273
20268
  if (valid) {
20274
20269
  self.emit(_events.default.VALID);
20275
- } else {
20270
+ } else if (invalidData) {
20276
20271
  self.emit(_events.default.INVALID, whyInvalid, invalidData);
20272
+ } else {
20273
+ self.emit(_events.default.INVALID, whyInvalid);
20277
20274
  }
20278
20275
  lastValidation = valid;
20279
20276
  }
@@ -20298,7 +20295,7 @@ var Container = function Container(options) {
20298
20295
  return method && method.toUpperCase() === "PUT";
20299
20296
  }
20300
20297
  this.submitAll = function (formData, method, url) {
20301
- debug("Container: submitAll(".concat(method, ": ").concat(url, ")"));
20298
+ debug("Container: submitAll(".concat(method, ": \"").concat(url, "\")"));
20302
20299
  var post = isPost(method);
20303
20300
  var hasVideomailKey = Boolean(formData[options.selectors.keyInputName]);
20304
20301
  function startSubmission() {
@@ -20917,13 +20914,14 @@ var Visuals = function Visuals(container, options) {
20917
20914
  }
20918
20915
  function buildChildren() {
20919
20916
  var playerOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20920
- debug("Visuals: buildChildren (playerOnly = ".concat(playerOnly, ")"));
20917
+ var replayParentElement = arguments.length > 1 ? arguments[1] : undefined;
20918
+ debug("Visuals: buildChildren (playerOnly = ".concat(playerOnly).concat(replayParentElement ? ", replayParentElement=\"".concat(replayParentElement, "\"") : "", ")"));
20921
20919
  buildNoScriptTag();
20922
20920
  if (!playerOnly) {
20923
20921
  notifier.build();
20924
20922
  recorderInsides.build();
20925
20923
  }
20926
- replay.build();
20924
+ replay.build(replayParentElement);
20927
20925
  }
20928
20926
  function initEvents() {
20929
20927
  var playerOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -20983,6 +20981,7 @@ var Visuals = function Visuals(container, options) {
20983
20981
  };
20984
20982
  this.build = function () {
20985
20983
  var playerOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20984
+ var replayParentElement = arguments.length > 1 ? arguments[1] : undefined;
20986
20985
  visualsElement = container.querySelector(".".concat(options.selectors.visualsClass));
20987
20986
  if (!visualsElement) {
20988
20987
  visualsElement = (0, _hyperscript.default)("div.".concat(options.selectors.visualsClass));
@@ -21007,7 +21006,7 @@ var Visuals = function Visuals(container, options) {
21007
21006
  visualsElement.classList.add("visuals");
21008
21007
  correctDimensions();
21009
21008
  !built && initEvents(playerOnly);
21010
- buildChildren(playerOnly);
21009
+ buildChildren(playerOnly, replayParentElement);
21011
21010
 
21012
21011
  // needed for replay handling and container.isOutsideElementOf()
21013
21012
  self.parentNode = visualsElement.parentNode;
@@ -21071,7 +21070,7 @@ var Visuals = function Visuals(container, options) {
21071
21070
  debug("Visuals: unload(".concat(e ? (0, _safeJsonStringify.default)(e) : "", ")"));
21072
21071
  recorder.unload(e);
21073
21072
  recorderInsides.unload(e);
21074
- replay.unload(e);
21073
+ replay.unload();
21075
21074
  built = false;
21076
21075
  } catch (exc) {
21077
21076
  this.emit(_events.default.ERROR, exc);
@@ -23110,12 +23109,15 @@ var Replay = function Replay(parentElement, options) {
23110
23109
  var replayElement;
23111
23110
  var videomail;
23112
23111
  function buildElement() {
23113
- debug("Replay: buildElement()");
23112
+ var replayParentElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : parentElement;
23114
23113
  replayElement = (0, _hyperscript.default)("video.".concat(options.selectors.replayClass));
23115
23114
  if (!replayElement.setAttribute) {
23116
23115
  throw _videomailError.default.create("Please upgrade browser", options);
23117
23116
  }
23118
- parentElement.appendChild(replayElement);
23117
+ if (typeof replayParentElement === "string") {
23118
+ replayParentElement = document.getElementById(replayParentElement);
23119
+ }
23120
+ replayParentElement.appendChild(replayElement);
23119
23121
  }
23120
23122
  function isStandalone() {
23121
23123
  return parentElement.constructor.name === "HTMLDivElement";
@@ -23225,11 +23227,11 @@ var Replay = function Replay(parentElement, options) {
23225
23227
  self.emit(_events.default.REPLAY_SHOWN);
23226
23228
  }
23227
23229
  };
23228
- this.build = function () {
23229
- debug("Replay: build()");
23230
+ this.build = function (replayParentElement) {
23231
+ debug("Replay: build (".concat(replayParentElement ? "replayParentElement=\"".concat(replayParentElement, "\"") : "", ")"));
23230
23232
  replayElement = parentElement.querySelector("video.".concat(options.selectors.replayClass));
23231
23233
  if (!replayElement) {
23232
- buildElement();
23234
+ buildElement(replayParentElement);
23233
23235
  }
23234
23236
  this.hide();
23235
23237
  replayElement.setAttribute("autoplay", true);