-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathchat.js
28 lines (23 loc) · 1.02 KB
/
chat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const tellraw2dom = require('tellraw2dom');
module.exports = (clientmc) => {
clientmc.handlers.chat = (event) => {
clientmc.console.logNode(tellraw2dom(event.message.json));
};
// call the browser console.log() function with arguments as an array
clientmc.nativeConsoleLog = (args) => {
Function.prototype.bind.call(console.log, console).apply(console, args); // see http://stackoverflow.com/questions/5538972
};
// log to browser and to user console if available
clientmc.log = (msg) => {
const rest = []; //arguments.slice(1); // TODO
clientmc.nativeConsoleLog(['[voxel-clientmc] ' + msg].concat(rest)); // as separate parameters to allow object expansion
if (clientmc.console) clientmc.console.log(msg + ' ' + rest.join(' '));
};
clientmc.on('connectServer', () => {
if (clientmc.console) clientmc.console.widget.on('input', this.onConsoleInput = (text) => {
clientmc.mfworkerStream.write({cmd: 'chat', text: text});
});
});
// TODO: remove listener on disconnect
};