mediabox.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * This file is part of Threema Web.
  3. *
  4. * Threema Web is free software: you can redistribute it and/or modify it
  5. * under the terms of the GNU Affero General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License
  15. * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. import {AsyncEvent} from 'ts-events';
  18. /**
  19. * This service is responsible for showing / hiding the media box.
  20. */
  21. export class MediaboxService {
  22. private logTag: string = '[MediaboxService]';
  23. private $log: ng.ILogService;
  24. /**
  25. * This event is triggered every time the media element changes.
  26. *
  27. * The boolean parameter indicates whether media content is available or not.
  28. */
  29. public evtMediaChanged = new AsyncEvent<boolean>();
  30. /**
  31. * The full-resolution media data.
  32. */
  33. public data: ArrayBuffer | null = null;
  34. public static $inject = ['$log'];
  35. constructor($log: ng.ILogService) {
  36. this.$log = $log;
  37. }
  38. /**
  39. * Update media data.
  40. */
  41. public setMedia(data: ArrayBuffer) {
  42. this.$log.debug(this.logTag, 'Media data updated');
  43. this.data = data;
  44. this.evtMediaChanged.post(data !== null);
  45. }
  46. /**
  47. * Clear media data.
  48. */
  49. public clearMedia() {
  50. this.$log.debug(this.logTag, 'Media data cleared');
  51. this.data = null;
  52. this.evtMediaChanged.post(false);
  53. }
  54. }