This package has been deprecated

Author message:

use 'emittery' instead

@throw-out-error/better-events
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Better Events

Better event emitters.

License: MIT

Installation

# pnpm
pnpm i @throw-out-error/better-events

# npm
npm i @throw-out-error/better-events

# Yarn
yarn add @throw-out-error/better-events

Example

In the server.js file:

const { RemoteEventEmitter } = require("@throw-out-error/better-events");
const net = require("net");

const server = net.createServer((socket) => {
    const connection = new RemoteEventEmitter(socket);

    connection.remoteEmit("ping");

    connection.on("pong", () => {
        console.log("pong");
    });
});

server.listen(8080);

In the client.js file:

const { RemoteEventEmitter } = require('@throw-out-error/better-events')
const net = require('net')

const socket = net.connect(8080)
const connection = new RemoteEventEmitter(socket)

connection.remoteEmit('pong')

connection.on('ping', () => {
    console.log('ping')
}

API

The RemoteEventEmitter extends the Connection class. This means that you can use the send method and the "message" event.

emitter.remoteEmit(event, ...args)

  • event <string> - The name of the event.
  • ...args <any> - Arguments for the event.

Emit an event on the EventEmitter on the other side of the socket connection. It returns a <boolean> that is true if the event was written to the socket.

Package Sidebar

Install

npm i @throw-out-error/better-events

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

23.8 kB

Total Files

17

Last publish

Collaborators

  • bayugoon
  • brenttrenholme
  • creepinson
  • sebastianspeitel