Gathering detailed insights and metrics for firebase-chat-ready-api
Gathering detailed insights and metrics for firebase-chat-ready-api
Gathering detailed insights and metrics for firebase-chat-ready-api
Gathering detailed insights and metrics for firebase-chat-ready-api
Firebase-chat-ready-API is a simple package, enable fast connection to firebase firestore to create chat manager API.
npm install firebase-chat-ready-api
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
54 Commits
1 Branches
1 Contributors
Updated on Jan 21, 2020
Latest Version
3.0.12
Package Id
firebase-chat-ready-api@3.0.12
Unpacked Size
192.74 kB
Size
68.58 kB
File Count
7
NPM Version
6.7.0
Node Version
11.14.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Firebase-chat-ready-API is a simple package enable fast connection to firebase firestore to create chat manager. Create chat rooms, send messages and listen to instance messages .
Installation with
1$ npm install firebase-chat-ready-api
This package have two main classes
ChatRoom
class andMessage
class as theChatRoom
class have properties and functions related to the whole chat room such as title, get messages, sending messages, etc ...and the
Message
class have properties and functions related to individual message like message body, time of creation, update message, etc ...
No ES6
1const { 2 initializeFirebase, 3 ChatRoom 4} = require("firebase-chat-ready-api");
ES6
1import { initializeFirebase, ChatRoom } from "firebase-chat-ready-api";
1initializeFirebase({
2 // your firebase app config...
3});
1// define users objects
2let userA = {userId: '1'}
3let userB = {userId: '2'}
4// create chat room
5let newchatRoom = new ChatRoom("chat title", userA, userB, err => {
6 if (!err) console.log(" chat room created successfully");
7});
This class take 5 params as initial values
title
the chat room titleuserA
one of the chat room members. object of {userId, username, photo}
userB
second chat member. object of {userId, username, photo}
onComplete
it's a callback function called after the chat room created successfully in firebasefromRef
create a class for chat room with it's firebase referenceNote: you can get created chat props also in the callback function through:
1var newchatRoom = new ChatRoom("chat title", userA, userB, err => { 2 // get the chat key 3 if (!err) console.log(newchatRoom.chatRoomRef.key); 4});
User Object is consists of
userId
: the user unique id required
usename
: username for this user not required
photo
: url image for this user not required
Note: you can get all of title, members with their props and createdAt bt simply user the chat instance
1newchatRoom.members[0].username; 2newchatRoom.ctreatedAt; 3...
1newchatRoom.setNewTitle("new title", title => {
2 console.log("the chat new title is " + title);
3});
This method is property of ChatRoom
class. call with 2 params
title
as a new string represent the new titleonComplete
callback after changing the title passing the new title1newchatRoom.remove();
This method is property of ChatRoom
class. call with 2 params
softRemove
set flag isRemoved
to true
onComplete
callback after removing the chat room1ChatRoom.removeMutualChatRooms('userA Id', 'userB Id);
This method static
function call with 2 params
userA
The id of the user AuserB
The id of the user BsoftRemove
set flag isRemoved
to true
You can use the ChatRoom instances to send messages to it.
1var message = newchatRoom.sendMessage("Hi", userA, err => {
2 if (!err) console.log("message sent");
3});
This method also member of ChatRoom
class. with 3 params
body
string is the message bodyfrom
represent the user how send the message could be user Id or the user objectonComplete
callback after sending the message to the firbasethis method is return Message
instance
1ChatRoom.getUserChatRooms(userB, (err, chats) => { 2 if (!err) console.log("Count of chats is :", chats.length); 3 chats.map(chat => { 4 console.log(chat.members[0].username); 5 }); 6});
Note: This method is a
static
function
call with 2 params
user
the user could be user Id or the user object
onComplete
callback function call after receiving all chats from firebase passing 2 params
err
is the error message if the call failedchats
it's an array ( List ) of all the user chat room (ChatRoom
instances)1newchatRoom.getMessagesAndListen(message => {
2 console.log(message.body);
3});
call 1 params
action
callback function is the action that should happen when receiving a message
Note : the massages come one after one not in list
This function fires after getting new message
1message.updateBody("new message", newBody => {
2 console.log("message text updated to" + newBody);
3});
This method member of Message
class
call with 2 params
newBody
is the new updated messageonComplete
callback after update1var removedMessage = message.remove();
This method member of Message
class
return the deleted message
call with 1 params
newMessage
is the new updated message stringafterRemove
callback after removing the message1console.log(message.createdAt); 2// as the updatedAt property not available only after the message get updated 3if (message.updatedAt) { 4 console.log(message.updatedAt); 5}
return timestamp
as you can easily format it using package like moment
(for more formats)
or by simply use Date
Class
1var date = new Date(createdAt); 2// like: 4:01:50 AM 3console.log(date.toLocaleTimeString()); 4// like: 10/16/2018 5console.log(date.toLocaleDateString()); 6// like: 110/16/2018, 4:01:50 AM 7console.log(date.toLocaleString());
createdAt
property available also inChatRoom
instance
1var reference = newchatRoom.chatRoomRef; 2var key = newchatRoom.chatRoomRef.key;
as newchatRoom is an instance of ChatRoom Class
static
function
1ChatRoom.findById("-LPK1Rr5mzwkuSDV9U9a", (err, chat) => { 2 if (!err) console.log(chat); 3});
call with 2 params
uid
chat unique id (key)
onComplete
callback function call after receiving all chats from firebase passing 2 params
err
is the error message if the call failedchat
chat room (ChatRoom
instance)Tests are using Jest, to run the tests add your firebase config object in the test file and run:
1$ npm test
Check out our roadmap to get informed by the latest feature released and the upcoming ones. You can also give us insights and vote for a specific feature. And your are more than welcome to contribute.
Note: You probably should change the rules of the firbase to link it correctly
👀 see examples.js
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More