forked from snxraven/LinkUp-P2P-Chat
Removed Enum class because it does not work 😭
This commit is contained in:
parent
b244aa9bdf
commit
164efc5b72
@ -38,7 +38,7 @@ loadCommands().then(commands => {
|
|||||||
const bot = new Client(process.env.LINKUP_ROOM_ID, botName);
|
const bot = new Client(process.env.LINKUP_ROOM_ID, botName);
|
||||||
|
|
||||||
// We use Event Emitter here to handle new messages
|
// We use Event Emitter here to handle new messages
|
||||||
bot.on(Event.onMessage, (peer, message) => {
|
bot.on('onMessage', (peer, message) => {
|
||||||
if (message.type == "icon") return;
|
if (message.type == "icon") return;
|
||||||
console.log(message);
|
console.log(message);
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ loadCommands().then(commands => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on(Event.onBotJoinRoom, () => {
|
bot.on('onBotJoinRoom', () => {
|
||||||
console.log("Bot is ready!");
|
console.log("Bot is ready!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
setupSwarm() {
|
setupSwarm() {
|
||||||
this.swarm.on('connection', (peer) => {
|
this.swarm.on('connection', (peer) => {
|
||||||
peer.on('data', message => this.emit(Event.onMessage, peer, JSON.parse(message.toString())));
|
peer.on('data', message => this.emit('onMessage', peer, JSON.parse(message.toString())));
|
||||||
peer.on('error', e => {
|
peer.on('error', e => {
|
||||||
this.emit(Event.onError, e);
|
this.emit('onError', e);
|
||||||
console.error(`Connection error: ${e}`)
|
console.error(`Connection error: ${e}`)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -27,7 +27,7 @@ class Client extends EventEmitter {
|
|||||||
joinChatRoom() {
|
joinChatRoom() {
|
||||||
this.discovery = this.swarm.join(this.topicBuffer, {client: true, server: true});
|
this.discovery = this.swarm.join(this.topicBuffer, {client: true, server: true});
|
||||||
this.discovery.flushed().then(() => {
|
this.discovery.flushed().then(() => {
|
||||||
this.emit(Event.onBotJoinRoom)
|
this.emit('onBotJoinRoom')
|
||||||
console.log(`Bot ${this.botName} joined the chat room.`);
|
console.log(`Bot ${this.botName} joined the chat room.`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -46,10 +46,4 @@ class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event {
|
export default Client;
|
||||||
onMessage,
|
|
||||||
onError,
|
|
||||||
onBotJoinRoom
|
|
||||||
}
|
|
||||||
|
|
||||||
export default { Client, Event };
|
|
||||||
|
Loading…
Reference in New Issue
Block a user