gpt4 book ai didi

javascript - 如何在 Firechat 中创建聊天室?

转载 作者:行者123 更新时间:2023-11-30 12:06:10 27 4
gpt4 key购买 nike

我正在使用 Firechat并且我能够成功启动聊天窗口。我正在使用 Firebase custom authentication我可以毫无问题地登录。但是,我现在尝试创建一个新的聊天室,然后进入它。基于Firechat documentation我做了以下事情:

<!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 控制台中我可以看到登录成功:

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

但是没有找到createRoom函数:

TypeError: Firechat.createRoom is not a function

知道这里出了什么问题吗?

最佳答案

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

使用给定的名称(字符串)和类型(字符串 - 公共(public)或私有(private))创建一个新房间,并在完成时使用房间 ID 调用回调。


您似乎没有回调。


 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());
}
});
};

来源:https://firechat.firebaseapp.com/docs/firechat.html

关于javascript - 如何在 Firechat 中创建聊天室?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35161116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com