1.0.7 • Published 1 year ago

@knfs-tech/bamimi-socket.io v1.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago