Quellcode durchsuchen

Add MediaboxService

Danilo Bargen vor 8 Jahren
Ursprung
Commit
fc06b8f661
3 geänderte Dateien mit 75 neuen und 2 gelöschten Zeilen
  1. 9 2
      src/directives/message_media.ts
  2. 2 0
      src/services.ts
  3. 64 0
      src/services/mediabox.ts

+ 9 - 2
src/directives/message_media.ts

@@ -15,21 +15,26 @@
  * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  */
 
+import {MediaboxService} from '../services/mediabox';
 import {MessageService} from '../services/message';
 import {WebClientService} from '../services/webclient';
 
 export default [
     'WebClientService',
+    'MediaboxService',
     'MessageService',
     '$rootScope',
     '$mdDialog',
     '$timeout',
     '$log',
     '$filter',
-    function(webClientService: WebClientService, messageService: MessageService,
+    function(webClientService: WebClientService,
+             mediaboxService: MediaboxService,
+             messageService: MessageService,
              $rootScope: ng.IRootScopeService,
              $mdDialog: ng.material.IDialogService,
-             $timeout: ng.ITimeoutService, $log: ng.ILogService,
+             $timeout: ng.ITimeoutService,
+             $log: ng.ILogService,
              $filter: ng.IFilterService) {
         return {
             restrict: 'EA',
@@ -161,6 +166,8 @@ export default [
 
                                 switch (this.message.type) {
                                     case 'image':
+                                        mediaboxService.setMedia(buffer);
+                                        break;
                                     case 'video':
                                         saveAs(new Blob([buffer]), messageService.getFileName(message));
                                         break;

+ 2 - 0
src/services.ts

@@ -21,6 +21,7 @@ import {ControllerService} from './services/controller';
 import {ControllerModelService} from './services/controller_model';
 import {FingerPrintService} from './services/fingerprint';
 import {TrustedKeyStoreService} from './services/keystore';
+import {MediaboxService} from './services/mediabox';
 import {MessageService} from './services/message';
 import {MimeService} from './services/mime';
 import {NotificationService} from './services/notification';
@@ -54,4 +55,5 @@ angular.module('3ema.services', [])
 .service('ControllerService', ControllerService)
 .service('StringService', StringService)
 .service('SettingsService', SettingsService)
+.service('MediaboxService', MediaboxService)
 ;

+ 64 - 0
src/services/mediabox.ts

@@ -0,0 +1,64 @@
+/**
+ * This file is part of Threema Web.
+ *
+ * Threema Web is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import {AsyncEvent} from 'ts-events';
+
+/**
+ * This service is responsible for showing / hiding the media box.
+ */
+export class MediaboxService {
+
+    private logTag: string = '[MediaboxService]';
+
+    private $log: ng.ILogService;
+
+    /**
+     * This event is triggered every time the media element changes.
+     *
+     * The boolean parameter indicates whether media content is available or not.
+     */
+    public evtMediaChanged = new AsyncEvent<boolean>();
+
+    /**
+     * The full-resolution media data.
+     */
+    public data: ArrayBuffer | null = null;
+
+    public static $inject = ['$log'];
+    constructor($log: ng.ILogService) {
+        this.$log = $log;
+    }
+
+    /**
+     * Update media data.
+     */
+    public setMedia(data: ArrayBuffer) {
+        this.$log.debug(this.logTag, 'Media data updated');
+        this.data = data;
+        this.evtMediaChanged.post(data !== null);
+    }
+
+    /**
+     * Clear media data.
+     */
+    public clearMedia() {
+        this.$log.debug(this.logTag, 'Media data cleared');
+        this.data = null;
+        this.evtMediaChanged.post(false);
+    }
+
+}