firechat icon indicating copy to clipboard operation
firechat copied to clipboard

Messages will not send

Open fleetclean opened this issue 7 years ago • 1 comments

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.

fleetclean avatar Oct 15 '18 14:10 fleetclean

You have to create a new Firechat object with var api = new Firechat(db); also,user does not appear to be defined, you should use var user = firebase.auth().currentUser;

FrostyAnimations126 avatar May 03 '21 17:05 FrostyAnimations126