0.1.4 • Published 1 year ago

gitplelive-voice-sdk v0.1.4

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

gitplelive-voice-sdk

Gitple Live Voice SDK

Table of Contents

  1. Install
  2. Import and Init
  3. Use
  4. Error
  5. Migration

Install

# npm
$ npm i gitplelive-voice-sdk

# yarn
$ yarn add gitplelive-voice-sdk

Import and Init

es6

import { VoiceClient } from 'gitplelive-voice-sdk';

const config = {
  host, // gitplelive api host (ex. live.example.com ), Without http:// or https:// or url path
  app_id,
  user_id,
  token
};

const gitpleLiveVoiceClient = new VoiceClient(config);

browser

<script src="./node_modules/gitplelive-voice-sdk/dist/voice.min.js"></script>

const config = {
  host,
  app_id,
  user_id,
  token
};

const gitpleLiveVoiceClient = new GitpleLiveVoice.VoiceClient(config);

Use

Get User Token

  • api
    • GET https://{Gitple Live API Host}/v1/voice/users/{USER_ID}/token
    • header
      {
        APP_API_KEY: 'APP API KEY',
        APP_ID: 'APP ID'
      }
    • response
      {
        token: 'TOKEN'
      }
    • expire: 24h

Init

  • Initialize the SDK.
try {
  const config = {
    host,
    app_id,
    user_id,
    token
  };
  // es6
  const gitpleLiveVoiceClient = new VoiceClient(config);

  // browser
  const gitpleLiveVoiceClient = new GitpleLiveVoice.VoiceClient(config);
} catch (error) {
  // handle error
}

Connect

  • Use to connect users to voice services.
try {
  await gitpleLiveVoiceClient.connectUser();
} catch (error) {
  // handle error
}

Disconnect

  • Use to terminate a voice service connection.
try {
  await gitpleLiveVoiceClient.disconnectUser();
} catch (error) {
  // handle error
}

Call

  • Use to make a call.
try {
  await gitpleLiveVoiceClient.call("{Other USER ID}");
} catch (error) {
  // handle error
}

Dial Up

  • Use to receive calls.
try {
  await gitpleLiveVoiceClient.dialUp();
} catch (error) {
  // handle error
}

Hang Up

  • Use to end or decline a call.
try {
  await gitpleLiveVoiceClient.hangUp();
} catch (error) {
  // handle error
}

Mute

  • Use it to mute my voice. Available after the call is connected.
try {
  await gitpleLiveVoiceClient.mute(true);
} catch (error) {
  // handle error
}

Unmute

  • Use to unmute. Available after the call is connected.
try {
  await gitpleLiveVoiceClient.mute(false);
} catch (error) {
  // handle error
}

Check Destination Session

  • Use to check that the destination session exists. Lets you determine if the destination is connected to the SDK.
    • Returns the boolean value. (true = session present, false = no session)
    • CAUTION! If multiple sessions are not created indiscriminately and explicitly disconnected, the session may remain. If possible, please use the 'disconnectUser()' function to explicitly terminate the connection.
try {
  const flag = await gitpleLiveVoiceClient.checkSession("{Other USER ID}");
  if (flag) {
    // handle
  } else {
    // handle
  }
} catch (error) {
  // handle error
}

Event Listener

// Received when the call is created.
gitpleLiveVoiceClient.on('call', (data) => {
  // data: { id: {Call ID}, status: {Call Status}, direction: {Call direction}, from: {User ID}, to: {User ID} }

  // handle event
});

// Received whenever the status of the call changes.
gitpleLiveVoiceClient.on('call_status_changed', (data) => {
  // data: { id: {Call ID}, status: {Call Status}, direction: {Call direction}, from: {User ID}, to: {User ID} }

  // handle event
});

Event Payload

  • payload

    {
      id: '{Call ID}',
      status: '{Call Status}',
      direction: '{Call direction}',
      from: '{User ID}',
      to: '{User ID}'
    }
  • status

    statusdesc
    startedThe call connection has been started
    ringingThe destination has confirmed that the call is ringing. It may be missing depending on the situation of the destination.
    answeredThe destination has answered the call
    completedThe call is completed successfully
    failedThe call connection failed
    rejectedThe call attempt was rejected by the destination
    unansweredThere is no response to the call connection from the server
    • call flow
      • nomal: started -> ringing (optional) -> answered -> completed
      • exception: started -> ringing(optional) -> unanswered | rejected | failed
  • direction

    directiondesc
    outboundOutgoing call
    inboundincoming call

Error

Payload

{
  code: number;
  name: string;
  message: string;
  stack: string;
}

Code

codenameDesc
80101invalid_parameterInvalid Parameter
80102not_found_user_session_idUser Session ID Not Found
80103same_caller_and_destinationSame caller and destination
80201already_connected_sessionAlready Connected Session
80202already_busy_callAlready Busy Call
80401invalid_tokenInvalid Token
80402no_connected_sessionNo Connected Session
80403no_connected_callNo Connected Call
80404no_connected_destinationDestination is not connected
80801not_found_deviceDevice Not Found (microphone)
80802permission_deniedPermission Denied (microphone)
80999unknown_errorUnknown Error. Please contact us at Gitple

Migration

Migration guide from SDK 0.0.x to 0.1.X

  • Initialize the SDK.

    • The host field has been added to the initialization information.

      try {
        const config = {
          host,  // Added Fields
          app_id,
          user_id,
          token
        };
        // es6
        const gitpleLiveVoiceClient = new VoiceClient(config);
      
        // browser
        const gitpleLiveVoiceClient = new GitpleLiveVoice.VoiceClient(config);
      } catch (error) {
        // handle error
      }
0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago