Reworking bot code. Again... #7

Merged
snxraven merged 5 commits from MiTask/LinkUp-P2P-Chat:main into main 2024-06-11 16:38:55 -04:00
3 changed files with 2 additions and 34 deletions
Showing only changes of commit 4aa205cd73 - Show all commits

View File

@ -1,8 +0,0 @@
class ChatRoom {
public ChatRoom(topic, peers) {
this.topic = topic;
this.peers = peers;
}
}
export default ChatRoom;

View File

@ -46,22 +46,8 @@ class Client extends EventEmitter {
}); });
} }
sendMessage(roomPeers, message) { // TODO: Make topic here actually work.
console.log('Bot name:', this.botName); sendMessage(topic, message) {
const timestamp = Date.now();
const messageObj = {
type: 'message',
name: this.botName,
message,
timestamp,
topic: this.currentTopic // Include the current topic
};
const data = JSON.stringify(messageObj);
const peers = [...this.swarm.connections].filter(peer => roomPeers.includes(peer.remotePublicKey.toString('hex')));
for (const peer of peers) peer.write(data);
}
sendMessageToAll(message) {
console.log('Bot name:', this.botName); console.log('Bot name:', this.botName);
const timestamp = Date.now(); const timestamp = Date.now();
const messageObj = { const messageObj = {

View File

@ -1,10 +0,0 @@
class UserPeer {
public UserPeer(peer, topics, username, avatar) {
this.peer = peer;
this.topics = topics;
this.username = username;
this.avatar = avatar;
}
}
export default UserPeer;