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

conversant-client-api

v1.0.2

Published

Javascript API for conversant.im apps.

Downloads

12

Readme

conversant-client-api

Javascript API for conversant.im apps. Write custom applications that allow you and your team to collaborate and store conversation and view state in context.

Index

Overview

This api relies on a streaming based approach. The underly data types describe the messages that can be pushed onto the stream or subscribed to react to when seen on the stream. The first part of this documentation will server to outline terminology used in the system, as well as illustrate the flow of data through the system architecture.

Terminology

Your application can exist in 2 states.

  • personal is the application state that each individual user sees the application in the application panel. This state is the workspace that is unique to each user as they prepare content to be collaborated on in the sync state.
  • sync is a shared application view that is common to all users that are present in the collaboration. Each users interactions to your app in the sync state should update all other views accordingly.

diagram

A word on restoring state.

Your application is responsible for reporting view state when a user enter messages into the chat stream. In addition users can restore state at the instance of a paticular chat message. Your application will receive this restore state and must respond to restore your applications state to the one reported.

Data flow.

You application is hosted in an iframe. Commonication with the iframe is brokered through the window.postMessage api. The main conversant application connects to the cluster via a websocket. Messages all have a strong type. These types are the basis for interacting with the system. For more information on the types that are available to use as a thirs party developer, view the types documentation.

  • host is the conversant.im site that maintains the websocket connection to the backend cluster.
  • application referse to all applications that are loaded in the personal or sync iframes. These applications are communicated with over the postMessage channel.

Data that enters the system via the websocket is pused to applications to react to. Additionally data that is pushed onto the stream will eventually make its way to the cluster via the websocket and results will be pushed down to the host and then made available to your application.

Usage

Node

npm install conversant-client-api

The use the require in your own module. ex:

let conversant = require('conversant-client-api')

Browser

To simply include the file in a web browser and use the window level api, you can include the bundle.js which includes everything you need to get running in a modern web browser.

<script src="bundle.js"></script>

Alternativly you can build the latest source using node with the following command.

node build.js

Getting Started

Register your application

TODO: docs on where and how to register your application with conversant.im NOTE: people will require SSL certs for self hosted applicatons NOTE: public vs. private apps NOTE: include the origin the app will be hosted on

The Code

A full reference of types and API documentation can be found here: http://conversant-im.github.io/conversant-client-api/docs.html

var conversant = new ConversantAPI();
conversant.init(function(appInit){
  var profile = appInit.profile; // This is of type m.Auth.ProfileInfo
  var collaboration = appInit.collaboration; // This is of type m.Collaboration.Collaboration
  var team = appInit.team; // This is of type m.Collaboration.SyncUserEvent[]
  var peers = appInit.peers; // This is of type m.Peers.PeerState[]
  
  // we can listen for types that our application can respond to like this.
  conversant.addResponder(m.Collaboration.SyncViewEvent.type(),function(sync){
    // sync will be of type m.Collaboration.SyncViewEvent
  });
  
  // alternatively if you prefer to deal with an Rx.Subscription directly
  // See documentation on RxJS for ways of working with subscriptions
  var subscription = conversant.addResponder(m.Collaboration.SyncViewEvent.type());
  
  
  // Here is an example of calling the API to add a guest account.
  var guest = new m.Auth.ProfileInfo(profile.orgId, 'email', '[email protected]', m.Auth.OrganizationRoles.guest(), 'Sponge Bob');
  
  conversant.addGuest(guest).then(function(primaryProfile){
    // addGuest returns a Promise that will be filled with m.Auth.PrimaryProfile
    var guestProfile = primaryProfile;   // type m.Auth.PrimaryProfile
  });
});

Word of Caution on Promise

Do not use Promise API when events happen in close time proximaty to one another. Use addResponder instead and filter the data for your expected result. Here is an example of what NOT TO DO.

var bob = new m.Auth.ProfileInfo(profile.orgId, 'email', '[email protected]', m.Auth.OrganizationRoles.guest(), 'Sponge Bob');
var patrick = new m.Auth.ProfileInfo(profile.orgId, 'email', '[email protected]', m.Auth.OrganizationRoles.guest(), 'Patrick');

conversant.addGuest(bob).then(function(primaryProfile){
  console.log('bob?',primaryProfile);
});
conversant.addGuest(patrick).then(function(primaryProfile){
  console.log('patrick?',primaryProfile);
});

// The order that these events will be serviced by the backend cluster is Not garenteed.  
// So for example it is possible that `patrick` returned before `bob` or `bob` then `patric`.
// In addition which ever one is returned first will fill BOTH promises.

The order that these events will be serviced by the backend cluster is Not garenteed. So for example it is possible that patrick returned before bob or bob then patric. In addition which ever one is returned first will fill BOTH promises. So for example if patric was returned first. You would get.

  • > bob? <patric object>
  • > patrick? <patric object>

If you need to predictably handle these you would do it as follows.

conversant.addResponder(m.Auth.PrimaryProfile.type(),function(profile){
  if( profile.primary.fullName == 'Sponge Bob' ){
    // do stuff..
  }else if(profile.primary.fullName == 'Patrick'){
    // other stuff
  }
});