changeset 145:fd3f25a41ecf

Notify subscribers of new recordings within the Angular Zone.
author Lucas Thompson <dev@lucas.im>
date Tue, 21 Mar 2017 13:00:59 +0000
parents f9624c7f2265
children 333fb7861976
files src/app/services/audio-recorder/audio-recorder.service.ts
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/app/services/audio-recorder/audio-recorder.service.ts	Tue Mar 21 11:11:23 2017 +0000
+++ b/src/app/services/audio-recorder/audio-recorder.service.ts	Tue Mar 21 13:00:59 2017 +0000
@@ -1,7 +1,7 @@
 /**
  * Created by lucas on 17/03/2017.
  */
-import {Injectable, Inject} from "@angular/core";
+import {Injectable, Inject, NgZone} from "@angular/core";
 import {Subject, Observable} from "rxjs";
 
 
@@ -112,7 +112,8 @@
   constructor(@Inject('AudioInputProvider') requestProvider: AudioInputProvider,
               @Inject(
                 'MediaRecorderFactory'
-              ) recorderImpl: MediaRecorderConstructor) {
+              ) recorderImpl: MediaRecorderConstructor,
+              private ngZone: NgZone) {
     this.requestProvider = requestProvider;
     this.recorderImpl = recorderImpl;
     this.recordingStateChange = new Subject<RecorderServiceStatus>();
@@ -134,9 +135,11 @@
         this.recorder.onstop = () => {
           const blob = new Blob(this.chunks, { 'type': this.recorder.mimeType });
           this.chunks.length = 0;
-          this.newRecording.next(
-            blob
-          );
+          this.ngZone.run(() => {
+            this.newRecording.next(
+              blob
+            );
+          });
         };
         this.isRecordingAble = true;
         this.recordingStateChange.next("enabled");