1.0.0-RC.0 • Published 4 years ago

convo-quantum-sdk v1.0.0-RC.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Convo Logo

Quantum SDK

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 0.10 or higher is required.

Installation is done using thenpm install command:

$ npm install convo-quantum-sdk

Import in ReactJS project:

import QuantumSdk from "convo-quantum-sdk";

Initializing QuantumSdk requires the mock server to e available for testing, check branch feature/PLT-74

Code for mock server is available here

Mock server is initialized by running command:

$ node index.js

Usage example:

import React from "react";
import "./App.css";
import QuantumSdk from "convo-quantum-sdk";

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <video id="remoteVideo" autoPlay />
        <video id="viVideo" autoPlay />
        <button onClick={initSdk}>Init SDK</button>
      </header>
    </div>
  );
}

export default App;

function initSdk() {
  QuantumSdk.builder()
    .withRemoteElementId("remoteVideo")
    .withViElementId("viVideo")
    .withPhoneNumber("2402066101")
    .withOnCalling(() => {
      alert("withOnCalling");
    })
    .withOnRinging(() => {
      alert("withOnRinging");
    })
    .withOnAccepted(() => {
      alert("withOnAccepted");
    })
    .withOnIncomingCall((callerNumber) => {
      alert("Incoming Call from: " + callerNumber);
    })
    .withOnHangUp(() => {
      alert("withOnHangUp");
    })
    .initSdk();
}

Enumarate devices & selecting specific device

/**
 * Returns an array of MediaDevices available
 * @param {QuantumSdk.MediaDeviceKind} kind 
 */
async function enumerateDevices(kind) {
  let devices = kind
    ? await QuantumSdk.enumerateDevices(kind)
    : await QuantumSdk.enumerateDevices();

  console.log(devices);
}

Yuo can reuse deviceId parameter from enumerateDevices() for selecting a specific device:

async function setVideoDevice() {
  const videoDevices = await QuantumSdk.enumerateDevices(
    QuantumSdk.MediaDeviceKind.VIDEOINPUT
  );

  const deviceId = videoDevices[0]["deviceId"];

  QuantumSdk.setVideoSource(deviceId);
}

async function setAudioInput() {
   const audioDevices = await QuantumSdk.enumerateDevices(
     QuantumSdk.MediaDeviceKind.AUDIOINPUT
   );
 
   const deviceId = audioDevices[0]["deviceId"];
 
   QuantumSdk.setAudioSource(deviceId);
}

async function setAudioOutput() {
  const audioDevices = await QuantumSdk.enumerateDevices(
    QuantumSdk.MediaDeviceKind.AUDIOOUTPUT
  );

  const deviceId = audioDevices[0]["deviceId"];

  QuantumSdk.setAudioSink(deviceId);
}

Make call and hang up

function makeCall(callConfiguration = {phoneNumber}) {
  QuantumSdk.makeCall(callConfiguration);
}

function answerCall() {
  QuantumSdk.answerCall();
}

function declineCall() {
  QuantumSdk.declineCall();
}

function hangUp() {
  QuantumSdk.hangUp();
}

Toggling media while in call

function toggleVideo() {
  QuantumSdk.toggleVideo();
}

function toggleMic() {
  QuantumSdk.toggleMic();
}
1.0.0-RC.0

4 years ago

0.1.0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago