angular socket sound
unknown
javascript
4 years ago
1.8 kB
7
Indexable
console.log("Talk button pressing");
this.pushToTalkIcon.nativeElement.src = "assets/red-light.png";
this.pushToTalkLabel.nativeElement.innerHTML = "Şuan siz konuşuyorsunuz.";
this.renderer.setAttribute(this.pushToTalkIcon.nativeElement, 'class', 'blink_img');
var constraints = { audio: true };
let websocket = this.socket;
navigator.mediaDevices.getUserMedia(constraints).then(function(mediaStream) {
var mediaRecorder = new MediaRecorder(mediaStream);
var recordedChunks = [];
mediaRecorder.onstart = function(e) {
recordedChunks = [];
};
mediaRecorder.ondataavailable = function(e) {
recordedChunks.push(e.data);
};
mediaRecorder.onstop = function(e) {
var blob = new Blob(recordedChunks, { 'type' : 'audio/x-wav; codecs=opus' });
//socket.emit('radio', blob);
console.log(blob);
websocket.sendAudioStream(blob);
};
// Start recording
mediaRecorder.start();
// Stop recording after 5 seconds and broadcast it to server
setTimeout(function() {
mediaRecorder.stop()
}, 3000);
mediaRecorder.addEventListener('stop', event => {
console.log("Ses akışı bitti!");
//this.releaseTalkButton(event);
this.pushToTalkIconRef.nativeElement.src = "assets/green-light.png";
this.pushToTalkLabelRef.nativeElement.innerHTML = "Haberleşme sistemi aktif.";
this.rendererRef.setAttribute(this.pushToTalkIcon.nativeElement, 'class', '');
});
});Editor is loading...