From 7263714562b72b437958ea638c7e9b88034ff33b Mon Sep 17 00:00:00 2001 From: Jonathan Nagy Date: Tue, 28 Jun 2022 11:49:54 +1000 Subject: [PATCH] Fix chat echo sample (#233) * Fix chat echo sample The `client.options.username` reference is optional for online connections. Referencing it here when it is null will not filter out the echo text, causing an infinite loop. * Update client.js --- README.md | 2 +- examples/client/client.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3707b1d..a72aea1 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ const client = bedrock.createClient({ }) client.on('text', (packet) => { // Listen for chat messages and echo them back. - if (packet.source_name != client.options.username) { + if (packet.source_name != client.username) { client.queue('text', { type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '', message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}` diff --git a/examples/client/client.js b/examples/client/client.js index c10710a..7bbd028 100644 --- a/examples/client/client.js +++ b/examples/client/client.js @@ -8,10 +8,10 @@ const client = bedrock.createClient({ }) client.on('text', (packet) => { // Listen for chat messages and echo them back. - if (packet.source_name != client.options.username) { + if (packet.source_name != client.username) { client.queue('text', { type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '', message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}` }) } -}) \ No newline at end of file +})