Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example chat application which uses zenoh-ts #72

Merged
merged 50 commits into from
Dec 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bfe4d2e
run zenohd with cargo-bin-run
milyin Dec 2, 2024
28242d8
example config updated
milyin Dec 2, 2024
c51e60a
search for plugin in /usr/lib added
milyin Dec 2, 2024
37faf61
docs: Update README with improved instructions for building and runni…
milyin Dec 2, 2024
64b94e8
readme updated, command line examples moved to deno subdirectory
milyin Dec 3, 2024
1c32e71
update readme formatting
milyin Dec 3, 2024
b46c0af
readme grammar fixes
milyin Dec 3, 2024
285ac28
long lines cut in readme
milyin Dec 3, 2024
0e492a5
unifinisehd
milyin Dec 5, 2024
4f2cd69
unfinished
milyin Dec 6, 2024
c3d5e1f
chat example build with importmap
milyin Dec 7, 2024
2c1daf4
unused packages removed, readme added
milyin Dec 7, 2024
80d59a2
readme corrected
milyin Dec 7, 2024
bd64c3f
add username input and integrate CryptoJS for user identification in …
milyin Dec 8, 2024
2974897
add disconnect button and implement username validation in chat example
milyin Dec 8, 2024
001e899
Merge branch 'main' into webpack_experiments
milyin Dec 12, 2024
00b81b7
fix build error when importing channel from bundled source
milyin Dec 12, 2024
41758dd
feat: enhance chat functionality with user management and liveliness …
milyin Dec 12, 2024
495b476
refactor: simplify ChatSession constructor and improve user management
milyin Dec 12, 2024
fa23924
style: enable flex-wrap in server panel for better layout
milyin Dec 12, 2024
21d9649
feat: invoke usersCallback with an empty array on ChatSession reset
milyin Dec 12, 2024
5e1eeef
feat: enhance ChatSession with message publishing and subscription ca…
milyin Dec 12, 2024
5454e92
feat: add message handling capabilities to ChatSession with send and …
milyin Dec 12, 2024
03a7c78
feat: log received messages in ChatSession subscriber for better debu…
milyin Dec 12, 2024
79f8381
feat: deserialize incoming messages in ChatSession subscriber and upd…
milyin Dec 12, 2024
2dc25bd
feat: update message handling in ChatSession to include user informat…
milyin Dec 12, 2024
df8b249
feat: implement message tracking in ChatSession with timestamp, usern…
milyin Dec 12, 2024
e1f8d5e
logging updated, keyexpr changed
milyin Dec 12, 2024
e9464f9
fix: correct keyexpr parsing in ChatUser and enhance message retrieva…
milyin Dec 12, 2024
73af96f
update message log on start
milyin Dec 12, 2024
72f2e49
feat: add message sending on Enter key press in chat input
milyin Dec 12, 2024
eac6614
feat: add connection and disconnection callbacks in ChatSession
milyin Dec 12, 2024
0bafb99
refactor: update log messages for clarity and consistency in ChatSession
milyin Dec 12, 2024
ee2e84c
split ChetSession to separate file
milyin Dec 12, 2024
ea49f20
feat: enhance chat UI with scrollable panels and auto-scroll function…
milyin Dec 12, 2024
ed12230
feat: improve chat UI with rounded corners and consistent spacing
milyin Dec 12, 2024
5565324
feat: enhance chat UI by removing default margin, preventing overflow…
milyin Dec 12, 2024
5c42fda
feat: enhance chat UI by adding padding, adjusting margins, and impro…
milyin Dec 12, 2024
370a8fd
feat: enhance server panel layout with improved input handling and bu…
milyin Dec 12, 2024
471f364
feat: enable and disable message input and send button based on conne…
milyin Dec 13, 2024
e8242bb
feat: improve message display in chat by separating username and mess…
milyin Dec 13, 2024
1e69009
feat: refactor message handling in chat to improve readability and ma…
milyin Dec 13, 2024
5567d76
feat: adjust input button layout in server panel for improved usability
milyin Dec 13, 2024
626c773
readme updated
milyin Dec 13, 2024
ff4c82f
readme updated
milyin Dec 13, 2024
d0cfe79
readme update
milyin Dec 13, 2024
200801a
readme update
milyin Dec 13, 2024
7d9d73d
readme update
milyin Dec 13, 2024
7def4bd
Merge branch 'main' into webpack_experiments
milyin Dec 17, 2024
26bfc74
grammar fix
milyin Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
logging updated, keyexpr changed
  • Loading branch information
milyin committed Dec 12, 2024
commit e1f8d5ecaa9002576648b6c9a0a0643dc1cbd849
17 changes: 12 additions & 5 deletions zenoh-ts/examples/chat/src/main.ts
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class ChatUser {
}
public static fromKeyexpr(keyexpr: KeyExpr): ChatUser | null {
let parts = (keyexpr.toString()).split("/");
if (parts.length < 2 || parts[0] != "user") {
if (parts.length < 3 || parts[0] != "chat" || parts[2] != "user") {
return null;
}
let username = parts[1];
@@ -29,7 +29,7 @@ class ChatUser {
return new ChatUser(username);
}
public toKeyexpr(): KeyExpr {
return new KeyExpr(`user/${this.username}`);
return new KeyExpr(`chat/user/${this.username}`);
}
public toString(): string {
return this.username;
@@ -69,7 +69,10 @@ class ChatSession {

let keyexpr = this.user.toKeyexpr();

this.messages_queryable = await this.session.declare_queryable(keyexpr, {
let messages = await this.session.get("chat/messages");
log(`[Session] Retrieved messages: ${messages}`);

this.messages_queryable = await this.session.declare_queryable("chat/messages", {
callback: (query: Query) => {
log(`[Queryable] Replying to query: ${query.selector().toString()}`);
const response = JSON.stringify(this.messages);
@@ -80,8 +83,9 @@ class ChatSession {
log(`[Session] Created queryable on ${keyexpr}`);

this.messages_publisher = this.session.declare_publisher(keyexpr, {});
log(`[Session] Created publisher on ${keyexpr}`);

this.message_subscriber = await this.session.declare_subscriber("user/*", (sample) => {
this.message_subscriber = await this.session.declare_subscriber("chat/user/*", (sample) => {
let message = deserialize_string(sample.payload().buffer());
let user = ChatUser.fromKeyexpr(sample.keyexpr());
if (user) {
@@ -94,11 +98,13 @@ class ChatSession {
}
return Promise.resolve();
});
log(`[Session] Created subscriber on chat/user/*`);

this.liveliness_token = this.session.liveliness().declare_token(keyexpr);
log(`[Session] Created liveliness token on ${keyexpr}`);

// Subscribe to changes of users presence
this.liveliness_subscriber = this.session.liveliness().declare_subscriber("user/*", {
this.liveliness_subscriber = this.session.liveliness().declare_subscriber("chat/user/*", {
callback: (sample: Sample) => {
let keyexpr = sample.keyexpr();
let user = ChatUser.fromKeyexpr(keyexpr);
@@ -129,6 +135,7 @@ class ChatSession {
},
history: true
});
log(`[Session] Created liveliness subscriber on chat/user/*`);
}

onChangeUsers(callback: () => void) {