Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
9da8262c
Commit
9da8262c
authored
11 months ago
by
Adrien Béraud
Committed by
Adrien Béraud
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
nodejs: fix binding
Change-Id: I11ee1d203c5a163eee323ba93636ae8800311b27
parent
59b5d0a2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/nodejs/callback.h
+142
-0
142 additions, 0 deletions
bin/nodejs/callback.h
with
142 additions
and
0 deletions
bin/nodejs/callback.h
+
142
−
0
View file @
9da8262c
...
@@ -35,6 +35,9 @@ Persistent<Function> swarmLoadedCb;
...
@@ -35,6 +35,9 @@ Persistent<Function> swarmLoadedCb;
Persistent
<
Function
>
messagesFoundCb
;
Persistent
<
Function
>
messagesFoundCb
;
Persistent
<
Function
>
messageReceivedCb
;
Persistent
<
Function
>
messageReceivedCb
;
Persistent
<
Function
>
swarmMessageReceivedCb
;
Persistent
<
Function
>
swarmMessageReceivedCb
;
Persistent
<
Function
>
swarmMessageUpdatedCb
;
Persistent
<
Function
>
reactionAddedCb
;
Persistent
<
Function
>
reactionRemovedCb
;
Persistent
<
Function
>
conversationProfileUpdatedCb
;
Persistent
<
Function
>
conversationProfileUpdatedCb
;
Persistent
<
Function
>
conversationRequestReceivedCb
;
Persistent
<
Function
>
conversationRequestReceivedCb
;
Persistent
<
Function
>
conversationRequestDeclinedCb
;
Persistent
<
Function
>
conversationRequestDeclinedCb
;
...
@@ -109,6 +112,12 @@ getPresistentCb(std::string_view signal)
...
@@ -109,6 +112,12 @@ getPresistentCb(std::string_view signal)
return
&
messageReceivedCb
;
return
&
messageReceivedCb
;
else
if
(
signal
==
"SwarmMessageReceived"
)
else
if
(
signal
==
"SwarmMessageReceived"
)
return
&
swarmMessageReceivedCb
;
return
&
swarmMessageReceivedCb
;
else
if
(
signal
==
"SwarmMessageUpdated"
)
return
&
swarmMessageUpdatedCb
;
else
if
(
signal
==
"ReactionAdded"
)
return
&
reactionAddedCb
;
else
if
(
signal
==
"ReactionRemoved"
)
return
&
reactionRemovedCb
;
else
if
(
signal
==
"ConversationProfileUpdated"
)
else
if
(
signal
==
"ConversationProfileUpdated"
)
return
&
conversationProfileUpdatedCb
;
return
&
conversationProfileUpdatedCb
;
else
if
(
signal
==
"ConversationReady"
)
else
if
(
signal
==
"ConversationReady"
)
...
@@ -139,6 +148,9 @@ getPresistentCb(std::string_view signal)
...
@@ -139,6 +148,9 @@ getPresistentCb(std::string_view signal)
return
nullptr
;
return
nullptr
;
}
}
#define V8_STRING_LITERAL(str) \
v8::String::NewFromUtf8Literal(v8::Isolate::GetCurrent(), str)
#define V8_STRING_NEW(str) \
#define V8_STRING_NEW(str) \
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), \
v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), \
str.data(), \
str.data(), \
...
@@ -174,6 +186,17 @@ stringMapToJsMap(const std::map<std::string, std::string>& strmap)
...
@@ -174,6 +186,17 @@ stringMapToJsMap(const std::map<std::string, std::string>& strmap)
return
jsMap
;
return
jsMap
;
}
}
inline
SWIGV8_OBJECT
stringIntMapToJsMap
(
const
std
::
map
<
std
::
string
,
int32_t
>&
strmap
)
{
SWIGV8_OBJECT
jsMap
=
SWIGV8_OBJECT_NEW
();
for
(
auto
&
kvpair
:
strmap
)
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_NEW_LOCAL
(
std
::
get
<
0
>
(
kvpair
)),
SWIGV8_INTEGER_NEW
(
std
::
get
<
1
>
(
kvpair
)));
return
jsMap
;
}
inline
SWIGV8_ARRAY
inline
SWIGV8_ARRAY
stringMapVecToJsMapArray
(
const
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>&
vect
)
stringMapVecToJsMapArray
(
const
std
::
vector
<
std
::
map
<
std
::
string
,
std
::
string
>>&
vect
)
{
{
...
@@ -183,6 +206,29 @@ stringMapVecToJsMapArray(const std::vector<std::map<std::string, std::string>>&
...
@@ -183,6 +206,29 @@ stringMapVecToJsMapArray(const std::vector<std::map<std::string, std::string>>&
return
jsArray
;
return
jsArray
;
}
}
inline
SWIGV8_OBJECT
swarmMessageToJs
(
const
libjami
::
SwarmMessage
&
message
)
{
SWIGV8_OBJECT
jsMap
=
SWIGV8_OBJECT_NEW
();
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"id"
),
V8_STRING_NEW_LOCAL
(
message
.
id
));
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"type"
),
V8_STRING_NEW_LOCAL
(
message
.
type
));
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"linearizedParent"
),
V8_STRING_NEW_LOCAL
(
message
.
linearizedParent
));
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"body"
),
stringMapToJsMap
(
message
.
body
));
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"reactions"
),
stringMapVecToJsMapArray
(
message
.
reactions
));
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"editions"
),
stringMapVecToJsMapArray
(
message
.
editions
));
jsMap
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
V8_STRING_LITERAL
(
"status"
),
stringIntMapToJsMap
(
message
.
status
));
return
jsMap
;
}
inline
SWIGV8_ARRAY
swarmMessagesToJsArray
(
const
std
::
vector
<
libjami
::
SwarmMessage
>&
messages
)
{
SWIGV8_ARRAY
jsArray
=
SWIGV8_ARRAY_NEW
(
messages
.
size
());
for
(
unsigned
int
i
=
0
;
i
<
messages
.
size
();
i
++
)
jsArray
->
Set
(
SWIGV8_CURRENT_CONTEXT
(),
SWIGV8_INTEGER_NEW_UNS
(
i
),
swarmMessageToJs
(
messages
[
i
]));
return
jsArray
;
}
void
void
setCallback
(
std
::
string_view
signal
,
Local
<
Function
>&
func
)
setCallback
(
std
::
string_view
signal
,
Local
<
Function
>&
func
)
{
{
...
@@ -643,6 +689,102 @@ conversationLoaded(uint32_t id,
...
@@ -643,6 +689,102 @@ conversationLoaded(uint32_t id,
uv_async_send
(
&
signalAsync
);
uv_async_send
(
&
signalAsync
);
}
}
void
swarmLoaded
(
uint32_t
id
,
const
std
::
string
&
accountId
,
const
std
::
string
&
conversationId
,
const
std
::
vector
<
libjami
::
SwarmMessage
>&
messages
)
{
std
::
lock_guard
lock
(
pendingSignalsLock
);
pendingSignals
.
emplace
([
id
,
accountId
,
conversationId
,
messages
]()
{
Local
<
Function
>
func
=
Local
<
Function
>::
New
(
Isolate
::
GetCurrent
(),
swarmLoadedCb
);
if
(
!
func
.
IsEmpty
())
{
SWIGV8_VALUE
callback_args
[]
=
{
SWIGV8_INTEGER_NEW_UNS
(
id
),
V8_STRING_NEW_LOCAL
(
accountId
),
V8_STRING_NEW_LOCAL
(
conversationId
),
swarmMessagesToJsArray
(
messages
)};
func
->
Call
(
SWIGV8_CURRENT_CONTEXT
(),
SWIGV8_NULL
(),
4
,
callback_args
);
}
});
uv_async_send
(
&
signalAsync
);
}
void
swarmMessageReceived
(
const
std
::
string
&
accountId
,
const
std
::
string
&
conversationId
,
const
libjami
::
SwarmMessage
&
message
)
{
std
::
lock_guard
lock
(
pendingSignalsLock
);
pendingSignals
.
emplace
([
accountId
,
conversationId
,
message
]()
{
Local
<
Function
>
func
=
Local
<
Function
>::
New
(
Isolate
::
GetCurrent
(),
swarmMessageReceivedCb
);
if
(
!
func
.
IsEmpty
())
{
SWIGV8_VALUE
callback_args
[]
=
{
V8_STRING_NEW_LOCAL
(
accountId
),
V8_STRING_NEW_LOCAL
(
conversationId
),
swarmMessageToJs
(
message
)};
func
->
Call
(
SWIGV8_CURRENT_CONTEXT
(),
SWIGV8_NULL
(),
3
,
callback_args
);
}
});
uv_async_send
(
&
signalAsync
);
}
void
swarmMessageUpdated
(
const
std
::
string
&
accountId
,
const
std
::
string
&
conversationId
,
const
libjami
::
SwarmMessage
&
message
)
{
std
::
lock_guard
lock
(
pendingSignalsLock
);
pendingSignals
.
emplace
([
accountId
,
conversationId
,
message
]()
{
Local
<
Function
>
func
=
Local
<
Function
>::
New
(
Isolate
::
GetCurrent
(),
swarmMessageUpdatedCb
);
if
(
!
func
.
IsEmpty
())
{
SWIGV8_VALUE
callback_args
[]
=
{
V8_STRING_NEW_LOCAL
(
accountId
),
V8_STRING_NEW_LOCAL
(
conversationId
),
swarmMessageToJs
(
message
)};
func
->
Call
(
SWIGV8_CURRENT_CONTEXT
(),
SWIGV8_NULL
(),
3
,
callback_args
);
}
});
uv_async_send
(
&
signalAsync
);
}
void
reactionAdded
(
const
std
::
string
&
accountId
,
const
std
::
string
&
conversationId
,
const
std
::
string
&
messageId
,
const
std
::
map
<
std
::
string
,
std
::
string
>&
reaction
)
{
std
::
lock_guard
lock
(
pendingSignalsLock
);
pendingSignals
.
emplace
([
accountId
,
conversationId
,
messageId
,
reaction
]()
{
Local
<
Function
>
func
=
Local
<
Function
>::
New
(
Isolate
::
GetCurrent
(),
reactionAddedCb
);
if
(
!
func
.
IsEmpty
())
{
SWIGV8_VALUE
callback_args
[]
=
{
V8_STRING_NEW_LOCAL
(
accountId
),
V8_STRING_NEW_LOCAL
(
conversationId
),
V8_STRING_NEW_LOCAL
(
messageId
),
stringMapToJsMap
(
reaction
)};
func
->
Call
(
SWIGV8_CURRENT_CONTEXT
(),
SWIGV8_NULL
(),
4
,
callback_args
);
}
});
uv_async_send
(
&
signalAsync
);
}
void
reactionRemoved
(
const
std
::
string
&
accountId
,
const
std
::
string
&
conversationId
,
const
std
::
string
&
messageId
,
const
std
::
string
&
reactionId
)
{
std
::
lock_guard
lock
(
pendingSignalsLock
);
pendingSignals
.
emplace
([
accountId
,
conversationId
,
messageId
,
reactionId
]()
{
Local
<
Function
>
func
=
Local
<
Function
>::
New
(
Isolate
::
GetCurrent
(),
reactionRemovedCb
);
if
(
!
func
.
IsEmpty
())
{
SWIGV8_VALUE
callback_args
[]
=
{
V8_STRING_NEW_LOCAL
(
accountId
),
V8_STRING_NEW_LOCAL
(
conversationId
),
V8_STRING_NEW_LOCAL
(
messageId
),
V8_STRING_NEW_LOCAL
(
reactionId
)};
func
->
Call
(
SWIGV8_CURRENT_CONTEXT
(),
SWIGV8_NULL
(),
4
,
callback_args
);
}
});
uv_async_send
(
&
signalAsync
);
}
void
void
messagesFound
(
uint32_t
id
,
messagesFound
(
uint32_t
id
,
const
std
::
string
&
accountId
,
const
std
::
string
&
accountId
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment