🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

urbit

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urbit

Library to interact with an Urbit ship

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

Urbit Connector

This project allows you to connect to an Urbit ship via a JavaScript application.

Example

Start a new project, run npm install urbit and run the below, or run node.js from the root of this project.

const Urbit = require('urbit').default;

// Assuming
// a) you are running a fakezod on port 8080
// b) you have created a chat called 'mc' on that fakezod,
const url = 'localhost';
const port = 8080;
const code = 'lidlut-tabwed-pillex-ridrup';

async function mars() {
    const ship = new Urbit(`http://${url}:${port}`, code);
    await ship.connect();
    await ship.subscribe('zod', 'chat-store', '/mailbox/~/~zod/mc');
    const pipe = ship.eventSource();
    await ship.poke('zod', 'chat-hook', 'json', {message: {path: '/~/~zod/mc', envelope: {
        uid: Urbit.uid(),
        number: 1, // Dummy, gets overwritten immediately
        author: '~zod',
        when: new Date().getTime(),
        letter: { text: 'Hello, Mars!' }
    }}});
}

mars();
console.log('Press ctrl-c to quit');

Design

This library is designed to be useful for node applications that communicate with an urbit running either on the local computer or on a remote one.

The majority of its methods are asynchronous and return Promises. This is due to the non-blocking nature of JavaScript. If used in a React app, response handlers should be bound with this to setState after a message is received.

It uses the Axios library to polyfill the native JavaScript fetch which is only available in the browser context. It uses a similar approach to EventSource.

Future Work

Future features include:

  • Reworking the axios calls to use a fetch-compatible syntax
  • Adding handlers for sending chat messages with a simpler syntax
  • Browser-ready dist file (let me know if you have experience with this)
  • Better tracking of current subscriptions and acks

FAQs

Package last updated on 16 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts