Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
firebase-chat-ready-api
Advanced tools
Firebase-chat-ready-API is a simple package, enable fast connection to firebase firestore to create chat manager API.
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
$ 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
const {
initializeFirebase,
ChatRoom
} = require("firebase-chat-ready-api");
ES6
import { initializeFirebase, ChatRoom } from "firebase-chat-ready-api";
initializeFirebase({
// your firebase app config...
});
// define users objects
let userA = {userId: '1'}
let userB = {userId: '2'}
// create chat room
let newchatRoom = new ChatRoom("chat title", userA, userB, err => {
if (!err) console.log(" chat room created successfully");
});
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:
var newchatRoom = new ChatRoom("chat title", userA, userB, err => { // get the chat key if (!err) console.log(newchatRoom.chatRoomRef.key); });
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
newchatRoom.members[0].username; newchatRoom.ctreatedAt; ...
newchatRoom.setNewTitle("new title", title => {
console.log("the chat new title is " + title);
});
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 titlenewchatRoom.remove();
This method is property of ChatRoom
class. call with 2 params
softRemove
set flag isRemoved
to true
onComplete
callback after removing the chat roomChatRoom.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.
var message = newchatRoom.sendMessage("Hi", userA, err => {
if (!err) console.log("message sent");
});
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
ChatRoom.getUserChatRooms(userB, (err, chats) => {
if (!err) console.log("Count of chats is :", chats.length);
chats.map(chat => {
console.log(chat.members[0].username);
});
});
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)newchatRoom.getMessagesAndListen(message => {
console.log(message.body);
});
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
message.updateBody("new message", newBody => {
console.log("message text updated to" + newBody);
});
This method member of Message
class
call with 2 params
newBody
is the new updated messageonComplete
callback after updatevar 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 messageconsole.log(message.createdAt);
// as the updatedAt property not available only after the message get updated
if (message.updatedAt) {
console.log(message.updatedAt);
}
return timestamp
as you can easily format it using package like moment
(for more formats)
or by simply use Date
Class
var date = new Date(createdAt);
// like: 4:01:50 AM
console.log(date.toLocaleTimeString());
// like: 10/16/2018
console.log(date.toLocaleDateString());
// like: 110/16/2018, 4:01:50 AM
console.log(date.toLocaleString());
createdAt
property available also inChatRoom
instance
var reference = newchatRoom.chatRoomRef;
var key = newchatRoom.chatRoomRef.key;
as newchatRoom is an instance of ChatRoom Class
static
function
ChatRoom.findById("-LPK1Rr5mzwkuSDV9U9a", (err, chat) => {
if (!err) console.log(chat);
});
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:
$ 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
FAQs
Firebase-chat-ready-API is a simple package, enable fast connection to firebase firestore to create chat manager API.
The npm package firebase-chat-ready-api receives a total of 2 weekly downloads. As such, firebase-chat-ready-api popularity was classified as not popular.
We found that firebase-chat-ready-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.