bedrock-protocol/examples/client/client.js
Jonathan Nagy 7263714562
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
2022-06-27 21:49:54 -04:00

17 lines
786 B
JavaScript

/* eslint-disable */
const bedrock = require('bedrock-protocol')
const client = bedrock.createClient({
host: 'localhost', // optional
port: 19132, // optional, default 19132
username: 'Notch', // the username you want to join as, optional if online mode
offline: false // optional, default false. if true, do not login with Xbox Live. You will not be asked to sign-in if set to true.
})
client.on('text', (packet) => { // Listen for chat messages and echo them back.
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()}`
})
}
})