npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socketio-chat

v1.0.2

Published

Simple way to implement a chat with socket.io

Downloads

10

Readme

#socketio-chat

You should use this project with vue-talk

Simple way to implement a chat with socket.io. This project give you a quick start and set everything you need to start a chat app.

Installation

$ npm install socketio-chat --save

Setup

//require socket.io

var SocketIOChat = require('socketio-chat');

io.on('connection', function (socket) {
	//Initiate the socketio-chat plugin
	SocketIOChat.install.call(this, socket, {
		//sets the current user
		user:{
			name: 'Valter Lorran',
			id: 1,
			image: 'img/img-01.png'
		}
	});

	//join a room 
	socket.socketIOChat.joinRoom('room-test');
});

Notice: when you install the plugin you'll be able to access the SocketIOChat object in socket.socketIOChat

Events

SocketIOChat sets the following events for you:

  • sendMessage: triggered when a user sends a message
  • disconnect: triggered when a user disconnects, this event is triggered automatically
  • startTyping: triggered when a user start typing
  • stopTyping: triggered when a user stop typing

In your client side you should have something like:

function sendMessage(message){
	socket.emit('sendMessage', {message:message});
}

function startTyping(){
	socket.emit('startTyping');
}

Each of these events trigger an event to the room that the user is in. And each of these events is sent with user_id(id that you set when you install the plugin in the socket) appended in the data object.

| Event | Triggers | | --- | --- | | when a user joins a room | userJoinendRoom | | sendMessage | userSentMessage | | startTyping | userStartedTyping | | stopTyping | userStoppedTyping | | disconnect | userDisconnect |

In your client side you should have something like:

socket.on('userSentMessage', function(data){
	var user_id = data.user_id;
	var message = data.message;
	alert('The user ' + user_id + ' sent a message: ' + message);
});

socket.on('userDisconnect', function(data){
	var user_id = data.user_id;
	alert('User ' + user_id + ' disconnected.');
});

Callback Before/After Event

You can add a callback before an event is trigger or after.

SocketIOChat.install.call(this, socket, {
	before_event:{
		sendMessage:function(socketIOChat, socket, data){

		}
	},
	after_event:{
		stopTyping:function(socketIOChat, socket, data){

		}
	},
	user:{/* */}
});

You can use it for save a message in the database for example.

##Personalization ###Custom emiters

You can set a custom name for the emits:

SocketIOChat.install.call(this, socket, {
	room_emiters:{
		userDisconnect:'user-got-disconnected',
		userStoppedTyping:'user-is-no-longer-typing'
	}
	user:{/* */}
});