Skip to content
Snippets Groups Projects
Commit 3004e72c authored by Léopold Chappuis's avatar Léopold Chappuis Committed by Adrien Béraud
Browse files

interface-nodejs: add files transfer support

Now it is possible to send and receive files through the nodejs interface

Change-Id: Ide81e01c1965ea790b4c0d892445d14dcec38b30
parent 4d1e7145
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,7 @@ Persistent<Function> mediaChangeRequestedCb;
Persistent<Function> incomingMessageCb;
Persistent<Function> incomingCallCb;
Persistent<Function> incomingCallWithMediaCb;
Persistent<Function> dataTransferEventCb;
Persistent<Function> conversationLoadedCb;
Persistent<Function> swarmLoadedCb;
Persistent<Function> messagesFoundCb;
......@@ -102,6 +103,8 @@ getPresistentCb(std::string_view signal)
return &incomingCallCb;
else if (signal == "IncomingCallWithMedia")
return &incomingCallWithMediaCb;
else if (signal == "DataTransferEvent")
return &dataTransferEventCb;
else if (signal == "ConversationLoaded")
return &conversationLoadedCb;
else if (signal == "SwarmLoaded")
......@@ -667,6 +670,30 @@ incomingCallWithMedia(const std::string& accountId,
uv_async_send(&signalAsync);
}
/** Data Transfer */
void
dataTransferEvent(const std::string& accountId,
const std::string& conversationId,
const std::string& interactionId,
const std::string& fileId,
int eventCode)
{
std::lock_guard<std::mutex> lock(pendingSignalsLock);
pendingSignals.emplace([accountId, conversationId, interactionId, fileId, eventCode]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), dataTransferEventCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(conversationId),
V8_STRING_NEW_LOCAL(interactionId),
V8_STRING_NEW_LOCAL(fileId),
SWIGV8_INTEGER_NEW(eventCode)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 5, callback_args);
}
});
uv_async_send(&signalAsync);
}
/** Conversations */
void
......
/*
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
*
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
* Author: Pierre Duchemin <pierre.duchemin@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.
*/
%apply uint32_t { libjami::DataTransferEventCode };
%apply uint32_t { libjami::DataTransferError };
%apply uint64_t { libjami::DataTransferId };
%apply uint64_t { const libjami::DataTransferId };
%apply int64_t& INOUT { libjami::DataTransferId& id };
%header %{
#include "jami/jami.h"
#include "jami/datatransfer_interface.h"
class DataTransferCallback {
public:
virtual ~DataTransferCallback(){}
virtual void dataTransferEvent(const std::string& accountId, const std::string& conversationId, const std::string& interactionId, const std::string& fileId, int eventCode){}
};
%}
%feature("director") DataTransferCallback;
%typemap(in) std::string& OUTPUT (std::string temp) {
if (!$input.IsEmpty()) {
SWIGV8_THROW_EXCEPTION(SWIGV8_STRING_NEW("array null"));
return;
}
if (SWIGV8_ARRAY::Cast($input)->Length()) {
SWIGV8_THROW_EXCEPTION(SWIGV8_STRING_NEW("Array must contain at least 1 element"));
}
$1 = &temp;
}
%typemap(argout) std::string& OUTPUT {
auto value = SWIGV8_STRING_NEW(temp$argnum.c_str());
SWIGV8_ARRAY_SET(SWIGV8_ARRAY::Cast($input), 0, value);
}
%apply std::string& OUTPUT { std::string& path_out }
%apply int64_t& OUTPUT { int64_t& total_out }
%apply int64_t& OUTPUT { int64_t& progress_out }
namespace libjami {
struct DataTransferInfo
{
std::string accountId;
libjami::DataTransferEventCode lastEvent;
uint32_t flags;
int64_t totalSize;
int64_t bytesProgress;
std::string author;
std::string peer;
std::string conversationId;
std::string displayName;
std::string path;
std::string mimetype;
};
// Files Management
void sendFile(const std::string& accountId, const std::string& conversationId, const std::string& path, const std::string& displayName, const std::string& replyTo);
uint64_t downloadFile(const std::string& accountId, const std::string& conversationId, const std::string& interactionId,const std::string& fileId, const std::string& path);
libjami::DataTransferError cancelDataTransfer(const std::string& accountId, const std::string& conversationId, const std::string& fileId);
libjami::DataTransferError fileTransferInfo(const std::string& accountId, const std::string& conversationId, const std::string& fileId, std::string &path_out, int64_t &total_out, int64_t &progress_out);
}
class DataTransferCallback {
public:
virtual ~DataTransferCallback(){}
virtual void dataTransferEvent(const std::string& accountId, const std::string& conversationId, const std::string& interactionId, const std::string& fileId, int eventCode){}
};
......@@ -78,6 +78,7 @@ namespace std {
%include "callmanager.i"
%include "videomanager.i"
%include "conversation.i"
%include "datatransfer.i"
%header %{
#include "callback.h"
......@@ -148,6 +149,10 @@ void init(const SWIGV8_VALUE& funcMap){
//exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&incomingTrustRequest, _1, _2, _3, _4, _5 )),
};
const std::map<std::string, SharedCallback> dataTransferEvHandlers = {
exportable_callback<libjami::DataTransferSignal::DataTransferEvent>(bind(&dataTransferEvent, _1, _2, _3, _4, _5)),
};
const std::map<std::string, SharedCallback> conversationHandlers = {
exportable_callback<ConversationSignal::ConversationLoaded>(bind(&conversationLoaded, _1, _2, _3, _4)),
exportable_callback<ConversationSignal::SwarmLoaded>(bind(&swarmLoaded, _1, _2, _3, _4)),
......@@ -173,7 +178,7 @@ void init(const SWIGV8_VALUE& funcMap){
registerSignalHandlers(configEvHandlers);
registerSignalHandlers(callEvHandlers);
registerSignalHandlers(conversationHandlers);
registerSignalHandlers(dataTransferEvHandlers);
libjami::start();
}
%}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment