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

@amazebot/rocket-socket

v0.1.1

Published

Communicate with Rocket.Chat Realtime API via websocket (DDP).

Downloads

9

Readme

🔌 Rocket Socket

Communicate with Rocket.Chat Realtime API via websocket (DDP).


Usage

See the main rocket-control README for general configuration.

This example script uses rocket-socket and rocket-sims to create a new bot user, connect to the general channel and stream all bot mentions to the console.

new Socket()

Accepts options object, or uses defaults from environment config. Attributes can include host string and ssl boolean.

Creates a websocket handler instance to manage the connection with Rocket.Chat.

import { Socket } from '@amazebot/rocket-socket'
const socket = new Socket()

.open() and .close()

Opens connection with Rocket.Chat. Returns promise.

Accepts option number of ms to attempt re-opening.

const socket = new Socket()
await socket.open()
await socket.close()

.login(credentials) and .logout()

Login can be called without explicit .open(), it will open the socket to login.

Login can be called without credentials to use the default user/pass from environment configs.

Login returns a credential object that can be used to resume login after closing and re-opening socket.

Login accepts a range of credential objects (including the resume object mentioned above):

Username/password:

{
  username: string
  password: string
}

Server credentials:

{
  user: { username: string }
  password: { digest: string, algorithm: string }
}

Oauth token:

{
  oauth: {
    credentialToken: string
    credentialSecret: string
  }
}

Resume token:

{
  resume: string
}

.connected and .loggedIn

Boolean attributes for confirming connection status.

.subscribe(name, params, callback)

Subscribe to any stream of events on the server, passing the stream name and params array as per Realtime API docs here: https://rocket.chat/docs/developer-guides/realtime-api/subscriptions/

The callback function will be called with every emitted event.

Subscribe method returns a subscription object, with the same attributes used to create it, along with an .id and .unsubscribe() method.

CLI Usage

Method calls can also be made over DDP manually through the CLI, using a method name and optional other parameters. Results will be printed to console. Requires the same config as above, with username/password as ENV or command line opts.

Locally with ts-node

Run pre-compiled locally, using

> ts-node src/cli --method getServerInfo

Outputs

{ result:
   { version: '0.73.2',
...

You can also pass params

> ts-node src/cli --method getRoomNameById --params GENERAL

Outputs

{ result: 'general' }

As a dependency with rocket-call

Run the compiled bin when installed as a dependency

> node_modules/bin/rocket-call --method getServerInfo

Or use the alias arguments for both method and params

> node_modules/bin/rocket-call -m getRoomNameById -p GENERAL

Could work as a global NPM package too.