 
       @__recorder.stop()
       @__chunks = []
+
+    __guessExtensionByMime: (mime) ->
+      known_containers = {
+        'mp4': 'mp4',
+        'ogg': 'ogg',
+        'webm': 'webm',
+        'quicktime': 'mov',
+        'x-matroska': 'mkv',
+      }
+      # e.g. "video/x-matroska;codecs=avc1,opus"
+      if mime
+        # e.g. ["video", "x-matroska;codecs=avc1,opus"]
+        mime = mime.split('/')
+        if mime[0] == 'video'
+          # e.g. "x-matroska;codecs=avc1,opus"
+          mime = mime.slice(1).join('/')
+          # e.g. "x-matroska"
+          container = mime.split(';')[0]
+          # e.g. "mkv"
+          if known_containers[container]
+            return known_containers[container]
+      # In all other cases just return the base extension for all times
+      return 'avi'


      @__recorder.onstop = =>
        blob = new Blob(@__chunks, {'type': @__recorder.mimeType})
        blob.name = "record.webm"
        @dialogApi.addFiles('object', [[blob, {source: 'camera'}]])
        @dialogApi.switchTab('preview')
        @__chunks = []

      @__setState('recording')

      @__chunks = []
      __recorderOptions = {}

      if @settings.audioBitsPerSecond != null
        __recorderOptions.audioBitsPerSecond = @settings.audioBitsPerSecond
