Cisco Spark

SDK for JavaScript

Integrate Cisco Spark calling into your JavaScript applications quickly

Features

Integrate the JavaScript SDK in both Node.js and client-side applications. Place and receive video calls via the SDK:

  • Audio and/or video 1:1 calling
  • Dial by email or SIP address
  • Call and event controls
  • Audio and video call control
Getting Started Guide

In this example, we'll use Node.js to create a simple project that will post a message to a room.

Overview

  • Create a Spark Room
  • Post a Message

Requirements

  • Node.js and npm
  • Optionally: nvm to manage Node.js versions
  • Supported Browsers: Google Chrome (latest) or Mozilla Firefox (latest) for calling features
  • This SDK requires the spark:all scope

Important Notes

  • Calls made between Chrome and the iOS SDK or iOS client are not supported

Step 1: Create the Project Directory

cd /my/project/directory
npm init

You’ll be prompted to answer a few simple questions, but typically the defaults are just fine.

Step 2: Install the JavaScript SDK

Now, install ciscospark.

npm install --save ciscospark

Step 3: Start Using the SDK

So, you want to send a message. First, you need an access token. For demonstration purposes, we’ll use environment variables to authorize the SDK. If you're logged into this site, you can see your token by clicking on your avatar in the top right corner of this page. If not, log in or sign up to get your access token.

Create a new file in your project directory named index.js and add the following to it:

var spark = require('ciscospark');
spark.rooms.create({
  title: 'My First Room!'
})
  // Make sure to log errors in case something goes wrong.
  .catch(function(reason) {
    console.error(reason);
    process.exit(1);
  });

Now, open the Cisco Spark Web Client to you see your code in action. Then, back in your terminal, run the following command:

CISCOSPARK_ACCESS_TOKEN= node index.js

Check out the web client. You should see your new room. Now, let’s send a message to it.

Open up index.js again and replace its contents with the following code:

var spark = require('ciscospark');
spark.rooms.list({
  max: 10
})
  .then(function(rooms) {
  var room = rooms.items.filter(function (room) {
    return room.title === 'My First Room!';
  })[0];

  return spark.messages.create({
    text: 'Hello World!',
    roomId: room.id
  });
})
// Make sure to log errors in case something goes wrong.
.catch(function(reason) {
  console.error(reason);
  process.exit(1);
});

Run it again with the following:

CISCOSPARK_ACCESS_TOKEN=$YOUR_TOKEN_FROM_THE_PORTAL node index.js

Now check out the web client. Congrats! You’ve sent your first message!