UNPKG

@e10in/videojs-record

Version:

A video.js plugin for recording audio/video/image files.

392 lines (317 loc) 13.9 kB
/*! * lamejs plugin for @e10in/videojs-record * @version 4.4.4 * @see https://github.com/collab-project/videojs-record * @copyright 2014-2021 Collab * @license MIT */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("video.js")); else if(typeof define === 'function' && define.amd) define("VideojsRecord", ["video.js"], factory); else if(typeof exports === 'object') exports["VideojsRecord"] = factory(require("video.js")); else root["VideojsRecord"] = root["VideojsRecord"] || {}, root["VideojsRecord"]["lamejs"] = factory(root["videojs"]); })(self, function(__WEBPACK_EXTERNAL_MODULE_video_js__) { return /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ /***/ "./node_modules/@babel/runtime/helpers/assertThisInitialized.js": /*!**********************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/assertThisInitialized.js ***! \**********************************************************************/ /***/ ((module) => { function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } module.exports = _assertThisInitialized; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/classCallCheck.js": /*!***************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/classCallCheck.js ***! \***************************************************************/ /***/ ((module) => { function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } module.exports = _classCallCheck; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/createClass.js": /*!************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/createClass.js ***! \************************************************************/ /***/ ((module) => { function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } module.exports = _createClass; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/getPrototypeOf.js": /*!***************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/getPrototypeOf.js ***! \***************************************************************/ /***/ ((module) => { function _getPrototypeOf(o) { module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } module.exports = _getPrototypeOf; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/inherits.js": /*!*********************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/inherits.js ***! \*********************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var setPrototypeOf = __webpack_require__(/*! ./setPrototypeOf */ "./node_modules/@babel/runtime/helpers/setPrototypeOf.js"); function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) setPrototypeOf(subClass, superClass); } module.exports = _inherits; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js": /*!**********************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/interopRequireDefault.js ***! \**********************************************************************/ /***/ ((module) => { function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } module.exports = _interopRequireDefault; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js": /*!**************************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js ***! \**************************************************************************/ /***/ ((module, __unused_webpack_exports, __webpack_require__) => { var _typeof = __webpack_require__(/*! ../helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js"); var assertThisInitialized = __webpack_require__(/*! ./assertThisInitialized */ "./node_modules/@babel/runtime/helpers/assertThisInitialized.js"); function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return assertThisInitialized(self); } module.exports = _possibleConstructorReturn; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/setPrototypeOf.js": /*!***************************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/setPrototypeOf.js ***! \***************************************************************/ /***/ ((module) => { function _setPrototypeOf(o, p) { module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } module.exports = _setPrototypeOf; /***/ }), /***/ "./node_modules/@babel/runtime/helpers/typeof.js": /*!*******************************************************!*\ !*** ./node_modules/@babel/runtime/helpers/typeof.js ***! \*******************************************************/ /***/ ((module) => { function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { module.exports = _typeof = function _typeof(obj) { return typeof obj; }; } else { module.exports = _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } module.exports = _typeof; /***/ }), /***/ "./src/js/plugins/lamejs-plugin.js": /*!*****************************************!*\ !*** ./src/js/plugins/lamejs-plugin.js ***! \*****************************************/ /***/ ((module, exports, __webpack_require__) => { "use strict"; var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js"); Object.defineProperty(exports, "__esModule", ({ value: true })); exports.default = void 0; var _classCallCheck2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/classCallCheck */ "./node_modules/@babel/runtime/helpers/classCallCheck.js")); var _createClass2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/createClass */ "./node_modules/@babel/runtime/helpers/createClass.js")); var _inherits2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/inherits */ "./node_modules/@babel/runtime/helpers/inherits.js")); var _possibleConstructorReturn2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/possibleConstructorReturn */ "./node_modules/@babel/runtime/helpers/possibleConstructorReturn.js")); var _getPrototypeOf2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/getPrototypeOf */ "./node_modules/@babel/runtime/helpers/getPrototypeOf.js")); var _video = _interopRequireDefault(__webpack_require__(/*! video.js */ "video.js")); function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } var RecordEngine = _video.default.getComponent('RecordEngine'); var LamejsEngine = function (_RecordEngine) { (0, _inherits2.default)(LamejsEngine, _RecordEngine); var _super = _createSuper(LamejsEngine); function LamejsEngine(player, options) { var _this; (0, _classCallCheck2.default)(this, LamejsEngine); _this = _super.call(this, player, options); _this.debug = false; _this.sampleRate = 44100; _this.bitRate = 128; _this.audioWorkerURL = 'worker-realtime.js'; _this.audioType = 'audio/mpeg'; return _this; } (0, _createClass2.default)(LamejsEngine, [{ key: "setup", value: function setup(stream, mediaType, debug) { this.inputStream = stream; this.mediaType = mediaType; this.debug = debug; this.config = { debug: this.debug, sampleRate: this.sampleRate, bitRate: this.bitRate }; this.engine = new Worker(this.audioWorkerURL); this.engine.onmessage = this.onWorkerMessage.bind(this); this.engine.postMessage({ cmd: 'init', config: this.config }); } }, { key: "start", value: function start() { var AudioContext = window.AudioContext || window.webkitAudioContext; this.audioContext = new AudioContext(); this.audioSourceNode = this.audioContext.createMediaStreamSource(this.inputStream); this.processor = this.audioContext.createScriptProcessor(0, 1, 1); this.processor.onaudioprocess = this.onAudioProcess.bind(this); this.audioSourceNode.connect(this.processor); this.processor.connect(this.audioContext.destination); } }, { key: "stop", value: function stop() { if (this.processor && this.audioSourceNode) { this.audioSourceNode.disconnect(); this.processor.disconnect(); this.processor.onaudioprocess = null; } if (this.audioContext) { this.audioContext.close().then(function () {}).catch(function (reason) {}); } this.engine.postMessage({ cmd: 'finish' }); } }, { key: "onWorkerMessage", value: function onWorkerMessage(ev) { switch (ev.data.cmd) { case 'end': this.onStopRecording(new Blob(ev.data.buf, { type: this.audioType })); break; case 'error': this.player().trigger('error', ev.data.error); break; default: this.player().trigger('error', ev.data); break; } } }, { key: "onAudioProcess", value: function onAudioProcess(ev) { var data = ev.inputBuffer.getChannelData(0); this.engine.postMessage({ cmd: 'encode', buf: data }); } }]); return LamejsEngine; }(RecordEngine); _video.default.LamejsEngine = LamejsEngine; var _default = LamejsEngine; exports.default = _default; module.exports = exports.default; /***/ }), /***/ "video.js": /*!*************************************************************************************************!*\ !*** external {"commonjs":"video.js","commonjs2":"video.js","amd":"video.js","root":"videojs"} ***! \*************************************************************************************************/ /***/ ((module) => { "use strict"; module.exports = __WEBPACK_EXTERNAL_MODULE_video_js__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module is referenced by other modules so it can't be inlined /******/ var __webpack_exports__ = __webpack_require__("./src/js/plugins/lamejs-plugin.js"); /******/ /******/ return __webpack_exports__; /******/ })() ; });