本文介绍了如何在Firechat中创建聊天室?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用,并且能够成功启动聊天窗口。我正在使用,我可以无任何问题地登录。但是,我现在尝试创建一个新的聊天室,然后输入它。根据,我做了以下操作:

I am using Firechat and I am able to successfully initiate the chat window. I am using Firebase custom authentication and I can login without any problem. However, I now try to create a new chat room and then enter it. Based on the Firechat documentation I did the following:

<!doctype html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8" />
<script src='https://cdn.firebase.com/js/client/2.0.2/firebase.js'></script>
<link rel='stylesheet' href='https://cdn.firebase.com/libs/firechat/2.0.1/firechat.min.css' />
<script src='https://cdn.firebase.com/libs/firechat/2.0.1/firechat.min.js'></script>
</head>
<body>

    <script type='text/javascript'>
    var fireBase = new Firebase("https://XXXXXXXXX.firebaseio.com/");

    function initChat(authData) {
      var Firechat = new FirechatUI(fireBase, document.getElementById('firechat'));
      Firechat.setUser(authData.uid, "Username");
      Firechat.createRoom("Test chat room", "public");
    }

    fireBase.authWithCustomToken("UNIQUE_TOKEN", function(error, authData) {
      if (error) {
        console.log("Login Failed!", error);
      } else {
        console.log("Login successful", authData);
        initChat(authData);
      }
    });
    </script>
    <div id='firechat'>
    </div>

</body>
</html>

在javascript控制台中,我可以看到登录成功:

In the javascript console I can see that login is successful:

Login successful Object { auth: Object, expires: XXXXXXXXX, token: "XXXXXXXX…", uid: "XXXXXX", provider: "custom" }

但是找不到createRoom函数:

But the createRoom function is not found:

TypeError: Firechat.createRoom is not a function

在这里错了吗?

Any idea what is going wrong here?

推荐答案

从文档:
Firechat.createRoom(roomName,roomType, callback(roomId))

使用给定的名称(字符串)和类型(string - public或private)创建一个新房间,在完成房间的回叫。

Creates a new room with the given name (string) and type (string - public or private) and invokes the callback with the room ID on completion.

您似乎没有回叫。




It would seem that you do not have a callback.

 Firechat.prototype.createRoom = function(roomName, roomType, callback) {
    var self = this,
        newRoomRef = this._roomRef.push();

    var newRoom = {
      id: newRoomRef.name(),
      name: roomName,
      type: roomType || 'public',
      createdByUserId: this._userId,
      createdAt: Firebase.ServerValue.TIMESTAMP
    };

    if (roomType === 'private') {
      newRoom.authorizedUsers = {};
      newRoom.authorizedUsers[this._userId] = true;
    }

    newRoomRef.set(newRoom, function(error) {
      if (!error) {
        self.enterRoom(newRoomRef.name());
      }
      if (callback) {
        callback(newRoomRef.name());
      }
    });
  };






来源:

这篇关于如何在Firechat中创建聊天室?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:13
查看更多