func (p *Plugin) apiAudioSetTarget(call otto.FunctionCall) otto.Value { if len(call.ArgumentList) == 0 { p.instance.Client.VoiceTarget = nil return otto.TrueValue() } target, err := call.Argument(0).Export() if err != nil { return otto.UndefinedValue() } voiceTarget := target.(*gumble.VoiceTarget) p.instance.Client.Send(voiceTarget) p.instance.Client.VoiceTarget = voiceTarget return otto.TrueValue() }
func (p *Plugin) apiAudioIsPlaying(call otto.FunctionCall) otto.Value { if p.instance.Audio.IsPlaying() { return otto.TrueValue() } else { return otto.FalseValue() } }
func (p *Plugin) apiAudioPlay(call otto.FunctionCall) otto.Value { if p.instance.Audio.IsPlaying() { return otto.FalseValue() } obj := call.Argument(0).Object() if obj == nil { return otto.FalseValue() } filenameValue, _ := obj.Get("filename") callbackValue, _ := obj.Get("callback") if enc, ok := p.instance.Client.AudioEncoder.(*opus.Encoder); ok { enc.SetApplication(gopus.Audio) } p.instance.Audio.Source = gumble_ffmpeg.SourceFile(filenameValue.String()) p.instance.Audio.Play() go func() { p.instance.Audio.Wait() if callbackValue.IsFunction() { p.callValue(callbackValue) } }() return otto.TrueValue() }