The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/rocketchat-ui/lib/recorderjs/audioRecorder.coffee

40 lines
912 B

@AudioRecorder = new class
start: (cb) ->
window.AudioContext = window.AudioContext or window.webkitAudioContext
navigator.getUserMedia = navigator.getUserMedia or navigator.webkitGetUserMedia
window.URL = window.URL or window.webkitURL
@audio_context = new AudioContext
ok = (stream) =>
@startUserMedia(stream)
cb?.call(@)
if not navigator.getUserMedia?
return cb false
navigator.getUserMedia {audio: true}, ok, (e) ->
console.log('No live audio input: ' + e)
startUserMedia: (stream) ->
@stream = stream
input = @audio_context.createMediaStreamSource(stream)
@recorder = new Recorder(input, {workerPath: '/recorderWorker.js'})
@recorder.record()
stop: (cb) ->
@recorder.stop()
if cb?
@getBlob cb
@stream.getAudioTracks()[0].stop()
@recorder.clear()
delete @audio_context
delete @recorder
delete @stream
getBlob: (cb) ->
@recorder.exportWAV cb