mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-26 14:33:27 +00:00
Add library/channels_api over the reliable-channel logic: channel_create
returns a {.ffiHandle.} ReliableChannelHandle, channel_send/channel_close
operate on it, and the channel message received/sent/error events are fed by
the channel-layer broker events. Wire them into the FFI root.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
1.1 KiB
Nim
34 lines
1.1 KiB
Nim
## Reliable-channel events: per-channel message received / sent / errored,
|
|
## fed by the channel-layer broker events.
|
|
|
|
proc onChannelMessageReceived*(
|
|
channelId: string, senderId: string, payload: seq[byte]
|
|
) {.ffiEvent: "on_channel_message_received".}
|
|
|
|
proc onChannelMessageSent*(
|
|
channelId: string, requestId: string
|
|
) {.ffiEvent: "on_channel_message_sent".}
|
|
|
|
proc onChannelMessageError*(
|
|
channelId: string, requestId: string, error: string
|
|
) {.ffiEvent: "on_channel_message_error".}
|
|
|
|
proc listenChannelEvents(self: LogosDelivery) =
|
|
let brokerCtx = self.waku.brokerCtx
|
|
|
|
discard ChannelMessageReceivedEvent.listen(
|
|
brokerCtx,
|
|
proc(e: ChannelMessageReceivedEvent) {.async: (raises: []).} =
|
|
onChannelMessageReceived(string(e.channelId), $e.senderId, e.payload),
|
|
)
|
|
discard ChannelMessageSentEvent.listen(
|
|
brokerCtx,
|
|
proc(e: ChannelMessageSentEvent) {.async: (raises: []).} =
|
|
onChannelMessageSent(string(e.channelId), $e.requestId),
|
|
)
|
|
discard ChannelMessageErrorEvent.listen(
|
|
brokerCtx,
|
|
proc(e: ChannelMessageErrorEvent) {.async: (raises: []).} =
|
|
onChannelMessageError(string(e.channelId), $e.requestId, e.error),
|
|
)
|