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

getsocket-core

v1.0.0

Published

p2p db functions for chat

Downloads

5

Readme

socket-core

Core database, replication, swarming, and chat APIs for socket.

Usage

npm install socket-core

API

var Socket = require('socket-node')

var socket = Socket([storage][, uriString][, opts])

Create a socket p2p database using storage storage, which must be either a string (filepath to directory on disk) or an instance of random-access-storage.

uriString is a socket URI string, of the form socket://<hexkey>[?param1=value1&param2=value2. A hexidecimal key on its own will also be understood.

If this is a new socket, key can be omitted and will be generated.

You can pass opts.db as a levelup or leveldown instance to use persistent storage for indexing instead of using memory. For example:

var level = require('level')
var socket = Socket(storage, key, { db: level('/tmp/bot.db') })

socket.getLocalKey(cb)

Returns the local user's key (as a hex string).

var ds = socket.replicate()

Creates a new, live replication stream. This duplex stream can be piped into any transport expressed as a node stream (tcp, websockets, udp, utp, etc).

socket.ready(cb)

Call cb() when the underlying indexes are caught up.

Channels

socket.channels.get(function (error, channels) {})

Retrieve a list of all channel names that exist in this socket.

socket.channels.events.on('add', function (channel) {})

Emitted when a new channel is added to the socket.

Messages

var rs = socket.messages.read(channel, opts)

Returns a readable stream of messages (most recent first) from a channel.

Pass opts.limit to set a maximum number of messages to read.

socket.messages.events.on('message', fn)

Calls fn with every new message that arrives, regardless of channel.

socket.messages.events.on(channel, fn)

Calls fn with every new message that arrives in channel.

Network

var swarm = require('socket-core/swarm')

socket.swarm(cb)

Joins the P2P swarm for a socket. This seeks out peers who are also part of this socket by various means (internet, local network), connects to them, and replicates socket messages between them.

The returned object is an instance of discovery-swarm.

socket.on('peer-added', function (key) {})

Emitted when you connect to a peer. key is a hex string of their public key.

socket.on('peer-dropped', function (key) {})

Emitted when you lose a connection to a peer. key is a hex string of their public key.

Moderation

socket has a subjective moderation system.

The three roles are "admin", "moderator", and "ban/key".

Any admin/mod/ban operation can be per-channel, or socket-wide (the @ group).

Every user sees themselves as an administrator across the entire socket. This means they can grant admin or moderator powers to anyone, and ban anyone, but only they will see its affects on their own computer.

A socket can be instantiated with a moderation key. This is an additional key to locally consider as a socket-wide administrator (in addition to yourself).

This means that if a group of people all specify the same moderation key, they will collectively see the same set of administrators, moderators, and banned users.

var rs = socket.moderation.listBans(channel)

Return a readable objectMode stream of bans for channel.

Each ban is an object with either a key or ip property.

To list socket-wide bans use the special channel @.

socket.moderation.isBanned({ ip, key, channel }, cb)

Determine whether a user identified by ip and/or key is banned on channel or socket-wide as cb(err, banned) for a boolean banned. If channel is omitted, only check socket-wide.

Publishing

socket.publish(message, opts, cb)

Publish message to your feed. message must have a type field set. If not, it defaults to chat/text. In general, a message is formatted as

{
  type: 'chat/text',
  content: {
    text: 'hello world',
    channel: 'socket-dev'
  }
}

A timestamp field is set automatically with the current system time.

type is an unrestricted field: you can make up new message types and clients will happily ignore them until someone implements support for them. Well documented types include

chat/text

{
  type: 'chat/text',
  content: {
    text: 'whatever the user wants to say',
    channel: 'some channel name. if it didnt exist before, it does now!'
  }
}

mod/{add,remove}

{
  type: '"mod/add" or "mod/remove"',
  content: {
    key: 'hex string key of the user to add/remove as mod',
    channel: 'channel name as a string or "@" for socket-wide'
    role: '"admin", "mod", or a custom role string'
  }
}

ban/{add,remove}

{
  type: '"ban/add" or "ban/remove"',
  content: {
    key: 'hex string key of the user to ban/unban',
    channel: 'channel name as a string or "@" for socket-wide'
  }
}

License

AGPLv3