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

circuit-sdk

v1.2.8401

Published

Circuit SDK

Downloads

68

Readme

Circuit JavaScript and Node.js SDK

GitHub release Build Status License

Prerequisites

  • Register for a free developer account and create your own OAuth app to get a client_id. See Getting Started for details.

API Reference

https://circuitsandbox.net/sdk/ with most APIs described in the Client class.

Usage

JavaScript

Add the the line below to the HTML file of your app. This will include the latest version of Circuit SDK and make the Circuit object available.

<script type="text/javascript" src="https://unpkg.com/circuit-sdk"></script>

JS SDK can also be imported via CommonJS or AMD. View the repo UMD for the different types of usage, or circuit-ionic-start for example how import the SDK via require using webpack.

Node.js

npm install --save circuit-sdk

Application Types

The majority of apps fall in one of the three types below. Each type uses a different OAuth 2.0 Grant.

  1. Client-side web applications use the JavaScript SDK with the OAuth 2.0 Implicit Grant.

    // No client_secret needed for Implicit Grant. SDK will obtain access token.
    const client = new Circuit.Client({
      client_id: '<your client_id>',
      domain: 'circuitsandbox.net'
    });
    client.logon()
      .then(user => console.log('Logged on as ' + user.displayName))
  2. Server-side web applications use the JavaScript SDK (or REST API) on the client, but handle the authentication flow on the server using the OAuth 2.0 Authorization Code Grant. The access token is obtained on the server and then passed to the client to use in the Circuit JavaScript SDK. These apps may also use the Node.js SDK on the server side to act on behalf of the user. Example apps: node-linkify or circuit-google-assistant

    // access token is obtained and managed by server-side app
    const client = new Circuit.Client({
      client_id: '<your client_id>',
      domain: 'circuitsandbox.net'
    });
    client.logon({accessToken: '<access_token>'})
      .then(user => console.log('Logged on as ' + user.displayName))
  3. Bots use the Node.js SDK or the REST API and use the OAuth 2.0 Client Credentials Grant. Bots are a special type of user; they don't login on behalf of a regular user, hence no OAuth popup asking for a user`s credentials and permissions. Example bots: xlator-bot or node-sdk-example Example electron bots: webrtc-bot-example or live-cam-bot

    const Circuit = require('circuit-sdk');
    const client = new Circuit.Client({
      client_id: '<client_id>',
      client_secret: '<client_secret>',
      domain: 'circuitsandbox.net'
    });
    client.logon()
      .then(user => console.log('Logged on as bot: ' + user.emailAddress))

Examples

JavaScript examples are located at /examples/js with more examples on jsbin.

Node.js example apps are on github. A summary is listed here. Runkit allows playing with Node.js modules live, similar to jsbin or jsfiddle on the client. Try it on runkit

Here are some snippets to get you started.

Create Group Conversation and send text message

Logon as bot, create a group conversation with two users and send a text message.

client.logon()
  .then(user => console.log(`Logged on as ${user.displayName}`, user))
  .then(() => client.getUsersByEmail(['[email protected]', '[email protected]']))
  .then(users => users.map(user => user.userId))
  .then(userIds => client.createGroupConversation(userIds, 'runkit example'))
  .then(conv => client.addTextItem(conv.convId, 'I am test bot. What can I do for you?'))
  .then(client.logout)
  .catch(console.error)

Get Conversations

Get 10 newest conversations of logged on user.

client.getConversations({numberOfConversations: 10})
  .then(conversations => console.log(`Retrieved ${conversations.length} conversations`))

Video call with another Circuit user

Start a video call with another user. Create conversation if not yet existing.

Only applicable to JavaScript SDK and only on browsers supporting WebRTC

client.makeCall('[email protected]', {audio: true, video: true}, true)
  .then(call => console.log('New call: ', call));

Listen for events

// Register new items added to the feed of this user. E.g. incoming text message
client.addEventListener('itemAdded', item =>
  console.log('itemAdded event received:', item));

// Register for connection state changes
client.addEventListener('connectionStateChanged', evt => {
  console.log(`New state is ${evt.state}`);
});

// Register and log all events
Circuit.supportedEvents.forEach(e => client.addEventListener(e, console.log));

Create an injector

Injectors allow extending the conversation, item and user objects within the SDK. In this example a new attribute teaser is created on the item object. This teaser will be added to item objects in any reponse or event from the SDK.

Circuit.Injectors.itemInjector = function (item) {
  if (item.type === Circuit.Enums.ConversationItemType.TEXT) {
    // Create item.teaser attribute with replacing br and hr tags with a space
    item.teaser = item.text.content.replace(/<(br[\/]?|\/li|hr[\/]?)>/gi, ' ');
  } else {
    item.teaser = item.type;
  }
};

Supported Browsers

Chrome and Firefox are officially supported.

Help us improve the SDK

Help us improve the SDK or examples by sending us a pull-request or opening a GitHub Issue.