Source: rest/video/v1/compositionHook.js

  1. 'use strict';
  2. /* jshint ignore:start */
  3. /**
  4. * This code was generated by
  5. * \ / _ _ _| _ _
  6. * | (_)\/(_)(_|\/| |(/_ v1.0.0
  7. * / /
  8. */
  9. /* jshint ignore:end */
  10. var Q = require('q'); /* jshint ignore:line */
  11. var _ = require('lodash'); /* jshint ignore:line */
  12. var util = require('util'); /* jshint ignore:line */
  13. var Page = require('../../../base/Page'); /* jshint ignore:line */
  14. var deserialize = require(
  15. '../../../base/deserialize'); /* jshint ignore:line */
  16. var serialize = require('../../../base/serialize'); /* jshint ignore:line */
  17. var values = require('../../../base/values'); /* jshint ignore:line */
  18. var CompositionHookList;
  19. var CompositionHookPage;
  20. var CompositionHookInstance;
  21. var CompositionHookContext;
  22. /* jshint ignore:start */
  23. /**
  24. * Initialize the CompositionHookList
  25. *
  26. * @constructor Twilio.Video.V1.CompositionHookList
  27. *
  28. * @param {Twilio.Video.V1} version - Version of the resource
  29. */
  30. /* jshint ignore:end */
  31. CompositionHookList = function CompositionHookList(version) {
  32. /* jshint ignore:start */
  33. /**
  34. * @function compositionHooks
  35. * @memberof Twilio.Video.V1#
  36. *
  37. * @param {string} sid - sid of instance
  38. *
  39. * @returns {Twilio.Video.V1.CompositionHookContext}
  40. */
  41. /* jshint ignore:end */
  42. function CompositionHookListInstance(sid) {
  43. return CompositionHookListInstance.get(sid);
  44. }
  45. CompositionHookListInstance._version = version;
  46. // Path Solution
  47. CompositionHookListInstance._solution = {};
  48. CompositionHookListInstance._uri = `/CompositionHooks`;
  49. /* jshint ignore:start */
  50. /**
  51. * Streams CompositionHookInstance records from the API.
  52. *
  53. * This operation lazily loads records as efficiently as possible until the limit
  54. * is reached.
  55. *
  56. * The results are passed into the callback function, so this operation is memory
  57. * efficient.
  58. *
  59. * If a function is passed as the first argument, it will be used as the callback
  60. * function.
  61. *
  62. * @function each
  63. * @memberof Twilio.Video.V1.CompositionHookList#
  64. *
  65. * @param {object} [opts] - Options for request
  66. * @param {boolean} [opts.enabled] -
  67. * Read only CompositionHook resources with an enabled value that matches this parameter
  68. * @param {Date} [opts.dateCreatedAfter] -
  69. * Read only CompositionHook resources created on or after this ISO 8601 datetime with time zone
  70. * @param {Date} [opts.dateCreatedBefore] -
  71. * Read only CompositionHook resources created before this ISO 8601 datetime with time zone
  72. * @param {string} [opts.friendlyName] -
  73. * Read only CompositionHook resources with friendly names that match this string
  74. * @param {number} [opts.limit] -
  75. * Upper limit for the number of records to return.
  76. * each() guarantees never to return more than limit.
  77. * Default is no limit
  78. * @param {number} [opts.pageSize] -
  79. * Number of records to fetch per request,
  80. * when not set will use the default value of 50 records.
  81. * If no pageSize is defined but a limit is defined,
  82. * each() will attempt to read the limit with the most efficient
  83. * page size, i.e. min(limit, 1000)
  84. * @param {Function} [opts.callback] -
  85. * Function to process each record. If this and a positional
  86. * callback are passed, this one will be used
  87. * @param {Function} [opts.done] -
  88. * Function to be called upon completion of streaming
  89. * @param {Function} [callback] - Function to process each record
  90. */
  91. /* jshint ignore:end */
  92. CompositionHookListInstance.each = function each(opts, callback) {
  93. if (_.isFunction(opts)) {
  94. callback = opts;
  95. opts = {};
  96. }
  97. opts = opts || {};
  98. if (opts.callback) {
  99. callback = opts.callback;
  100. }
  101. if (_.isUndefined(callback)) {
  102. throw new Error('Callback function must be provided');
  103. }
  104. var done = false;
  105. var currentPage = 1;
  106. var currentResource = 0;
  107. var limits = this._version.readLimits({
  108. limit: opts.limit,
  109. pageSize: opts.pageSize
  110. });
  111. function onComplete(error) {
  112. done = true;
  113. if (_.isFunction(opts.done)) {
  114. opts.done(error);
  115. }
  116. }
  117. function fetchNextPage(fn) {
  118. var promise = fn();
  119. if (_.isUndefined(promise)) {
  120. onComplete();
  121. return;
  122. }
  123. promise.then(function(page) {
  124. _.each(page.instances, function(instance) {
  125. if (done || (!_.isUndefined(opts.limit) && currentResource >= opts.limit)) {
  126. done = true;
  127. return false;
  128. }
  129. currentResource++;
  130. callback(instance, onComplete);
  131. });
  132. if (!done) {
  133. currentPage++;
  134. fetchNextPage(_.bind(page.nextPage, page));
  135. }
  136. });
  137. promise.catch(onComplete);
  138. }
  139. fetchNextPage(_.bind(this.page, this, _.merge(opts, limits)));
  140. };
  141. /* jshint ignore:start */
  142. /**
  143. * Lists CompositionHookInstance records from the API as a list.
  144. *
  145. * If a function is passed as the first argument, it will be used as the callback
  146. * function.
  147. *
  148. * @function list
  149. * @memberof Twilio.Video.V1.CompositionHookList#
  150. *
  151. * @param {object} [opts] - Options for request
  152. * @param {boolean} [opts.enabled] -
  153. * Read only CompositionHook resources with an enabled value that matches this parameter
  154. * @param {Date} [opts.dateCreatedAfter] -
  155. * Read only CompositionHook resources created on or after this ISO 8601 datetime with time zone
  156. * @param {Date} [opts.dateCreatedBefore] -
  157. * Read only CompositionHook resources created before this ISO 8601 datetime with time zone
  158. * @param {string} [opts.friendlyName] -
  159. * Read only CompositionHook resources with friendly names that match this string
  160. * @param {number} [opts.limit] -
  161. * Upper limit for the number of records to return.
  162. * list() guarantees never to return more than limit.
  163. * Default is no limit
  164. * @param {number} [opts.pageSize] -
  165. * Number of records to fetch per request,
  166. * when not set will use the default value of 50 records.
  167. * If no page_size is defined but a limit is defined,
  168. * list() will attempt to read the limit with the most
  169. * efficient page size, i.e. min(limit, 1000)
  170. * @param {function} [callback] - Callback to handle list of records
  171. *
  172. * @returns {Promise} Resolves to a list of records
  173. */
  174. /* jshint ignore:end */
  175. CompositionHookListInstance.list = function list(opts, callback) {
  176. if (_.isFunction(opts)) {
  177. callback = opts;
  178. opts = {};
  179. }
  180. opts = opts || {};
  181. var deferred = Q.defer();
  182. var allResources = [];
  183. opts.callback = function(resource, done) {
  184. allResources.push(resource);
  185. if (!_.isUndefined(opts.limit) && allResources.length === opts.limit) {
  186. done();
  187. }
  188. };
  189. opts.done = function(error) {
  190. if (_.isUndefined(error)) {
  191. deferred.resolve(allResources);
  192. } else {
  193. deferred.reject(error);
  194. }
  195. };
  196. if (_.isFunction(callback)) {
  197. deferred.promise.nodeify(callback);
  198. }
  199. this.each(opts);
  200. return deferred.promise;
  201. };
  202. /* jshint ignore:start */
  203. /**
  204. * Retrieve a single page of CompositionHookInstance records from the API.
  205. *
  206. * The request is executed immediately.
  207. *
  208. * If a function is passed as the first argument, it will be used as the callback
  209. * function.
  210. *
  211. * @function page
  212. * @memberof Twilio.Video.V1.CompositionHookList#
  213. *
  214. * @param {object} [opts] - Options for request
  215. * @param {boolean} [opts.enabled] -
  216. * Read only CompositionHook resources with an enabled value that matches this parameter
  217. * @param {Date} [opts.dateCreatedAfter] -
  218. * Read only CompositionHook resources created on or after this ISO 8601 datetime with time zone
  219. * @param {Date} [opts.dateCreatedBefore] -
  220. * Read only CompositionHook resources created before this ISO 8601 datetime with time zone
  221. * @param {string} [opts.friendlyName] -
  222. * Read only CompositionHook resources with friendly names that match this string
  223. * @param {string} [opts.pageToken] - PageToken provided by the API
  224. * @param {number} [opts.pageNumber] -
  225. * Page Number, this value is simply for client state
  226. * @param {number} [opts.pageSize] - Number of records to return, defaults to 50
  227. * @param {function} [callback] - Callback to handle list of records
  228. *
  229. * @returns {Promise} Resolves to a list of records
  230. */
  231. /* jshint ignore:end */
  232. CompositionHookListInstance.page = function page(opts, callback) {
  233. if (_.isFunction(opts)) {
  234. callback = opts;
  235. opts = {};
  236. }
  237. opts = opts || {};
  238. var deferred = Q.defer();
  239. var data = values.of({
  240. 'Enabled': serialize.bool(_.get(opts, 'enabled')),
  241. 'DateCreatedAfter': serialize.iso8601DateTime(_.get(opts, 'dateCreatedAfter')),
  242. 'DateCreatedBefore': serialize.iso8601DateTime(_.get(opts, 'dateCreatedBefore')),
  243. 'FriendlyName': _.get(opts, 'friendlyName'),
  244. 'PageToken': opts.pageToken,
  245. 'Page': opts.pageNumber,
  246. 'PageSize': opts.pageSize
  247. });
  248. var promise = this._version.page({uri: this._uri, method: 'GET', params: data});
  249. promise = promise.then(function(payload) {
  250. deferred.resolve(new CompositionHookPage(this._version, payload, this._solution));
  251. }.bind(this));
  252. promise.catch(function(error) {
  253. deferred.reject(error);
  254. });
  255. if (_.isFunction(callback)) {
  256. deferred.promise.nodeify(callback);
  257. }
  258. return deferred.promise;
  259. };
  260. /* jshint ignore:start */
  261. /**
  262. * Retrieve a single target page of CompositionHookInstance records from the API.
  263. *
  264. * The request is executed immediately.
  265. *
  266. * If a function is passed as the first argument, it will be used as the callback
  267. * function.
  268. *
  269. * @function getPage
  270. * @memberof Twilio.Video.V1.CompositionHookList#
  271. *
  272. * @param {string} [targetUrl] - API-generated URL for the requested results page
  273. * @param {function} [callback] - Callback to handle list of records
  274. *
  275. * @returns {Promise} Resolves to a list of records
  276. */
  277. /* jshint ignore:end */
  278. CompositionHookListInstance.getPage = function getPage(targetUrl, callback) {
  279. var deferred = Q.defer();
  280. var promise = this._version._domain.twilio.request({method: 'GET', uri: targetUrl});
  281. promise = promise.then(function(payload) {
  282. deferred.resolve(new CompositionHookPage(this._version, payload, this._solution));
  283. }.bind(this));
  284. promise.catch(function(error) {
  285. deferred.reject(error);
  286. });
  287. if (_.isFunction(callback)) {
  288. deferred.promise.nodeify(callback);
  289. }
  290. return deferred.promise;
  291. };
  292. /* jshint ignore:start */
  293. /**
  294. * create a CompositionHookInstance
  295. *
  296. * @function create
  297. * @memberof Twilio.Video.V1.CompositionHookList#
  298. *
  299. * @param {object} opts - Options for request
  300. * @param {string} opts.friendlyName - A unique string to describe the resource
  301. * @param {boolean} [opts.enabled] - Whether the composition hook is active
  302. * @param {object} [opts.videoLayout] -
  303. * An object that describes the video layout of the composition hook
  304. * @param {string|list} [opts.audioSources] -
  305. * An array of track names from the same group room to merge
  306. * @param {string|list} [opts.audioSourcesExcluded] -
  307. * An array of track names to exclude
  308. * @param {string} [opts.resolution] -
  309. * A string that describes the rows (width) and columns (height) of the generated composed video in pixels
  310. * @param {composition_hook.format} [opts.format] -
  311. * The container format of the media files used by the compositions created by the composition hook
  312. * @param {string} [opts.statusCallback] -
  313. * The URL we should call to send status information to your application
  314. * @param {string} [opts.statusCallbackMethod] -
  315. * The HTTP method we should use to call status_callback
  316. * @param {boolean} [opts.trim] -
  317. * Whether to clip the intervals where there is no active media in the Compositions triggered by the composition hook
  318. * @param {function} [callback] - Callback to handle processed record
  319. *
  320. * @returns {Promise} Resolves to processed CompositionHookInstance
  321. */
  322. /* jshint ignore:end */
  323. CompositionHookListInstance.create = function create(opts, callback) {
  324. if (_.isUndefined(opts)) {
  325. throw new Error('Required parameter "opts" missing.');
  326. }
  327. if (_.isUndefined(opts.friendlyName)) {
  328. throw new Error('Required parameter "opts.friendlyName" missing.');
  329. }
  330. var deferred = Q.defer();
  331. var data = values.of({
  332. 'FriendlyName': _.get(opts, 'friendlyName'),
  333. 'Enabled': serialize.bool(_.get(opts, 'enabled')),
  334. 'VideoLayout': serialize.object(_.get(opts, 'videoLayout')),
  335. 'AudioSources': serialize.map(_.get(opts, 'audioSources'), function(e) { return e; }),
  336. 'AudioSourcesExcluded': serialize.map(_.get(opts, 'audioSourcesExcluded'), function(e) { return e; }),
  337. 'Resolution': _.get(opts, 'resolution'),
  338. 'Format': _.get(opts, 'format'),
  339. 'StatusCallback': _.get(opts, 'statusCallback'),
  340. 'StatusCallbackMethod': _.get(opts, 'statusCallbackMethod'),
  341. 'Trim': serialize.bool(_.get(opts, 'trim'))
  342. });
  343. var promise = this._version.create({uri: this._uri, method: 'POST', data: data});
  344. promise = promise.then(function(payload) {
  345. deferred.resolve(new CompositionHookInstance(this._version, payload, this._solution.sid));
  346. }.bind(this));
  347. promise.catch(function(error) {
  348. deferred.reject(error);
  349. });
  350. if (_.isFunction(callback)) {
  351. deferred.promise.nodeify(callback);
  352. }
  353. return deferred.promise;
  354. };
  355. /* jshint ignore:start */
  356. /**
  357. * Constructs a composition_hook
  358. *
  359. * @function get
  360. * @memberof Twilio.Video.V1.CompositionHookList#
  361. *
  362. * @param {string} sid - The SID that identifies the resource to fetch
  363. *
  364. * @returns {Twilio.Video.V1.CompositionHookContext}
  365. */
  366. /* jshint ignore:end */
  367. CompositionHookListInstance.get = function get(sid) {
  368. return new CompositionHookContext(this._version, sid);
  369. };
  370. /* jshint ignore:start */
  371. /**
  372. * Provide a user-friendly representation
  373. *
  374. * @function toJSON
  375. * @memberof Twilio.Video.V1.CompositionHookList#
  376. *
  377. * @returns Object
  378. */
  379. /* jshint ignore:end */
  380. CompositionHookListInstance.toJSON = function toJSON() {
  381. return this._solution;
  382. };
  383. CompositionHookListInstance[util.inspect.custom] = function inspect(depth,
  384. options) {
  385. return util.inspect(this.toJSON(), options);
  386. };
  387. return CompositionHookListInstance;
  388. };
  389. /* jshint ignore:start */
  390. /**
  391. * Initialize the CompositionHookPage
  392. *
  393. * @constructor Twilio.Video.V1.CompositionHookPage
  394. *
  395. * @param {V1} version - Version of the resource
  396. * @param {Response<string>} response - Response from the API
  397. * @param {CompositionHookSolution} solution - Path solution
  398. *
  399. * @returns CompositionHookPage
  400. */
  401. /* jshint ignore:end */
  402. CompositionHookPage = function CompositionHookPage(version, response, solution)
  403. {
  404. // Path Solution
  405. this._solution = solution;
  406. Page.prototype.constructor.call(this, version, response, this._solution);
  407. };
  408. _.extend(CompositionHookPage.prototype, Page.prototype);
  409. CompositionHookPage.prototype.constructor = CompositionHookPage;
  410. /* jshint ignore:start */
  411. /**
  412. * Build an instance of CompositionHookInstance
  413. *
  414. * @function getInstance
  415. * @memberof Twilio.Video.V1.CompositionHookPage#
  416. *
  417. * @param {CompositionHookPayload} payload - Payload response from the API
  418. *
  419. * @returns CompositionHookInstance
  420. */
  421. /* jshint ignore:end */
  422. CompositionHookPage.prototype.getInstance = function getInstance(payload) {
  423. return new CompositionHookInstance(this._version, payload);
  424. };
  425. /* jshint ignore:start */
  426. /**
  427. * Provide a user-friendly representation
  428. *
  429. * @function toJSON
  430. * @memberof Twilio.Video.V1.CompositionHookPage#
  431. *
  432. * @returns Object
  433. */
  434. /* jshint ignore:end */
  435. CompositionHookPage.prototype.toJSON = function toJSON() {
  436. let clone = {};
  437. _.forOwn(this, function(value, key) {
  438. if (!_.startsWith(key, '_') && ! _.isFunction(value)) {
  439. clone[key] = value;
  440. }
  441. });
  442. return clone;
  443. };
  444. CompositionHookPage.prototype[util.inspect.custom] = function inspect(depth,
  445. options) {
  446. return util.inspect(this.toJSON(), options);
  447. };
  448. /* jshint ignore:start */
  449. /**
  450. * Initialize the CompositionHookContext
  451. *
  452. * @constructor Twilio.Video.V1.CompositionHookInstance
  453. *
  454. * @property {string} accountSid - The SID of the Account that created the resource
  455. * @property {string} friendlyName -
  456. * The string that you assigned to describe the resource
  457. * @property {boolean} enabled - Whether the CompositionHook is active
  458. * @property {Date} dateCreated -
  459. * The ISO 8601 date and time in GMT when the resource was created
  460. * @property {Date} dateUpdated -
  461. * The ISO 8601 date and time in GMT when the resource was last updated
  462. * @property {string} sid - The unique string that identifies the resource
  463. * @property {string} audioSources -
  464. * The array of track names to include in the compositions created by the composition hook
  465. * @property {string} audioSourcesExcluded -
  466. * The array of track names to exclude from the compositions created by the composition hook
  467. * @property {object} videoLayout -
  468. * A JSON object that describes the video layout of the Composition
  469. * @property {string} resolution -
  470. * The dimensions of the video image in pixels expressed as columns (width) and rows (height)
  471. * @property {boolean} trim - Whether intervals with no media are clipped
  472. * @property {composition_hook.format} format -
  473. * The container format of the media files used by the compositions created by the composition hook
  474. * @property {string} statusCallback -
  475. * The URL to send status information to your application
  476. * @property {string} statusCallbackMethod -
  477. * The HTTP method we should use to call status_callback
  478. * @property {string} url - The absolute URL of the resource
  479. *
  480. * @param {V1} version - Version of the resource
  481. * @param {CompositionHookPayload} payload - The instance payload
  482. * @param {sid} sid - The SID that identifies the resource to fetch
  483. */
  484. /* jshint ignore:end */
  485. CompositionHookInstance = function CompositionHookInstance(version, payload,
  486. sid) {
  487. this._version = version;
  488. // Marshaled Properties
  489. this.accountSid = payload.account_sid; // jshint ignore:line
  490. this.friendlyName = payload.friendly_name; // jshint ignore:line
  491. this.enabled = payload.enabled; // jshint ignore:line
  492. this.dateCreated = deserialize.iso8601DateTime(payload.date_created); // jshint ignore:line
  493. this.dateUpdated = deserialize.iso8601DateTime(payload.date_updated); // jshint ignore:line
  494. this.sid = payload.sid; // jshint ignore:line
  495. this.audioSources = payload.audio_sources; // jshint ignore:line
  496. this.audioSourcesExcluded = payload.audio_sources_excluded; // jshint ignore:line
  497. this.videoLayout = payload.video_layout; // jshint ignore:line
  498. this.resolution = payload.resolution; // jshint ignore:line
  499. this.trim = payload.trim; // jshint ignore:line
  500. this.format = payload.format; // jshint ignore:line
  501. this.statusCallback = payload.status_callback; // jshint ignore:line
  502. this.statusCallbackMethod = payload.status_callback_method; // jshint ignore:line
  503. this.url = payload.url; // jshint ignore:line
  504. // Context
  505. this._context = undefined;
  506. this._solution = {sid: sid || this.sid, };
  507. };
  508. Object.defineProperty(CompositionHookInstance.prototype,
  509. '_proxy', {
  510. get: function() {
  511. if (!this._context) {
  512. this._context = new CompositionHookContext(this._version, this._solution.sid);
  513. }
  514. return this._context;
  515. }
  516. });
  517. /* jshint ignore:start */
  518. /**
  519. * fetch a CompositionHookInstance
  520. *
  521. * @function fetch
  522. * @memberof Twilio.Video.V1.CompositionHookInstance#
  523. *
  524. * @param {function} [callback] - Callback to handle processed record
  525. *
  526. * @returns {Promise} Resolves to processed CompositionHookInstance
  527. */
  528. /* jshint ignore:end */
  529. CompositionHookInstance.prototype.fetch = function fetch(callback) {
  530. return this._proxy.fetch(callback);
  531. };
  532. /* jshint ignore:start */
  533. /**
  534. * remove a CompositionHookInstance
  535. *
  536. * @function remove
  537. * @memberof Twilio.Video.V1.CompositionHookInstance#
  538. *
  539. * @param {function} [callback] - Callback to handle processed record
  540. *
  541. * @returns {Promise} Resolves to processed CompositionHookInstance
  542. */
  543. /* jshint ignore:end */
  544. CompositionHookInstance.prototype.remove = function remove(callback) {
  545. return this._proxy.remove(callback);
  546. };
  547. /* jshint ignore:start */
  548. /**
  549. * update a CompositionHookInstance
  550. *
  551. * @function update
  552. * @memberof Twilio.Video.V1.CompositionHookInstance#
  553. *
  554. * @param {object} opts - Options for request
  555. * @param {string} opts.friendlyName - A unique string to describe the resource
  556. * @param {boolean} [opts.enabled] - Whether the composition hook is active
  557. * @param {object} [opts.videoLayout] -
  558. * A JSON object that describes the video layout of the composition hook
  559. * @param {string|list} [opts.audioSources] -
  560. * An array of track names from the same group room to merge
  561. * @param {string|list} [opts.audioSourcesExcluded] -
  562. * An array of track names to exclude
  563. * @param {boolean} [opts.trim] -
  564. * Whether to clip the intervals where there is no active media in the Compositions triggered by the composition hook
  565. * @param {composition_hook.format} [opts.format] -
  566. * The container format of the media files used by the compositions created by the composition hook
  567. * @param {string} [opts.resolution] -
  568. * A string that describes the columns (width) and rows (height) of the generated composed video in pixels
  569. * @param {string} [opts.statusCallback] -
  570. * The URL we should call to send status information to your application
  571. * @param {string} [opts.statusCallbackMethod] -
  572. * The HTTP method we should use to call status_callback
  573. * @param {function} [callback] - Callback to handle processed record
  574. *
  575. * @returns {Promise} Resolves to processed CompositionHookInstance
  576. */
  577. /* jshint ignore:end */
  578. CompositionHookInstance.prototype.update = function update(opts, callback) {
  579. return this._proxy.update(opts, callback);
  580. };
  581. /* jshint ignore:start */
  582. /**
  583. * Provide a user-friendly representation
  584. *
  585. * @function toJSON
  586. * @memberof Twilio.Video.V1.CompositionHookInstance#
  587. *
  588. * @returns Object
  589. */
  590. /* jshint ignore:end */
  591. CompositionHookInstance.prototype.toJSON = function toJSON() {
  592. let clone = {};
  593. _.forOwn(this, function(value, key) {
  594. if (!_.startsWith(key, '_') && ! _.isFunction(value)) {
  595. clone[key] = value;
  596. }
  597. });
  598. return clone;
  599. };
  600. CompositionHookInstance.prototype[util.inspect.custom] = function inspect(depth,
  601. options) {
  602. return util.inspect(this.toJSON(), options);
  603. };
  604. /* jshint ignore:start */
  605. /**
  606. * Initialize the CompositionHookContext
  607. *
  608. * @constructor Twilio.Video.V1.CompositionHookContext
  609. *
  610. * @param {V1} version - Version of the resource
  611. * @param {sid} sid - The SID that identifies the resource to fetch
  612. */
  613. /* jshint ignore:end */
  614. CompositionHookContext = function CompositionHookContext(version, sid) {
  615. this._version = version;
  616. // Path Solution
  617. this._solution = {sid: sid, };
  618. this._uri = `/CompositionHooks/${sid}`;
  619. };
  620. /* jshint ignore:start */
  621. /**
  622. * fetch a CompositionHookInstance
  623. *
  624. * @function fetch
  625. * @memberof Twilio.Video.V1.CompositionHookContext#
  626. *
  627. * @param {function} [callback] - Callback to handle processed record
  628. *
  629. * @returns {Promise} Resolves to processed CompositionHookInstance
  630. */
  631. /* jshint ignore:end */
  632. CompositionHookContext.prototype.fetch = function fetch(callback) {
  633. var deferred = Q.defer();
  634. var promise = this._version.fetch({uri: this._uri, method: 'GET'});
  635. promise = promise.then(function(payload) {
  636. deferred.resolve(new CompositionHookInstance(this._version, payload, this._solution.sid));
  637. }.bind(this));
  638. promise.catch(function(error) {
  639. deferred.reject(error);
  640. });
  641. if (_.isFunction(callback)) {
  642. deferred.promise.nodeify(callback);
  643. }
  644. return deferred.promise;
  645. };
  646. /* jshint ignore:start */
  647. /**
  648. * remove a CompositionHookInstance
  649. *
  650. * @function remove
  651. * @memberof Twilio.Video.V1.CompositionHookContext#
  652. *
  653. * @param {function} [callback] - Callback to handle processed record
  654. *
  655. * @returns {Promise} Resolves to processed CompositionHookInstance
  656. */
  657. /* jshint ignore:end */
  658. CompositionHookContext.prototype.remove = function remove(callback) {
  659. var deferred = Q.defer();
  660. var promise = this._version.remove({uri: this._uri, method: 'DELETE'});
  661. promise = promise.then(function(payload) {
  662. deferred.resolve(payload);
  663. }.bind(this));
  664. promise.catch(function(error) {
  665. deferred.reject(error);
  666. });
  667. if (_.isFunction(callback)) {
  668. deferred.promise.nodeify(callback);
  669. }
  670. return deferred.promise;
  671. };
  672. /* jshint ignore:start */
  673. /**
  674. * update a CompositionHookInstance
  675. *
  676. * @function update
  677. * @memberof Twilio.Video.V1.CompositionHookContext#
  678. *
  679. * @param {object} opts - Options for request
  680. * @param {string} opts.friendlyName - A unique string to describe the resource
  681. * @param {boolean} [opts.enabled] - Whether the composition hook is active
  682. * @param {object} [opts.videoLayout] -
  683. * A JSON object that describes the video layout of the composition hook
  684. * @param {string|list} [opts.audioSources] -
  685. * An array of track names from the same group room to merge
  686. * @param {string|list} [opts.audioSourcesExcluded] -
  687. * An array of track names to exclude
  688. * @param {boolean} [opts.trim] -
  689. * Whether to clip the intervals where there is no active media in the Compositions triggered by the composition hook
  690. * @param {composition_hook.format} [opts.format] -
  691. * The container format of the media files used by the compositions created by the composition hook
  692. * @param {string} [opts.resolution] -
  693. * A string that describes the columns (width) and rows (height) of the generated composed video in pixels
  694. * @param {string} [opts.statusCallback] -
  695. * The URL we should call to send status information to your application
  696. * @param {string} [opts.statusCallbackMethod] -
  697. * The HTTP method we should use to call status_callback
  698. * @param {function} [callback] - Callback to handle processed record
  699. *
  700. * @returns {Promise} Resolves to processed CompositionHookInstance
  701. */
  702. /* jshint ignore:end */
  703. CompositionHookContext.prototype.update = function update(opts, callback) {
  704. if (_.isUndefined(opts)) {
  705. throw new Error('Required parameter "opts" missing.');
  706. }
  707. if (_.isUndefined(opts.friendlyName)) {
  708. throw new Error('Required parameter "opts.friendlyName" missing.');
  709. }
  710. var deferred = Q.defer();
  711. var data = values.of({
  712. 'FriendlyName': _.get(opts, 'friendlyName'),
  713. 'Enabled': serialize.bool(_.get(opts, 'enabled')),
  714. 'VideoLayout': serialize.object(_.get(opts, 'videoLayout')),
  715. 'AudioSources': serialize.map(_.get(opts, 'audioSources'), function(e) { return e; }),
  716. 'AudioSourcesExcluded': serialize.map(_.get(opts, 'audioSourcesExcluded'), function(e) { return e; }),
  717. 'Trim': serialize.bool(_.get(opts, 'trim')),
  718. 'Format': _.get(opts, 'format'),
  719. 'Resolution': _.get(opts, 'resolution'),
  720. 'StatusCallback': _.get(opts, 'statusCallback'),
  721. 'StatusCallbackMethod': _.get(opts, 'statusCallbackMethod')
  722. });
  723. var promise = this._version.update({uri: this._uri, method: 'POST', data: data});
  724. promise = promise.then(function(payload) {
  725. deferred.resolve(new CompositionHookInstance(this._version, payload, this._solution.sid));
  726. }.bind(this));
  727. promise.catch(function(error) {
  728. deferred.reject(error);
  729. });
  730. if (_.isFunction(callback)) {
  731. deferred.promise.nodeify(callback);
  732. }
  733. return deferred.promise;
  734. };
  735. /* jshint ignore:start */
  736. /**
  737. * Provide a user-friendly representation
  738. *
  739. * @function toJSON
  740. * @memberof Twilio.Video.V1.CompositionHookContext#
  741. *
  742. * @returns Object
  743. */
  744. /* jshint ignore:end */
  745. CompositionHookContext.prototype.toJSON = function toJSON() {
  746. return this._solution;
  747. };
  748. CompositionHookContext.prototype[util.inspect.custom] = function inspect(depth,
  749. options) {
  750. return util.inspect(this.toJSON(), options);
  751. };
  752. module.exports = {
  753. CompositionHookList: CompositionHookList,
  754. CompositionHookPage: CompositionHookPage,
  755. CompositionHookInstance: CompositionHookInstance,
  756. CompositionHookContext: CompositionHookContext
  757. };