Commit ef14f9b6 authored by Jonas Herzig's avatar Jonas Herzig
Browse files

Add push-to-talk voice handler

parent 9ad548e1
......@@ -8,7 +8,7 @@ import Resampler from 'libsamplerate.js'
import ko from 'knockout'
import _dompurify from 'dompurify'
import { ContinuousVoiceHandler, initVoice } from './voice'
import { ContinuousVoiceHandler, PushToTalkVoiceHandler, initVoice } from './voice'
const dompurify = _dompurify(window)
......@@ -309,7 +309,7 @@ class GlobalBindings {
if (mode === 'cont') {
voiceHandler = new ContinuousVoiceHandler(this.client)
} else if (mode === 'ptt') {
voiceHandler = new PushToTalkVoiceHandler(this.client, 'ctrl + shift')
} else if (mode === 'vad') {
} else {
......
......@@ -4,6 +4,7 @@ import audioContext from 'audio-context'
import chunker from 'stream-chunker'
import Resampler from 'libsamplerate.js'
import getUserMedia from 'getusermedia'
import keyboardjs from 'keyboardjs'
class VoiceHandler extends Writable {
constructor (client) {
......@@ -44,6 +45,35 @@ export class ContinuousVoiceHandler extends VoiceHandler {
}
}
export class PushToTalkVoiceHandler extends VoiceHandler {
constructor (client, key) {
super(client)
this._key = key
this._pushed = false
this._keydown_handler = () => this._pushed = true
this._keyup_handler = () => {
this._stopOutbound()
this._pushed = false
}
keyboardjs.bind(this._key, this._keydown_handler, this._keyup_handler)
}
_write (data, _, callback) {
if (this._pushed) {
this._getOrCreateOutbound().write(data, callback)
} else {
callback()
}
}
_final (callback) {
super._final(e => {
keyboardjs.unbind(this._key, this._keydown_handler, this._keyup_handler)
callback(e)
})
}
}
export function initVoice (onData, onUserMediaError) {
var resampler = new Resampler({
unsafe: true,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment