Firechat - это «чат с открытым исходным кодом в реальном времени, построенный на Firebase». Вы можете найти его исходный код here.Почему Firechat не инициализируется?
Я пытаюсь инициализировать Firechat после аутентификации пользователя, но чат не будет инициализироваться. Я не вижу ошибок на консоли. Это код (нет CSS). Обычно я регистрирую пользователя, а затем пытаюсь войти в него.
HTML:
<html>
<head>
<title></title>
<!-- jQuery -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>
<!-- Firebase -->
<script src='https://cdn.firebase.com/js/client/2.1.0/firebase.js'></script>
<!-- Firechat -->
<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>
<script src='authentication.js'></script>
</head>
<body>
<section class="container">
<div class="login">
<h1>Login to Chat</h1>
<form>
<p><input type="text" name="login" value="" placeholder="Username" id="loginUsername"></p>
<p><input type="password" name="password" value="" placeholder="Password" id="loginPassword"></p>
<p class="submit"><input type="submit" name="commit" value="Login" onclick='login();'></p>
</form>
</div>
</section>
<section class="container">
<div class="register">
<h1>Register on Chat</h1>
<form>
<p><input type="text" name="login" value="" placeholder="Username" id="registerUsername"></p>
<p><input type="password" name="password" value="" placeholder="Password" id="registerPassword"></p>
<p class="submit"><input type="submit" name="commit" value="Register" onclick='register();'></p>
</form>
</div>
</section>
<div id='firechat-wrapper'></div>
</body>
</html>
JS:
// Create a new Firebase reference, and a new instance of the Login client
var chatRef = new Firebase('https://myfirebase.firebaseio.com/');
// Create new user
function register() {
var username = document.getElementById("registerUsername").value;
var password = document.getElementById("registerPassword").value;
chatRef.createUser({
email : username,
password : password
}, function(error, userData) {
if (error) {
console.log("Error creating user:", error);
} else {
console.log("Successfully created user account with uid:", userData.uid);
}
});
}
// Login user
function login() {
var username = document.getElementById("loginUsername").value;
var password = document.getElementById("loginPassword").value;
chatRef.authWithPassword({
email : username,
password : password
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
chatRef.onAuth(function(authData) {
// Once authenticated, instantiate Firechat with the user id and user name
if (authData) {
initChat(authData);
}
});
}
function initChat(authData) {
var chat = new FirechatUI(chatRef, document.getElementById('firechat-wrapper'));
chat.setUser(authData.uid, authData[authData.provider].displayName);
}
Привет Роб - это работало отлично. Большое спасибо за вашу помощь. – jgozal
Привет, Роб: Может, ты сможешь помочь мне решить эту проблему. После аутентификации пользователя FireChat выполняет инициализацию, но в чате отсутствуют ключевые функции (http://oi58.tinypic.com/2cqgubm.jpg). Я читал документы API, но не могу понять, как различные методы FireChat взаимодействуют с # firechat-wrapper в html. Возможно, я ошибаюсь в этом вопросе. Кроме того, если это помогает, когда я создаю комнату в чате, она дает следующую ошибку: «FIREBASE WARNING: set at/room-metadata/-JwRsGpD1VLJv0XlXzKG failed: permission_denied« – jgozal
Rob - я понял это. Это была проблема с моими правилами. – jgozal