Client for VSChat Server.
npm i @vstoodeeoh/vschat-client
useVsChat(serverUrl, secretKey, userId);
useConversations();
useMessages();
import { useVSChat, useConversation, useMessages } from "@vstoodeeoh/vschat-client"
const vsChat = useVSChat("http://localhost:5555", "1234", userId);
const vsCon = useConversations();
const vsMsg = useMessages();
Here are some basic examples to be used. This pacakage was designed by having "freedom" in mind, allowing you to use the information as you find fit.
const vsCon = useConversations();
const myConversations = vsCon.conversations;
console.log(myConversations)
/* Returns
[
{
"_id": "6330d103bb8c954650c1d950",
"participants": [
"6330b9202cde875e935aeadx",
"6330b9202cde875e935aeady"
],
"createdAt": "2022-09-25T22:06:59.332Z",
"updatedAt": "2022-09-25T22:06:59.332Z",
"__v": 0
}
]
*/
By Default it will fetch messages for the first conversation
const vsMsg = useMessages();
const messages = vsMsg.texts;
console.log(messages)
/* Returns
[
{
"conversationId": "633108aabb8c954650c1d9af",
"sender": "6330b9202cde875e935aeadx",
"text": "Testing",
"_id": "63310b79bb8c954650c1da07",
"createdAt": "2022-09-26T02:16:25.854Z",
"updatedAt": "2022-09-26T02:16:25.854Z",
"__v": 0
}
]
*/
const vsCon = useConversations();
vsCon.setConversation("Conversation ID);
const vsChat = useVSChat("http://localhost:5555", "1234", userId);
const onlineUsers = vsChat.onlineUsers;
console.log(onlineUsers);
/* Returns
[
{
"userId": "6330b9202cde875e935aeady",
"socketId": "nugNMvEBlhiDfSKsAADT"
}
]
*/
By default sendMessage sends a message to the selected conversation unless a conversation ID was specified.
const vsMsg = useMessages();
vsMsg.sendMessage("Hello VS Chat"); // Send to current conversation
// Sending message to specific conversation will be added next release.
A VSChat Server must be setup before you can utilize this pacakage