Commit c4d03c6d authored by Adrien Béraud's avatar Adrien Béraud

nodejs: add initial module

Change-Id: I12310bd4a5826e5658e5b7fe72a8a5ae6efe82d0
parent a72465d8
include $(top_srcdir)/globals.mk
BUILT_SOURCES= \
ring_wrapper.cpp
ring_wrapper.cpp: jni_interface.i configurationmanager.i managerimpl.i
$(SWIG) -v -c++ -javascript -node -o ring_wrapper.cpp jni_interface.i
CLEANFILES= \
$(BUILT_SOURCES)
{
"targets": [
{
"target_name": "dring",
"sources": [ "ring_wrapper.cpp" ],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ]
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
* Alexandre Lision <alexnadre.L@savoirfairelinux.com>
* Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
%header %{
#include "dring/dring.h"
#include "dring/callmanager_interface.h"
class Callback {
public:
virtual ~Callback() {}
virtual void callStateChanged(const std::string& call_id, const std::string& state, int detail_code){}
virtual void transferFailed(void){}
virtual void transferSucceeded(void){}
virtual void recordPlaybackStopped(const std::string& path){}
virtual void voiceMailNotify(const std::string& call_id, int nd_msg){}
virtual void incomingMessage(const std::string& id, const std::string& from, const std::map<std::string, std::string>& messages){}
virtual void incomingCall(const std::string& account_id, const std::string& call_id, const std::string& from){}
virtual void recordPlaybackFilepath(const std::string& id, const std::string& filename){}
virtual void conferenceCreated(const std::string& conf_id){}
virtual void conferenceChanged(const std::string& conf_id, const std::string& state){}
virtual void conferenceRemoved(const std::string& conf_id){}
virtual void newCallCreated(const std::string& call_id, const std::string&, const std::string&){}
virtual void updatePlaybackScale(const std::string& filepath, int position, int scale){}
virtual void conferenceRemove(const std::string& conf_id){}
virtual void newCall(const std::string& account_id, const std::string& call_id, const std::string& to){}
virtual void sipCallStateChange(const std::string& call_id, const std::string& state, int code){}
virtual void recordingStateChanged(const std::string& call_id, int code){}
virtual void recordStateChange(const std::string& call_id, int state){}
virtual void onRtcpReportReceived(const std::string& call_id, const std::map<std::string, int>& stats){}
virtual void peerHold(const std::string& call_id, bool holding){}
};
%}
%feature("director") Callback;
namespace DRing {
/* Call related methods */
std::string placeCall(const std::string& accountID, const std::string& to);
bool refuse(const std::string& callID);
bool accept(const std::string& callID);
bool hangUp(const std::string& callID);
bool hold(const std::string& callID);
bool unhold(const std::string& callID);
bool muteLocalMedia(const std::string& callid, const std::string& mediaType, bool mute);
bool transfer(const std::string& callID, const std::string& to);
bool attendedTransfer(const std::string& transferID, const std::string& targetID);
std::map<std::string, std::string> getCallDetails(const std::string& callID);
std::vector<std::string> getCallList();
/* Conference related methods */
void removeConference(const std::string& conference_id);
bool joinParticipant(const std::string& sel_callID, const std::string& drag_callID);
void createConfFromParticipantList(const std::vector<std::string>& participants);
bool isConferenceParticipant(const std::string& call_id);
bool addParticipant(const std::string& callID, const std::string& confID);
bool addMainParticipant(const std::string& confID);
bool detachParticipant(const std::string& callID);
bool joinConference(const std::string& sel_confID, const std::string& drag_confID);
bool hangUpConference(const std::string& confID);
bool holdConference(const std::string& confID);
bool unholdConference(const std::string& confID);
std::vector<std::string> getConferenceList();
std::vector<std::string> getParticipantList(const std::string& confID);
std::vector<std::string> getDisplayNames(const std::string& confID);
std::string getConferenceId(const std::string& callID);
std::map<std::string, std::string> getConferenceDetails(const std::string& callID);
/* File Playback methods */
bool startRecordedFilePlayback(const std::string& filepath);
void stopRecordedFilePlayback(const std::string& filepath);
/* General audio methods */
bool toggleRecording(const std::string& callID);
/* DEPRECATED */
void setRecording(const std::string& callID);
void recordPlaybackSeek(double value);
bool getIsRecording(const std::string& callID);
std::string getCurrentAudioCodecName(const std::string& callID);
void playDTMF(const std::string& key);
void startTone(int32_t start, int32_t type);
bool switchInput(const std::string& callID, const std::string& resource);
/* Instant messaging */
void sendTextMessage(const std::string& callID, const std::map<std::string, std::string>& messages, const std::string& from, const bool& isMixed);
}
class Callback {
public:
virtual ~Callback() {}
virtual void callStateChanged(const std::string& call_id, const std::string& state, int detail_code){}
virtual void transferFailed(void){}
virtual void transferSucceeded(void){}
virtual void recordPlaybackStopped(const std::string& path){}
virtual void voiceMailNotify(const std::string& call_id, int nd_msg){}
virtual void incomingMessage(const std::string& id, const std::string& from, const std::map<std::string, std::string>& messages){}
virtual void incomingCall(const std::string& account_id, const std::string& call_id, const std::string& from){}
virtual void recordPlaybackFilepath(const std::string& id, const std::string& filename){}
virtual void conferenceCreated(const std::string& conf_id){}
virtual void conferenceChanged(const std::string& conf_id, const std::string& state){}
virtual void conferenceRemoved(const std::string& conf_id){}
virtual void newCallCreated(const std::string& call_id, const std::string&, const std::string&){}
virtual void updatePlaybackScale(const std::string& filepath, int position, int scale){}
virtual void conferenceRemove(const std::string& conf_id){}
virtual void newCall(const std::string& account_id, const std::string& call_id, const std::string& to){}
virtual void sipCallStateChange(const std::string& call_id, const std::string& state, int code){}
virtual void recordingStateChanged(const std::string& call_id, int code){}
virtual void recordStateChange(const std::string& call_id, int state){}
virtual void onRtcpReportReceived(const std::string& call_id, const std::map<std::string, int>& stats){}
virtual void peerHold(const std::string& call_id, bool holding){}
};
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
%header %{
#include "dring/dring.h"
#include "dring/configurationmanager_interface.h"
class ConfigurationCallback {
public:
virtual ~ConfigurationCallback(){}
virtual void volumeChanged(const std::string& device, int value){}
virtual void accountsChanged(void){}
virtual void historyChanged(void){}
virtual void stunStatusFailure(const std::string& account_id){}
virtual void registrationStateChanged(const std::string& account_id, const std::string& state, int code, const std::string& detail_str){}
virtual void volatileAccountDetailsChanged(const std::string& account_id, const std::map<std::string, std::string>& details){}
virtual void incomingAccountMessage(const std::string& /*account_id*/, const std::string& /*from*/, const std::map<std::string, std::string>& /*payload*/){}
virtual void accountMessageStatusChanged(const std::string& /*account_id*/, uint64_t /*message_id*/, const std::string& /*to*/, int /*state*/){}
virtual void knownDevicesChanged(const std::string& /*account_id*/, const std::map<std::string, std::string>& /*devices*/){}
virtual void exportOnRingEnded(const std::string& /*account_id*/, int /*state*/, const std::string& /*pin*/){}
virtual void incomingTrustRequest(const std::string& /*account_id*/, const std::string& /*from*/, const std::vector<uint8_t>& /*payload*/, time_t received){}
virtual void contactAdded(const std::string& /*account_id*/, const std::string& /*uri*/, bool confirmed){}
virtual void contactRemoved(const std::string& /*account_id*/, const std::string& /*uri*/, bool banned){}
virtual void certificatePinned(const std::string& /*certId*/){}
virtual void certificatePathPinned(const std::string& /*path*/, const std::vector<std::string>& /*certId*/){}
virtual void certificateExpired(const std::string& /*certId*/){}
virtual void certificateStateChanged(const std::string& /*account_id*/, const std::string& /*certId*/, const std::string& /*state*/){}
virtual void errorAlert(int alert){}
virtual void nameRegistrationEnded(const std::string& /*account_id*/, int state, const std::string& /*name*/){}
virtual void registeredNameFound(const std::string& /*account_id*/, int state, const std::string& /*address*/, const std::string& /*name*/){}
virtual void migrationEnded(const std::string& /*accountId*/, const std::string& /*state*/){}
virtual void deviceRevocationEnded(const std::string& /*accountId*/, const std::string& /*device*/, int /*status*/){}
};
%}
%feature("director") ConfigurationCallback;
namespace DRing {
std::map<std::string, std::string> getAccountDetails(const std::string& accountID);
std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID);
void setAccountDetails(const std::string& accountID, const std::map<std::string, std::string>& details);
void setAccountActive(const std::string& accountID, bool active);
std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
std::string addAccount(const std::map<std::string, std::string>& details);
void removeAccount(const std::string& accountID);
std::vector<std::string> getAccountList();
void sendRegister(const std::string& accountID, bool enable);
void registerAllAccounts(void);
uint64_t sendAccountTextMessage(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& message);
int getMessageStatus(uint64_t id);
bool lookupName(const std::string& account, const std::string& nameserver, const std::string& name);
bool lookupAddress(const std::string& account, const std::string& nameserver, const std::string& address);
bool registerName(const std::string& account, const std::string& password, const std::string& name);
std::map<std::string, std::string> getTlsDefaultSettings();
std::vector<unsigned> getCodecList();
std::vector<std::string> getSupportedTlsMethod();
std::vector<std::string> getSupportedCiphers(const std::string& accountID);
std::map<std::string, std::string> getCodecDetails(const std::string& accountID, const unsigned& codecId);
bool setCodecDetails(const std::string& accountID, const unsigned& codecId, const std::map<std::string, std::string>& details);
std::vector<unsigned> getActiveCodecList(const std::string& accountID);
std::string exportOnRing(const std::string& accountID, const std::string& password);
std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID);
bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& deviceID);
void setActiveCodecList(const std::string& accountID, const std::vector<unsigned>& list);
std::vector<std::string> getAudioPluginList();
void setAudioPlugin(const std::string& audioPlugin);
std::vector<std::string> getAudioOutputDeviceList();
void setAudioOutputDevice(int32_t index);
void setAudioInputDevice(int32_t index);
void setAudioRingtoneDevice(int32_t index);
std::vector<std::string> getAudioInputDeviceList();
std::vector<std::string> getCurrentAudioDevicesIndex();
int32_t getAudioInputDeviceIndex(const std::string& name);
int32_t getAudioOutputDeviceIndex(const std::string& name);
std::string getCurrentAudioOutputPlugin();
bool getNoiseSuppressState();
void setNoiseSuppressState(bool state);
bool isAgcEnabled();
void setAgcState(bool enabled);
void muteDtmf(bool mute);
bool isDtmfMuted();
bool isCaptureMuted();
void muteCapture(bool mute);
bool isPlaybackMuted();
void mutePlayback(bool mute);
bool isRingtoneMuted();
void muteRingtone(bool mute);
std::string getAudioManager();
bool setAudioManager(const std::string& api);
std::string getRecordPath();
void setRecordPath(const std::string& recPath);
bool getIsAlwaysRecording();
void setIsAlwaysRecording(bool rec);
void setHistoryLimit(int32_t days);
int32_t getHistoryLimit();
void setAccountsOrder(const std::string& order);
std::map<std::string, std::string> getHookSettings();
void setHookSettings(const std::map<std::string, std::string>& settings);
std::vector<std::map<std::string, std::string> > getCredentials(const std::string& accountID);
void setCredentials(const std::string& accountID, const std::vector<std::map<std::string, std::string> >& details);
std::string getAddrFromInterfaceName(const std::string& interface);
std::vector<std::string> getAllIpInterface();
std::vector<std::string> getAllIpInterfaceByName();
std::map<std::string, std::string> getShortcuts();
void setShortcuts(const std::map<std::string, std::string> &shortcutsMap);
void setVolume(const std::string& device, double value);
double getVolume(const std::string& device);
/*
* Security
*/
std::map<std::string, std::string> validateCertificatePath(const std::string& accountId,
const std::string& certificate,
const std::string& privateKey,
const std::string& privateKeyPassword,
const std::string& caList);
std::map<std::string, std::string> validateCertificate(const std::string& accountId, const std::string& certificate);
std::map<std::string, std::string> getCertificateDetails(const std::string& certificate);
std::map<std::string, std::string> getCertificateDetailsPath(const std::string& certificate, const std::string& privateKey, const std::string& privateKeyPass);
std::vector<std::string> getPinnedCertificates();
std::vector<std::string> pinCertificate(const std::vector<uint8_t>& certificate, bool local);
bool unpinCertificate(const std::string& certId);
void pinCertificatePath(const std::string& path);
unsigned unpinCertificatePath(const std::string& path);
bool pinRemoteCertificate(const std::string& accountId, const std::string& certId);
bool setCertificateStatus(const std::string& account, const std::string& certId, const std::string& status);
std::vector<std::string> getCertificatesByStatus(const std::string& account, const std::string& status);
/* contact requests */
std::vector<std::map<std::string, std::string>> getTrustRequests(const std::string& accountId);
bool acceptTrustRequest(const std::string& accountId, const std::string& from);
bool discardTrustRequest(const std::string& accountId, const std::string& from);
void sendTrustRequest(const std::string& accountId, const std::string& to, const std::vector<uint8_t>& payload);
/* Contacts */
void addContact(const std::string& accountId, const std::string& uri);
void removeContact(const std::string& accountId, const std::string& uri);
std::vector<std::map<std::string, std::string>> getContacts(const std::string& accountId);
int exportAccounts(std::vector<std::string> accountIDs, std::string toDir, std::string password);
int importAccounts(std::string archivePath, std::string password);
void connectivityChanged();
}
class ConfigurationCallback {
public:
virtual ~ConfigurationCallback(){}
virtual void volumeChanged(const std::string& device, int value){}
virtual void accountsChanged(void){}
virtual void historyChanged(void){}
virtual void stunStatusFailure(const std::string& account_id){}
virtual void registrationStateChanged(const std::string& account_id, const std::string& state, int code, const std::string& detail_str){}
virtual void volatileAccountDetailsChanged(const std::string& account_id, const std::map<std::string, std::string>& details){}
virtual void incomingAccountMessage(const std::string& /*account_id*/, const std::string& /*from*/, const std::map<std::string, std::string>& /*payload*/){}
virtual void accountMessageStatusChanged(const std::string& /*account_id*/, uint64_t /*message_id*/, const std::string& /*to*/, int /*state*/){}
virtual void knownDevicesChanged(const std::string& /*account_id*/, const std::map<std::string, std::string>& /*devices*/){}
virtual void exportOnRingEnded(const std::string& /*account_id*/, int /*state*/, const std::string& /*pin*/){}
virtual void incomingTrustRequest(const std::string& /*account_id*/, const std::string& /*from*/, const std::vector<uint8_t>& /*payload*/, time_t received){}
virtual void contactAdded(const std::string& /*account_id*/, const std::string& /*uri*/, bool confirmed){}
virtual void contactRemoved(const std::string& /*account_id*/, const std::string& /*uri*/, bool banned){}
virtual void certificatePinned(const std::string& /*certId*/){}
virtual void certificatePathPinned(const std::string& /*path*/, const std::vector<std::string>& /*certId*/){}
virtual void certificateExpired(const std::string& /*certId*/){}
virtual void certificateStateChanged(const std::string& /*account_id*/, const std::string& /*certId*/, const std::string& /*state*/){}
virtual void errorAlert(int alert){}
virtual void nameRegistrationEnded(const std::string& /*account_id*/, int state, const std::string& /*name*/){}
virtual void registeredNameFound(const std::string& /*account_id*/, int state, const std::string& /*address*/, const std::string& /*name*/){}
virtual void migrationEnded(const std::string& /*accountId*/, const std::string& /*state*/){}
virtual void deviceRevocationEnded(const std::string& /*accountId*/, const std::string& /*device*/, int /*status*/){}
};
/*
* Copyright (c) 2017 Savoir-faire Linux Inc.
*
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
'use strict';
require("./build/Release/dring")
/*
* Copyright (C) 2004-2016 Savoir-faire Linux Inc.
*
* Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* File : jni_interface.i */
%module (directors="1") Ringservice
#define SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON
%include "typemaps.i"
%include "std_string.i" /* std::string typemaps */
%include "arrays_javascript.i";
%include "carrays.i";
%include "std_map.i";
%include "std_vector.i";
%include "stdint.i";
/* void* shall be handled as byte arrays */
%typemap(jni) void * "void *"
%typemap(jtype) void * "byte[]"
%typemap(jstype) void * "byte[]"
%typemap(javain) void * "$javainput"
%typemap(in) void * %{
$1 = (void*)$input;
%}
%typemap(javadirectorin) void * "$jniinput"
%typemap(out) void * %{
$result = $1;
%}
%typemap(javaout) void * {
return $jnicall;
}
/* Avoid uint64_t to be converted to BigInteger */
%apply int64_t { uint64_t };
namespace std {
%typemap(javacode) map<string, string> %{
public static $javaclassname toSwig(java.util.Map<String,String> in) {
$javaclassname n = new $javaclassname();
for (java.util.Map.Entry<String, String> entry : in.entrySet()) {
if (entry.getValue() != null) {
n.set(entry.getKey(), entry.getValue());
}
}
return n;
}
public java.util.HashMap<String,String> toNative() {
java.util.HashMap<String,String> out = new java.util.HashMap<>((int)size());
StringVect keys = keys();
for (String s : keys) {
out.put(s, get(s));
}
return out;
}
public java.util.HashMap<String,String> toNativeFromUtf8() {
java.util.HashMap<String,String> out = new java.util.HashMap<>((int)size());
StringVect keys = keys();
for (String s : keys) {
out.put(s, getRaw(s).toJavaString());
}
return out;
}
%}
%extend map<string, string> {
std::vector<std::string> keys() const {
std::vector<std::string> k;
k.reserve($self->size());
for (const auto& i : *$self) {
k.push_back(i.first);
}
return k;
}
void setRaw(std::string key, const vector<uint8_t>& value) {
(*$self)[key] = std::string(value.data(), value.data()+value.size());
}
std::vector<uint8_t> getRaw(std::string key) {
auto& v = $self->at(key);
return {v.begin(), v.end()};
}
}
%template(StringMap) map<string, string>;
%typemap(javabase) vector<string> "java.util.AbstractList<String>"
%typemap(javainterface) vector<string> "java.util.RandomAccess"
%extend vector<string> {
value_type set(int i, const value_type& in) throw (std::out_of_range) {
const std::string old = $self->at(i);
$self->at(i) = in;
return old;
}
bool add(const value_type& in) {
$self->push_back(in);
return true;
}
int32_t size() const {
return $self->size();
}
}
%template(StringVect) vector<string>;
%typemap(javacode) vector< map<string,string> > %{
public java.util.ArrayList<java.util.Map<String, String>> toNative() {
java.util.ArrayList<java.util.Map<String, String>> out = new java.util.ArrayList<>();
for (int i = 0; i < size(); ++i) {
out.add(get(i).toNative());
}
return out;
}
%}
%template(VectMap) vector< map<string,string> >;
%template(IntegerMap) map<string,int>;
%template(IntVect) vector<int32_t>;
%template(UintVect) vector<uint32_t>;
%typemap(javacode) vector<uint8_t> %{
public static Blob fromString(String in) {
byte[] dat;
try {
dat = in.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
dat = in.getBytes();
}
Blob n = new Blob(dat.length);
for (int i=0; i<dat.length; i++) {
n.set(i, dat[i]);
}
return n;
}
public String toJavaString() {
byte[] dat = new byte[(int)size()];
for (int i=0; i<dat.length; i++) {
dat[i] = (byte)get(i);
}
try {
return new String(dat, "utf-8");
} catch (java.io.UnsupportedEncodingException e) {
return "";
}
}
%}
%template(Blob) vector<uint8_t>;
%template(FloatVect) vector<float>;
}
/* not parsed by SWIG but needed by generated C files */