mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 06:03:09 +00:00
update pingpong example
This commit is contained in:
parent
16aebac0c7
commit
d910b7f8a7
2
Makefile
2
Makefile
@ -88,7 +88,7 @@ nim_chat_poc: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
$(ENV_SCRIPT) nim nim_chat_poc $(NIM_PARAMS) nim_chat_poc.nims
|
||||
|
||||
# Ensure there is a nimble task with a name that matches the target
|
||||
tui bot_echo: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
tui bot_echo pingpong: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
$(ENV_SCRIPT) nim $@ $(NIM_PARAMS) --path:src nim_chat_poc.nims
|
||||
|
||||
|
||||
@ -1,15 +1,19 @@
|
||||
import chronicles
|
||||
import chronos
|
||||
import strformat
|
||||
|
||||
import chat_sdk
|
||||
import content_types
|
||||
|
||||
# TEsting
|
||||
import ../src/chat_sdk/crypto
|
||||
|
||||
|
||||
proc getContent(content: ContentFrame): string =
|
||||
# Skip type checks and assume its a TextFrame
|
||||
let m = decode(content.bytes, TextFrame).valueOr:
|
||||
raise newException(ValueError, fmt"Badly formed Content")
|
||||
return fmt"{m}"
|
||||
raise newException(ValueError, fmt"Badly formed Content")
|
||||
return fmt"{m}"
|
||||
|
||||
proc main() {.async.} =
|
||||
|
||||
@ -21,15 +25,22 @@ proc main() {.async.} =
|
||||
cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
|
||||
cfg_raya.staticPeers.add(cfg_saro.getMultiAddr())
|
||||
|
||||
# Create Clients
|
||||
var saro = newClient(cfg_saro, createIdentity("Saro"))
|
||||
var raya = newClient(cfg_raya, createIdentity("Raya"))
|
||||
let sKey = loadPrivateKeyFromBytes(@[45u8, 216, 160, 24, 19, 207, 193, 214, 98, 92, 153, 145, 222, 247, 101, 99, 96, 131, 149, 185, 33, 187, 229, 251, 100, 158, 20, 131, 111, 97, 181, 210]).get()
|
||||
let rKey = loadPrivateKeyFromBytes(@[43u8, 12, 160, 51, 212, 90, 199, 160, 154, 164, 129, 229, 147, 69, 151, 17, 239, 51, 190, 33, 86, 164, 50, 105, 39, 250, 182, 116, 138, 132, 114, 234]).get()
|
||||
|
||||
let sIdent = Identity(name: "saro", privateKey: sKey)
|
||||
|
||||
# Create Clients
|
||||
var saro = newClient(cfg_saro, sIdent)
|
||||
var raya = newClient(cfg_raya, Identity(name: "raya", privateKey: rKey))
|
||||
|
||||
var ri = 0
|
||||
# Wire Callbacks
|
||||
saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||
echo " Saro <------ :: " & getContent(msg)
|
||||
await sleepAsync(10000)
|
||||
await sleepAsync(5000)
|
||||
discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame())
|
||||
|
||||
)
|
||||
|
||||
saro.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
||||
@ -41,8 +52,13 @@ proc main() {.async.} =
|
||||
|
||||
raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||
echo " ------> Raya :: " & getContent(msg)
|
||||
await sleepAsync(10000)
|
||||
sdiscard await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame())
|
||||
await sleepAsync(500)
|
||||
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
|
||||
await sleepAsync(800)
|
||||
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
|
||||
await sleepAsync(500)
|
||||
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
|
||||
inc ri
|
||||
)
|
||||
|
||||
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||
@ -63,7 +79,12 @@ proc main() {.async.} =
|
||||
let raya_bundle = raya.createIntroBundle()
|
||||
discard await saro.newPrivateConversation(raya_bundle)
|
||||
|
||||
await sleepAsync(10000) # Run for some time
|
||||
await sleepAsync(20000) # Run for some time
|
||||
|
||||
saro.stop()
|
||||
raya.stop()
|
||||
raya.stop()
|
||||
|
||||
|
||||
when isMainModule:
|
||||
waitFor main()
|
||||
notice "Shutdown"
|
||||
|
||||
@ -49,3 +49,7 @@ task tui, "Build Waku based simple example":
|
||||
task bot_echo, "Build the EchoBot example":
|
||||
let name = "bot_echo"
|
||||
buildBinary name, "examples/", "-d:chronicles_log_level='INFO' -d:chronicles_disabled_topics='waku node' "
|
||||
|
||||
task pingpong, "Build the Pingpong example":
|
||||
let name = "pingpong"
|
||||
buildBinary name, "examples/", "-d:chronicles_log_level='INFO' -d:chronicles_disabled_topics='waku node' "
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user