1.0.8 • Published 1 year ago

node-hello-prayag v1.0.8

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
1 year ago

node-hello-prayag

A set of handlers for one-to-one chat functionality using Socket.io.

Installation

Install the package using npm:

npm install node-hello-prayag

Usage

First, require the package in your server file:

const { initUser, sendMessageHandler, startTyping, stopTyping, handleDisconnect } = require('node-hello-prayag');

Here is a complete example of how to set up a Socket.io server with these handlers:

const http = require('http');
const express = require('express');
const socketIo = require('socket.io');
const { initUser, sendMessageHandler, startTyping, stopTyping, handleDisconnect } = require('node-hello-prayag');

const app = express();
const server = http.createServer(app);
const io = socketIo(server);

// List of active users
const activeUsers = [];

io.on('connection', (socket) => {
    console.log('A user connected:', socket.id);

    // Initialize user
    socket.on('initUser', initUser(socket, io));
    
    // Handle sending messages
    socket.on('sendMessage', sendMessageHandler(socket, io));

    // Handle typing start
    socket.on('startTyping', startTyping(socket, io));

    // Handle typing stop
    socket.on('stopTyping', stopTyping(socket, io));

    // Handle user disconnection
    socket.on('disconnect', handleDisconnect(socket, io));
});

server.listen(3000, () => {
    console.log('Server is listening on port 3000');
});
1.0.8

1 year ago

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