Skip to content

Commit

Permalink
feat: call events
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Jan 28, 2024
1 parent 8af4598 commit 7d8f57c
Show file tree
Hide file tree
Showing 10 changed files with 4,314 additions and 12,708 deletions.
7 changes: 6 additions & 1 deletion examples/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import magic

from neonize.client import NewClient
from neonize.events import ConnectedEv, MessageEv, PairStatusEv, event, ReceiptEv
from neonize.events import ConnectedEv, MessageEv, PairStatusEv, event, ReceiptEv, CallOfferEv
from neonize.proto.def_pb2 import ImageMessage
from neonize.types import MessageServerID
from neonize.utils import log
Expand Down Expand Up @@ -38,6 +38,11 @@ def on_receipt(_: NewClient, receipt: ReceiptEv):
log.debug(receipt)


@client.event(CallOfferEv)
def on_call(_: NewClient, call: CallOfferEv):
log.debug(call)


@client.event(MessageEv)
def on_message(client: NewClient, message: MessageEv):
handler(client, message)
Expand Down
18 changes: 18 additions & 0 deletions neonize/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from threading import Event as EventThread
from .proto.Neonize_pb2 import (
QR as QREv,
CallAccept,
PairStatus as PairStatusEv,
Connected as ConnectedEv,
KeepAliveTimeout as KeepAliveTimeoutEv,
Expand Down Expand Up @@ -41,6 +42,14 @@
NewsletterLeave as NewsletterLeaveEv,
NewsletterMuteChange as NewsletterMuteChangeEv,
NewsletterLiveUpdate as NewsletterLiveUpdateEV,
CallOffer as CallOfferEv,
CallAccept as CallAcceptEv,
CallPreAccept as CallPreAcceptEv,
CallTransport as CallTransportEv,
CallOfferNotice as CallOfferNoticeEv,
CallRelayLatency as CallRelayLatencyEV,
CallTerminate as CallTerminateEv,
UnknownCallEvent as UnknownCallEventEV
)

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -80,6 +89,15 @@
NewsletterLeaveEv: 33,
NewsletterMuteChangeEv: 34,
NewsletterLiveUpdateEV: 35,
CallOfferEv: 36,
CallAcceptEv: 37,
CallPreAcceptEv: 38,
CallTransportEv: 39,
CallOfferNoticeEv: 40,
CallRelayLatencyEV: 41,
CallTerminateEv: 42,
UnknownCallEventEV: 43

}
INT_TO_EVENT: Dict[int, Type[Message]] = {code: ev for ev, code in EVENT_TO_INT.items()}

Expand Down
55 changes: 55 additions & 0 deletions neonize/goneonize/Neonize.proto
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ message NodeAttrs {
bool boolean = 2;
int64 integer = 3;
string text = 4;
JID jid = 5;
}
}

Expand Down Expand Up @@ -782,7 +783,61 @@ message NewsletterLiveUpdate { //35
required int64 TIME = 2;
repeated NewsletterMessage Messages = 3;
}
// call events
message BasicCallMeta {
required JID from = 1;
required int64 timestamp = 2;
required JID callCreator = 3;
required string callID = 4;
}
message CallRemoteMeta {
required string remotePlatform = 1;
required string remoteVersion = 2;
}
//events
message CallOffer {
required BasicCallMeta basicCallMeta = 1;
required CallRemoteMeta callRemoteMeta = 2;
required Node data = 3;

}
message CallAccept {
required BasicCallMeta basicCallMeta = 1;
required CallRemoteMeta callRemoteMeta = 2;
required Node data = 3;

}
message CallPreAccept {
required BasicCallMeta basicCallMeta = 1;
required CallRemoteMeta callRemoteMeta = 2;
required Node data = 3;

}
message CallTransport {
required BasicCallMeta basicCallMeta = 1;
required CallRemoteMeta callRemoteMeta = 2;
required Node data = 3;

}
message CallOfferNotice {
required BasicCallMeta basicCallMeta = 1;
required string media = 2;
required string type = 3;
required Node data = 4;

}
message CallRelayLatency {
required BasicCallMeta basicCallMeta = 1;
required Node data = 2;
}
message CallTerminate {
required BasicCallMeta basicCallMeta = 1;
required string reason = 2;
required Node data = 3;
}
message UnknownCallEvent {
required Node node = 1;
}
message UpdateGroupParticipantsReturnFunction {
optional string Error = 1;
repeated GroupParticipant participants = 2;
Expand Down
111 changes: 111 additions & 0 deletions neonize/goneonize/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,118 @@ func Neonize(db *C.char, id *C.char, logLevel *C.char, qrCb C.ptr_to_python_func
data, size := getBytesAndSize(update_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(35))
}
case *events.CallOffer:
if _, ok := subscribers[36]; ok {
callOffer := neonize.CallOffer{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
CallRemoteMeta: utils.EncodeCallRemoteMeta(v.CallRemoteMeta),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callOffer)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(36))
}
case *events.CallAccept:
if _, ok := subscribers[37]; ok {
callAccept := neonize.CallAccept{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
CallRemoteMeta: utils.EncodeCallRemoteMeta(v.CallRemoteMeta),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callAccept)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(37))
}
case *events.CallPreAccept:
if _, ok := subscribers[38]; ok {
callPreAccept := neonize.CallPreAccept{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
CallRemoteMeta: utils.EncodeCallRemoteMeta(v.CallRemoteMeta),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callPreAccept)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(38))
}
case *events.CallTransport:
if _, ok := subscribers[39]; ok {
callTransport := neonize.CallTransport{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
CallRemoteMeta: utils.EncodeCallRemoteMeta(v.CallRemoteMeta),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callTransport)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(39))
}
case *events.CallOfferNotice:
if _, ok := subscribers[40]; ok {
callOfferNotice := neonize.CallOfferNotice{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
Media: proto.String(v.Media),
Type: proto.String(v.Type),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callOfferNotice)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(40))
}
case *events.CallRelayLatency:
if _, ok := subscribers[41]; ok {
callRelayLatency := neonize.CallRelayLatency{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callRelayLatency)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(41))
}
case *events.CallTerminate:
if _, ok := subscribers[42]; ok {
callTerminate := neonize.CallTerminate{
BasicCallMeta: utils.EncodeBasicCallMeta(v.BasicCallMeta),
Reason: proto.String(v.Reason),
Data: utils.EncodeNode(v.Data),
}
call_bytes, err := proto.Marshal(&callTerminate)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(42))
}
case *events.UnknownCallEvent:
if _, ok := subscribers[43]; ok {
unknownCall := neonize.UnknownCallEvent{
Node: utils.EncodeNode(v.Node),
}
call_bytes, err := proto.Marshal(&unknownCall)
if err != nil {
panic(err)
}
data, size := getBytesAndSize(call_bytes)
go C.call_c_func_callback_bytes(event, data, size, C.int(43))
}
}

// C.free(unsafe.Pointer(CData))
}
client.AddEventHandler(eventHandler)
Expand Down
Loading

0 comments on commit 7d8f57c

Please sign in to comment.