diff --git a/README.md b/README.md index b90a4d3..dd35b01 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,33 @@ Exported static methods * **createPlaylist**(< _array_ >filenames[, < _boolean_ >noLoop]) - _Media_ - Creates an audio player that sequentially reads from the list of `filenames`. Set `noLoop` to true to disable looping of the playlist. When `noLoop` is true, an 'eof' event will be emitted on the Media object when it reaches the end of the playlist. +* **getDevices**() - _(array)_ - Gets list of audio devices + +* **setNullDev**() - _(void)_ - Set null audio device + +* **setPlaybackDev**(<_int_>deviceId) - _(void)_ - Set playback device + +* **setCaptureDev**(<_int_>deviceId) - _(void)_ - Set capture device + +* **getPlaybackDev**(<_int_>deviceId) - _(int)_ - Get playback device + +* **getCaptureDev**(<_int_>deviceId) - _(int)_ - Get capture device + +* **setAECTail**(<_int_>tail) - _(void)_ - Set EC tail in milliseconds + +* **getAECTail**() - _(int)_ - Get EC tail lenght + +* **setInputVolume**(<_int_>volume) - _(void)_ - Set input volume in percentage + +* **getInputVolume**() - _(int)_ - Get input volume percentage + +* **setOutputVolume**(<_int_>volume) - _(void)_ - Set output volume in percentage + +* **getOutputVolume**() - _(int)_ - Get output volume percentage + +* **getCaptureDevMedia**() - _(Media)_ - Get media object for input device + +* **getPlaybackDevMedia**() - _(Media)_ - Get media object for playback device Exported properties ------------------- diff --git a/lib/main.js b/lib/main.js index 2f96641..bf5f3f3 100644 --- a/lib/main.js +++ b/lib/main.js @@ -14,7 +14,20 @@ exports = { createRecorder: addon.createRecorder, createPlayer: addon.createPlayer, createPlaylist: addon.createPlaylist, - + getDevices: addon.getDevices, + setNullDev: addon.setNullDev, + setCaptureDev: addon.setCaptureDev, + setPlaybackDev: addon.setPlaybackDev, + getCaptureDev: addon.getCaptureDev, + getPlaybackDev: addon.getPlaybackDev, + getCaptureDevMedia: addon.getCaptureDevMedia, + getPlaybackDevMedia: addon.getPlaybackDevMedia, + setInputVolume: addon.setInputVolume, + getInputVolume: addon.getInputVolume, + getOutputVolume: addon.getOutputVolume, + setOutputVolume: addon.setOutputVolume, + getAECTail: addon.getAECTail, + setAECTail: addon.setAECTail, version: addon.version(), get config() { diff --git a/src/binding.cc b/src/binding.cc index 03d5223..f1bb536 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -472,6 +472,39 @@ static NAN_METHOD(CreatePlayer) { info.GetReturnValue().Set(med_obj); } +static NAN_METHOD(EPGetPlaybackDevMedia) { + Nan::HandleScope scope; + + AudioMedia& playbackMedia = ep->audDevManager().getPlaybackDevMedia(); + Local med_obj; + med_obj = Nan::New(SIPSTERMedia_constructor) + ->GetFunction() + ->NewInstance(0, NULL); + SIPSTERMedia* med = Nan::ObjectWrap::Unwrap(med_obj); + + med->media = &playbackMedia; + med->is_media_new = true; + + info.GetReturnValue().Set(med_obj); +} +static NAN_METHOD(EPGetCaptureDevMedia) { + Nan::HandleScope scope; + + AudioMedia& captureMedia = ep->audDevManager().getCaptureDevMedia(); + + Local med_obj; + + med_obj = Nan::New(SIPSTERMedia_constructor) + ->GetFunction() + ->NewInstance(0, NULL); + + SIPSTERMedia* med = Nan::ObjectWrap::Unwrap(med_obj); + med->media = &captureMedia; + med->is_media_new = true; + + info.GetReturnValue().Set(med_obj); +} + static NAN_METHOD(CreatePlaylist) { Nan::HandleScope scope; @@ -686,8 +719,6 @@ static NAN_METHOD(EPInit) { uv_async_init(uv_default_loop(), &dumb, static_cast(dumb_cb)); - Endpoint::instance().audDevManager().setNullDev(); - if ((info.Length() == 1 && info[0]->IsBoolean() && info[0]->BooleanValue()) || (info.Length() > 1 && info[1]->IsBoolean() @@ -722,7 +753,86 @@ static NAN_METHOD(EPStart) { } info.GetReturnValue().SetUndefined(); } +static NAN_METHOD(EPGetDevices) { + Nan::HandleScope scope; + AudioDevInfoVector devices; + v8::Local nodeDevices = v8::Local(Nan::New()); + devices = ep->audDevManager().enumDev(); + + for(std::vector::size_type i = 0; i != devices.size(); i++) { + + v8::Local item = Nan::New(); + Nan::Set(item, Nan::New("name").ToLocalChecked(), + Nan::New(devices[i]->name).ToLocalChecked()); + Nan::Set(item, Nan::New("id").ToLocalChecked(), + Nan::New(static_cast(i)) ); + Nan::Set(item, Nan::New("inputCount").ToLocalChecked(), + Nan::New(devices[i]->inputCount)); + Nan::Set(item, Nan::New("outputCount").ToLocalChecked(), + Nan::New(devices[i]->outputCount)); + Nan::Set(nodeDevices, static_cast(i), item); + } + + info.GetReturnValue().Set(nodeDevices); + +} +static NAN_METHOD(EPSetCaptureDevice) { + Nan::HandleScope scope; + int deviceId = Nan::To(info[0]).FromJust(); + ep->audDevManager().setCaptureDev(deviceId); + info.GetReturnValue().SetUndefined(); +} +static NAN_METHOD(EPSetPlaybackDevice) { + Nan::HandleScope scope; + int deviceId = Nan::To(info[0]).FromJust(); + ep->audDevManager().setPlaybackDev(deviceId); + info.GetReturnValue().SetUndefined(); +} +static NAN_METHOD(EPSetNullDevice){ + Nan::HandleScope scope; + ep->audDevManager().setNullDev(); + info.GetReturnValue().SetUndefined(); +} +static NAN_METHOD(EPSetInputVolume) { + Nan::HandleScope scope; + + int volume = Nan::To(info[0]).FromJust(); + ep->audDevManager().setInputVolume(volume); + info.GetReturnValue().SetUndefined(); +} +static NAN_METHOD(EPSetOutputVolume) { + Nan::HandleScope scope; + int volume = Nan::To(info[0]).FromJust(); + ep->audDevManager().setOutputVolume(volume); + info.GetReturnValue().SetUndefined(); +} +static NAN_METHOD(EPGetInputVolume) { + Nan::HandleScope scope; + info.GetReturnValue().Set(Nan::New(static_cast(ep->audDevManager().getInputVolume()))); +} +static NAN_METHOD(EPGetOutputVolume) { + Nan::HandleScope scope; + info.GetReturnValue().Set(Nan::New(static_cast(ep->audDevManager().getOutputVolume()))); +} +static NAN_METHOD(EPGetPlaybackDevice) { + Nan::HandleScope scope; + info.GetReturnValue().Set(Nan::New(static_cast(ep->audDevManager().getPlaybackDev()))); +} +static NAN_METHOD(EPGetCaptureDevice) { + Nan::HandleScope scope; + info.GetReturnValue().Set(Nan::New(static_cast(ep->audDevManager().getCaptureDev()))); +} +static NAN_METHOD(EPSetAEC) { + Nan::HandleScope scope; + int ec = Nan::To(info[0]).FromJust(); + ep->audDevManager().setEcOptions(ec,0); + info.GetReturnValue().SetUndefined(); +} +static NAN_METHOD(EPGetAEC) { + Nan::HandleScope scope; + info.GetReturnValue().Set(Nan::New(static_cast( ep->audDevManager().getEcTail()))); +} static NAN_METHOD(EPGetConfig) { Nan::HandleScope scope; string errstr; @@ -870,7 +980,48 @@ extern "C" { Nan::Set(target, Nan::New("mediaMaxPorts").ToLocalChecked(), Nan::New(EPMediaMaxPorts)->GetFunction()); - + Nan::Set(target, + Nan::New("getDevices").ToLocalChecked(), + Nan::New(EPGetDevices)->GetFunction()); + Nan::Set(target, + Nan::New("setCaptureDev").ToLocalChecked(), + Nan::New(EPSetCaptureDevice)->GetFunction()); + Nan::Set(target, + Nan::New("setNullDev").ToLocalChecked(), + Nan::New(EPSetNullDevice)->GetFunction()); + Nan::Set(target, + Nan::New("setPlaybackDev").ToLocalChecked(), + Nan::New(EPSetPlaybackDevice)->GetFunction()); + Nan::Set(target, + Nan::New("getCaptureDev").ToLocalChecked(), + Nan::New(EPGetCaptureDevice)->GetFunction()); + Nan::Set(target, + Nan::New("getPlaybackDev").ToLocalChecked(), + Nan::New(EPGetPlaybackDevice)->GetFunction()); + Nan::Set(target, + Nan::New("setInputVolume").ToLocalChecked(), + Nan::New(EPSetInputVolume)->GetFunction()); + Nan::Set(target, + Nan::New("setOutputVolume").ToLocalChecked(), + Nan::New(EPSetOutputVolume)->GetFunction()); + Nan::Set(target, + Nan::New("getInputVolume").ToLocalChecked(), + Nan::New(EPGetInputVolume)->GetFunction()); + Nan::Set(target, + Nan::New("getOutputVolume").ToLocalChecked(), + Nan::New(EPGetOutputVolume)->GetFunction()); + Nan::Set(target, + Nan::New("getAECTail").ToLocalChecked(), + Nan::New(EPGetAEC)->GetFunction()); + Nan::Set(target, + Nan::New("setAECTail").ToLocalChecked(), + Nan::New(EPSetAEC)->GetFunction()); + Nan::Set(target, + Nan::New("getPlaybackDevMedia").ToLocalChecked(), + Nan::New(EPGetPlaybackDevMedia)->GetFunction()); + Nan::Set(target, + Nan::New("getCaptureDevMedia").ToLocalChecked(), + Nan::New(EPGetCaptureDevMedia)->GetFunction()); Nan::Set(target, Nan::New("createRecorder").ToLocalChecked(), Nan::New(CreateRecorder)->GetFunction());