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

gossiphaus

v1.2.4

Published

Easy integration with the gossip inter-MUD communication protocol

Downloads

5

Readme

gossiphaus

Integration for the gossip MUD protocol, a scrappy start-up inter-MUD communication protocol.

Installation

npm install gossiphaus

Debugging

Run with DEBUG=gossiphaus to see debug messages:

$ DEBUG=gossiphaus node example.js

Example

const gossip = require('../index')

run()

async function run() {
  try {
    // initialize with a configuration object.  your client_id and
    // client_secret are the minimum required parameters.
    let emitter = gossip.init({
      client_id: '12345678-1234-1234-1234-123456789abc',
      client_secret: '12345678-1234-1234-1234-123456789abc'
    })

    // catch asynchronous errors
    emitter.on('error', (err) => {
      console.log(err.stack)
    })

    // handle channel broadcasts
    emitter.on('channels/broadcast', (payload) => {
      console.log(payload)
    })

    // handle tells
    emitter.on('tells/receive', (payload) => {
      console.log(payload)
    })

    // connect to gossip and retrieve current game status
    await gossip.connect()

    // an array of other games connected to the gossip network with their
    // currently authenticated players
    console.log(gossip.games)  

    // notify gossip of a new player authenticated into your game
    let result = await gossip.addPlayer('SomePlayer')

    // subscribe your game to the 'secrets' channel
    result = await gossip.send('channels/subscribe', {
      channel: 'secrets'
    })

    // send a message to the 'secrets' channel
    result = await gossip.send('channels/send', {
      channel: 'secrets',
      name: 'SomePlayer',
      message: 'shhh'
    })

    // unsubscribe from the 'secrets' channel
    result = await gossip.send('channels/unsubscribe', {
      channel: 'secrets'
    })

    // returns {name: 'SomeOtherPlayer', game: 'SomeGame'} if that remote
    // player identifier is currently signed in on the remote game
    result = gossip.findPlayer('someotherplayer@somegame')

    // send a tell to a remote user
    result = await gossip.send('tells/send', {
      from_name: 'SomePlayer',
      to_game: 'SomeGame',
      to_name: 'SomeOtherPlayer',
      sent_at: new Date(),
      message: 'test'
    })

    // true
    console.log('isAlive: ' + gossip.isAlive())

    // notify gossip of a new player logged out of your game
    result = await gossip.removePlayer('SomePlayer')

    // forcibly close the connection
    gossip.close()

    // false
    console.log('isAlive: ' + gossip.isAlive())

  } catch (err) {
    console.log(err.stack)
  }
}

API

gossiphaus.init(config)

Initializes gossiphaus configuration. Returns an event emitter object that will report asynchronous errors. You should listen for the error event of this emitter object to catch asynchronous errors (ie. socket unexpectedly closed, reconnection failures).

  • config.client_id {string} Your game's gossip client_id (required)
  • config.client_secret {string} Your game's gossip client_secret (required)
  • config.statusWait {Number} How long to wait and collect status messages on connect before resolving (in ms), default: 100
  • config.url {string} gossip websocket url, default: wss://gossip.haus/socket
  • config.supports {Array.} Supported methods, default: ['channels', 'players', 'tells']
  • config.channels {Array.} Channels to subscribe to, default: ['testing', 'gossip']
  • config.version {string} API version number to use, default not set
  • config.user_agent {string} Game user agent, default not set

async gossiphaus.connect()

Connects to gossip, authenticates, and gets the status of current remotely connected games. Returns a promise that resolves after config.statusWait. The delay allows remote game status to accumulate and be available when the promise resolves.

async gossiphaus.close()

Closes the connection with gossip. Sends sign-off messages for each locally connected player gossiphaus knows about. Connection can be re-established with gossiphaus.connect().

async gossiphaus.send(event, payload, ref = true)

Sends an event to gossip. See the documentation for information on the messages that can be sent. Returns a promise that resolves with the acknowledgement packet.

  • event {string} The gossip event name (required)
  • payload {Object} The gossip event payload object (required)
  • ref {boolean} If a ref id should be generated with this request, default: true

async gossiphaus.addPlayer(name)

Adds a player to your local game and informs the gossip network. This should be called when a user logs in to your game. You should use this method instead of calling send('players/sign-in') directly so that heartbeat responses have an up-to-date player list.

  • name {string} The player's name (required)

async gossiphaus.removePlayer(name)

Removes a player from your local game and informs the gossip network. This should be called when a user logs out of your game. You should use this method instead of calling send('players/sign-out') directly so that heartbeat responses have an up-to-date player list.

  • name {string} The player's name (required)

gossiphaus.findPlayer(rpi)

Verifies that a remote player identifier (ie. someplayer@somegame) is logged in. Case-insensitive but returns the proper capitalization. Useful when targeting remote players (ie. a remote tell command). Returns an object of the form {name: 'SomePlayer', game: 'SomeGame'}.

  • rpi {string} The remote player identifier, ie. someplayer@somegame (required)

gossiphaus.isAlive()

Returns true if we are connected and authenticated to gossip and ready to send messages.

gossiphaus.games

An array of remote game objects. This object will be initialized as part of the connect() method and will be kept in sync when remote players/sign-in and players/sign-out messages are received. The config.statusWait parameter controls how long to wait for this object to be populated.