1.0.7 • Published 2 years ago

express-io-chat v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Chat Package

A package you can use to create a Chat with express and socket.io

Create a database

Create a file with this json content in it

{
  "users": {},
  "rooms": {}
}

Class Documentation

Setup

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const socketChat = require('socket.io-chat');
const Chat = new socketChat.Chat(app, {
  file: "./chat.json"
} // options that always will be the same, {
  messageCharacterLimit: 200, // Limit of characters of a message
  roomNameCharacterLimit: 30, // Limit of characters of a room name
  usernameCharacterLimit: 20, // Limit of characters of a username
} // options that can be defined and overwrited for each single request);

io.on('connection', (socket, name) => {});

Default options

Message Limit

Unlimited

Room Name Character Limit

Unlimited

Username Character Limit

Unlimited

Create Room

socket.on("createRoom", (options) => {
  const result = Chat.rooms({
    roomNameCharacterLimit: 50 // other options you can use to overwrite the options of the class
  }).create(socket.id, options, { roomNameCharacterLimit: 40 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Edit Room

socket.on("editRoom", (options) => {
  const result = Chat.rooms({
    roomNameCharacterLimit: 50 // other options you can use to overwrite the options of the class
  }).edit(socket.id, options, { roomNameCharacterLimit: 40 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Delete Room

socket.on("deleteRoom", (options) => {
  const result = Chat.rooms({
    // other options you can use to overwrite the options of the class, but there are currently no 
  }).delete(socket.id, options, { // this options can overwrite the other options, but there are currently no  });
  socket.emit(socket.id, result);
});

Get Room

socket.on("getRoom", (options) => {
  const result = Chat.rooms({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).get(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

All Rooms

socket.on("allRooms", (options) => {
  const result = Chat.rooms({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).all(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

Send Message

socket.on("sendMessage", (options) => {
  const result = Chat.messages({
    messageCharacterLimit: 20 // other options you can use to overwrite the options of the class
  }).send(socket.id, options, { messageCharacterLimit: 15 // this options can overwrite the other options });
  socket.emit(socket.id, result);
});

Edit Message

socket.on("editMessage", (options) => {
  const result = Chat.messages({
    messageCharacterLimit: 20 // other options you can use to overwrite the options of the class
  }).edit(socket.id, options, { messageCharacterLimit: 15 // this options can overwrite the other options });
  socket.emit(socket.id, result);
});

Delete Message

socket.on("deleteMessage", (options) => {
  const result = Chat.messages({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).delete(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

Get Message

socket.on("getMessage", (options) => {
  const result = Chat.messages({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).get(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

Create User

socket.on("createUser", (options) => {
  const result = Chat.users({
    usernameCharacterLimit: 15 // other options you can use to overwrite the options of the class
  }).create(socket.id, options, { usernameCharacterLimit: 25 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Edit User

socket.on("editUser", (options) => {
  const result = Chat.users({
    usernameCharacterLimit: 15 // other options you can use to overwrite the options of the class
  }).edit(socket.id, options, { usernameCharacterLimit: 25 } // this options can overwrite the other options);
  socket.emit(socket.id, result);
});

Delete User

socket.on("deleteUser", (options) => {
  const result = Chat.users({
    // other options you can use to overwrite the options of the class, but there are currently no 
  }).delete(socket.id, options, { // this options can overwrite the other options, but there are currently no  });
  socket.emit(socket.id, result);
});

Get User

socket.on("getUser", (options) => {
  const result = Chat.users({
    // other options you can use to overwrite the options of the class, but there are currently no
  }).get(socket.id, options, { // this options can overwrite the other options, but there are currently no });
  socket.emit(socket.id, result);
});

HTML Client Side Documentation

Setup

<script src="/socket.io-chat/socket.io-chat.js">

Configuration

const socket = io();
const chat new Chat(socket);

Create Room

Chat.rooms().create(options);

Edit Room

Chat.rooms().edit(options);

Delete Room

Chat.rooms().delete(options);

Get Room

Chat.rooms().get(options);

All Rooms

Chat.rooms().all();

Send Message

Chat.messages().send(options);

Edit Message

Chat.messages().edit(options);

Delete Message

Chat.messages().delete(options);

Get Message

Chat.messages().get(options);

Create User

Chat.users().create(options);

Edit User

Chat.users().edit(options);

Delete User

Chat.users().delete(options);

Get User

Chat.users().get(options);

Functions

[
  isURL,
  configRooms,
  createRoom,
  editRoom,
  deleteRoom,
  getRoom,
  allRooms,
  joinRoom,
  leaveRoom,
  sendMessage,
  editMessage,
  deleteMessage,
  getMessage,
  createUser,
  editUser,
  deleteUser,
  getUser,
  isURLSync,
  configRoomsSync,
  createRoomSync,
  editRoomSync,
  deleteRoomSync,
  getRoomSync,
  allRoomsSync,
  joinRoomSync,
  leaveRoomSync,
  sendMessageSync,
  editMessageSync,
  deleteMessageSync,
  getMessageSync,
  createUserSync,
  editUserSync,
  deleteUserSync,
  getUserSync
]

Classes

[
  Chat,
  RoomManager,
  MessageManager,
  UserManager,
  UtilManager,
  FunctionManager
]

Types

{
  "Types": {
    "Managers": {
      "Rooms": "rooms",
      "Messages": "messages",
      "Users": "users",
      "Util": "util",
      "Functions": "functions"
    }
  }
}
1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago