Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firechat - Can't send messages

I have a Firechat implementation that initializes properly but when logged in you can create and enter rooms but the messages go nowhere. I've built functions to handle the sending of messages but I don't think it's connecting the FirechatUI and Firechat objects correctly to the Firebase database.

function initChat(user) {
    var room = '';
    var db = firebase.database().ref("chat");
    var chat = new FirechatUI(db, document.getElementById('firechat'));
    var api = chat._chat;
    console.log(api);
    api.setUser(user.uid, user.displayName, function(user) {
        api.resumeSession();
    });

    chat.setUser(user.uid, user.displayName, function(user) {
        chat.resumeSession();
    });

    api.on('message-add', function(messagedRoom, messageContent) {
        console.log('Sent message to room: '+messagedRoom.id+' with the content "'+messageContent+'"');
        api.sendMessage(messagedRoom.id, messageContent, 'default');
    });

    api.on('room-enter', function(enteredRoom) {
        api.enterRoom(enteredRoom.id);
        room = enteredRoom.id;
    });

    api.on('room-exit', function(exitedRoom) {
        api.leaveRoom(exitedRoom.id);
        room = '';
    });

    isInitialized = true;
}

The "message-add" event never gets triggered but the "room-enter" and "room-exit" events do.

like image 612
Daniel Harris Avatar asked Feb 03 '26 14:02

Daniel Harris


1 Answers

Ok, I tried to create new app with firebase and deploy your code.

Database I'm choose Realtime database enter image description here

You don't need to create tables, you should setup database rules. In my example I set up true for read|write enter image description here

Then we can go to our deployed application, log-in and try to create chat and post messages. enter image description here

All works, and if we try to login from another account - all data exists. enter image description here

Resume: You should setup database rules.

like image 88
mrgrechkinn Avatar answered Feb 06 '26 04:02

mrgrechkinn