Skip to content

knfs-library/bamimi-socket.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Build Status

About Bamimi socket.io

This package was developed to make using sockets easier because:

  • Using router-like implementation in Express makes it easy for you to develop
  • Can write functions as functions or divide into Controllers / Services

Install

npm i @knfs-tech/bamimi-socket.io
#or
yarn add @knfs-tech/bamimi-socket.io

Usage

Step 1: Create file config.js

module.exports = {
   cors: {
   	origin: "*",
   	transports: ['websocket', 'polling'],
   },
   transports: ['websocket', 'polling'],
   ...
};

Note: You can see more information at socket.io

Step 2: Create file index.js

const { createServer } = require('node:http');
const config = require("/path/to/your-config")
const socket = require("@knfs-tech/bamimi-socket.io")
const express = require("express");
const app = express();
const server = createServer(app);

socket.io(server, config)


const connection = (io, socket) => {
	console.log("____Connection___")
}

socket.on(
	'/abc',
	function (socket, next) {
		console.log("___Middleware 1 socket___")
		next()
	},
	function (socket, next) {
		console.log("___Middleware 2 socket___")
		next()
	},
	function (socket, next) {
		console.log("___Middleware 3 socket___-")
		next()
	},
	connection
)

server.listen(3001, () => {
	console.log(`server running at http://localhost:3001`);
})

Step 3: Run file index.js

npm start
#or
node index.js
#or
yarn start

Author

Owner

License

Bamimi is open-sourced software licensed under the MIT license.

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •