mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-08 00:53:08 +00:00
remove stale demo
This commit is contained in:
parent
2cd53d69b0
commit
640db286c6
7
Makefile
7
Makefile
@ -28,7 +28,7 @@ else # "variables.mk" was included. Business as usual until the end of this file
|
||||
.PHONY: all update clean
|
||||
|
||||
# default target, because it's the first one that doesn't start with '.'
|
||||
all: | waku_example nim_chat_poc tui
|
||||
all: | waku_example tui bot_echo pingpong
|
||||
|
||||
test_file := $(word 2,$(MAKECMDGOALS))
|
||||
define test_name
|
||||
@ -82,11 +82,6 @@ waku_example: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
\
|
||||
$(ENV_SCRIPT) nim waku_example $(NIM_PARAMS) nim_chat_poc.nims
|
||||
|
||||
nim_chat_poc: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
\
|
||||
$(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 pingpong: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||
echo -e $(BUILD_MSG) "build/$@" && \
|
||||
|
||||
@ -1,111 +0,0 @@
|
||||
import chronos
|
||||
import chronicles
|
||||
import strformat
|
||||
|
||||
import ../src/chat_sdk/client
|
||||
import ../src/chat_sdk/conversations
|
||||
import ../src/chat_sdk/delivery/waku_client
|
||||
import ../src/chat_sdk/utils
|
||||
import ../src/chat_sdk/identity
|
||||
|
||||
import ../src/content_types/all
|
||||
|
||||
const SELF_DEFINED = 99
|
||||
|
||||
type ImageFrame {.proto3.} = object
|
||||
url {.fieldNumber: 1.}: string
|
||||
altText {.fieldNumber: 2.}: string
|
||||
|
||||
|
||||
proc initImage(url: string): ContentFrame =
|
||||
result = ContentFrame(domain: SELF_DEFINED, tag: 0, bytes: encode(ImageFrame(
|
||||
url: url, altText: "This is an image")))
|
||||
|
||||
proc `$`*(frame: ImageFrame): string =
|
||||
result = fmt"ImageFrame(url:{frame.url} alt_text:{frame.altText})"
|
||||
|
||||
|
||||
proc initLogging() =
|
||||
when defined(chronicles_runtime_filtering):
|
||||
setLogLevel(LogLevel.Debug)
|
||||
discard setTopicState("waku filter", chronicles.Normal, LogLevel.Error)
|
||||
discard setTopicState("waku relay", chronicles.Normal, LogLevel.Error)
|
||||
discard setTopicState("chat client", chronicles.Enabled, LogLevel.Debug)
|
||||
|
||||
proc getContent(content: ContentFrame): string =
|
||||
notice "GetContent", domain = content.domain, tag = content.tag
|
||||
|
||||
# TODO: Hide this complexity from developers
|
||||
if content.domain == 0:
|
||||
if content.tag == 0:
|
||||
let m = decode(content.bytes, TextFrame).valueOr:
|
||||
raise newException(ValueError, fmt"Badly formed Content (domain:{content.domain} tag:{content.tag})")
|
||||
return fmt"{m}"
|
||||
|
||||
if content.domain == SELF_DEFINED:
|
||||
if content.tag == 0:
|
||||
let m = decode(content.bytes, ImageFrame).valueOr:
|
||||
raise newException(ValueError, fmt"Badly formed Content (domain:{content.domain} tag:{content.tag})")
|
||||
return fmt"{m}"
|
||||
|
||||
raise newException(ValueError, fmt"Unhandled content (domain:{content.domain} tag:{content.tag})")
|
||||
|
||||
|
||||
proc main() {.async.} =
|
||||
|
||||
# Create Configurations
|
||||
var cfg_saro = DefaultConfig()
|
||||
var cfg_raya = DefaultConfig()
|
||||
|
||||
# Cross pollinate Peers
|
||||
cfg_saro.staticPeers.add(cfg_raya.getMultiAddr())
|
||||
cfg_raya.staticPeers.add(cfg_saro.getMultiAddr())
|
||||
|
||||
# Start Clients
|
||||
var saro = newClient(cfg_saro, createIdentity("Saro"))
|
||||
saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||
echo " Saro <------ :: " & getContent(msg)
|
||||
await sleepAsync(10000)
|
||||
discard await convo.sendMessage(saro.ds, initImage(
|
||||
"https://waku.org/theme/image/logo-black.svg"))
|
||||
)
|
||||
|
||||
saro.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
||||
echo " Saro -- Read Receipt for " & msgId
|
||||
)
|
||||
|
||||
await saro.start()
|
||||
|
||||
var raya = newClient(cfg_raya, createIdentity("Raya"))
|
||||
raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||
echo " ------> Raya :: " & getContent(msg)
|
||||
await sleepAsync(10000)
|
||||
discard await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame())
|
||||
)
|
||||
|
||||
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||
echo " ------> Raya :: New Conversation: " & convo.id()
|
||||
discard await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame())
|
||||
)
|
||||
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
||||
echo " raya -- Read Receipt for " & msgId
|
||||
)
|
||||
|
||||
await raya.start()
|
||||
|
||||
|
||||
await sleepAsync(5000)
|
||||
|
||||
# Perform OOB Introduction: Raya -> Saro
|
||||
let raya_bundle = raya.createIntroBundle()
|
||||
discard await saro.newPrivateConversation(raya_bundle)
|
||||
|
||||
await sleepAsync(400000)
|
||||
|
||||
saro.stop()
|
||||
raya.stop()
|
||||
|
||||
when isMainModule:
|
||||
initLogging()
|
||||
waitFor main()
|
||||
notice "Shutdown"
|
||||
@ -38,10 +38,6 @@ task waku_example, "Build Waku based simple example":
|
||||
let name = "waku_example"
|
||||
buildBinary name, "examples/", " -d:chronicles_log_level='TRACE' "
|
||||
|
||||
task nim_chat_poc, "Build Waku based simple example":
|
||||
let name = "nim_chat_poc"
|
||||
buildBinary name, "examples/", " -d:chronicles_log_level='INFO' "
|
||||
|
||||
task tui, "Build Waku based simple example":
|
||||
let name = "tui"
|
||||
buildBinary name, "examples/", " -d:chronicles_enabled=on -d:chronicles_log_level='INFO' -d:chronicles_sinks=textlines[file]"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user