Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vonage/client-sdk

Package Overview
Dependencies
Maintainers
47
Versions
247
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/client-sdk - npm Package Compare versions

Comparing version 1.1.0-alpha.10 to 1.1.0-alpha.12

snippet.js

123

dist/client/VonageClient.d.ts

@@ -22,2 +22,3 @@ import vonage from '../utils/vonage';

export declare const SessionErrorReason: typeof vonage.SessionErrorReasonJS;
export type Leg = vonage.LegJS;
export type LegStatus = vonage.LegStatusJS;

@@ -45,7 +46,2 @@ export declare const LegStatus: typeof vonage.LegStatusJS;

export declare class VonageClient extends vonage.CombinedClientJS {
/**
* Proxy object to allow for registering callbacks via `on()`
* @internal
*/
private callbacks;
constructor();

@@ -55,2 +51,5 @@ /**

*
* @example
* [[include:register_listener.txt]]
*
* @param event - the event to register for (e.g. 'legStatusUpdate')

@@ -67,2 +66,5 @@ * @param callback - the callback to register for the event

*
* @example
* [[include:unregister_listener.txt]]
*
* @param event - the event to register for (e.g. 'legStatusUpdate')

@@ -78,3 +80,6 @@ * @param callbackSymbol - the callback symbol to unregister

*
* @param event - the event to register for (e.g. 'legStatusUpdate')
* @example
* [[include: clear_callbacks.txt]]
*
* @param event - the event to unregister from (e.g. 'legStatusUpdate')
* @returns void

@@ -85,6 +90,2 @@ *

*
* @example
* ```ts
* client.clearCallbacks('legStatusUpdate');
* ```
*/

@@ -98,2 +99,5 @@ clearCallbacks<T extends keyof VonageEvent>(event: T): void;

*
* @example
* [[include:create_session.txt]]
*
* @param token

@@ -105,5 +109,24 @@ * @param sessionId - optional sessionId to use

/**
* Get the Peer Connection for a call
*
* @experimental
* @group Voice
* @param id - The Call Id
*/
getPeerConnection(id: string): RTCPeerConnection;
/**
* Get the Leg for a call
*
* @group Voice
* @param legId - The Leg Id
*/
getLeg(legId: string): Promise<Leg>;
/**
* Make a server call to the Vonage API.
* This is used to initiate a call using the Voice API and NCCO.
*
* @example
* [[include:outbound_call.txt]]
*
* @group Voice
* @param context - the context to send to the server passed as Custom data to the voice answer webhook

@@ -116,5 +139,6 @@ * @returns the `callId` of the call

*
* @remarks
* this is a convenience method that calls `hangupWithReason` with
* @example
* [[include:call_hangup.txt]]
*
* @group Voice
* @param callId - the `callId` of the call to hangup

@@ -128,2 +152,4 @@ * @param reasonText - optional reason text to send to the other party

* Sends a TTS message to the Call
*
* @group Voice
* @param callId - the `callId` of the call to send the message to

@@ -136,2 +162,7 @@ * @param text - the text to send

* Sends a TTS message to the Call
*
* @example
* [[include:call_say.txt]]
*
* @group Voice
* @param callId - the `callId` of the call to send the message to

@@ -145,2 +176,7 @@ * @param params - the `CallSayParams` to send

*
* @example
* [[include:get_conversations.txt]]
*
* @group Chat
* @beta
* @param order - the order to return the conversations in (default: 'asc')

@@ -155,2 +191,7 @@ * @param pageSize - the number of conversations to return per page (default: 100)

*
* @example
* [[include:get_conversation_events.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -165,2 +206,8 @@ * @param order - the order to return the events in (default: 'asc')

* Get a Conversation's Members
*
* @example
* [[include:get_conversation_members.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -175,2 +222,8 @@ * @param order - the order to return the members in (default: 'asc')

* Create a conversation
*
* @example
* [[include:create_conversation.txt]]
*
* @group Chat
* @beta
* @param name - the name of the conversation

@@ -183,2 +236,6 @@ * @param displayName - the display name of the conversation

* Get a Conversation
*
* @example
* [[include:get_conversation.txt]]
*
* @param id - the Conversation's id

@@ -190,2 +247,8 @@ * @returns the `Conversation`

* Leave a Conversation
*
* @example
* [[include:leave_conversation.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -197,2 +260,8 @@ * @returns void

* Join a Conversation
*
* @example
* [[include:join_conversation.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -204,2 +273,8 @@ * @returns the `memberId` of the member

* Delete a Conversation
*
* @example
* [[include:delete_conversation.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -211,2 +286,8 @@ * @returns void

* Invite a user to a Conversation by user's `name`
*
* @example
* [[include:invite_to_conversation.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -219,2 +300,8 @@ * @param name - the namne of the user to invite

* Send a text message to a Conversation
*
* @example
* [[include:send_text_message.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -227,2 +314,8 @@ * @param text - the Body of the message

* Send a custom message to a Conversation
*
* @example
* [[include:send_custom_message.txt]]
*
* @group Chat
* @beta
* @param id - the Conversation's id

@@ -235,2 +328,8 @@ * @param customData - the body of the message

* Get a Member of a Conversation
*
* @example
* [[include:get_conversation_member.txt]]
*
* @group Chat
* @beta
* @param cid - the Conversation's id

@@ -237,0 +336,0 @@ * @param mid - the Member's id

@@ -7,4 +7,9 @@ import './kotlin/clientsdk-clientcore_js';

* Mute your leg of a call
*
* @example
* [[include:call_mute.txt]]
*
* @param callId - Call ID
* @returns void
* @group Voice
*/

@@ -16,2 +21,3 @@ mute(callId: string): Promise<void>;

* @returns void
* @group Voice
*/

@@ -21,4 +27,9 @@ unmute(callId: string): Promise<void>;

* Earmuff your leg of a call
*
* @example
* [[include:earmuff_event.txt]]
*
* @param callId - Call ID
* @returns void
* @group Voice
*/

@@ -30,15 +41,52 @@ enableEarmuff(callId: string): Promise<void>;

* @returns void
* @group Voice
*/
disableEarmuff(callId: string): Promise<void>;
}
interface CoreClientJS {
/**
* Get the peer connection for a call
* Send a string of digits to a call via DTMF
*
* @internal
* @param id - Call ID
* @example
* [[include:send_dtmf_digits.txt]]
*
* @param callId - Call ID
* @param digits - DTMF digits
* @returns void
* @group Voice
*/
getPeerConnection(id: string): RTCPeerConnection;
sendDTMF(callId: string, digits: string): Promise<void>;
/**
* Answer a call
*
* @example
* [[include:answer_call.txt]]
*
* @param callId - Call ID
* @returns void
* @group Voice
*/
answerCall(callId: string): Promise<void>;
/**
* Reject a call
*
* @example
* [[include:reject_call.txt]]
*
* @param callId - Call ID
* @returns void
* @group Voice
*/
rejectCall(callId: string): Promise<void>;
/**
* Reconnect a call
*
* @example
* [[include:reconnect_call.txt]]
*
* @param callId - Call ID
* @returns void
* @group Voice
*/
reconnectCall(callId: string): Promise<void>;
}
}
}
import vonage from '../utils/vonage';
export declare const ConfigRegion: typeof vonage.CoreClientConfigRegionJS;
/**
* Represents the configuration object for the client.
*
* The `ClientConfig` class provides a convenient way to configure the client by specifying various properties.
* These properties control different aspects of the client's behavior, such as API URLs, media reoffer, and WebSocket settings.
*
* @example
* [[include:set_client_config.txt]]
*/
export declare class ClientConfig extends vonage.CoreClientConfigJS {
/**
* Constructs a new instance of the class.
*
* @param {string} region The region where the API and WebSocket URLs should be configured.
* Valid values are "EU" (Europe), "US" (United States), or "AP" (Asia Pacific).
* The URLs will be automatically set based on the selected region.
* Defaults to "US" if no region is specified.
*/
constructor(region?: vonage.CoreClientConfigRegionJS);
}

6

package.json
{
"name": "@vonage/client-sdk",
"version": "1.1.0-alpha.10",
"version": "1.1.0-alpha.12",
"description": "",

@@ -24,5 +24,7 @@ "type": "module",

"build:rollup": "rollup -c",
"build:readme": "chmod +x ./docs/generate_readme.sh; ./docs/generate_readme.sh",
"snippets": "node snippet.js $PWD",
"start": "node dist/Client.js",
"build:watch": "tsc -w",
"check": "tsc ./examples/* --noEmit --skipLibCheck --strictNullChecks true",
"check": "tsc ./examples/*.ts --noEmit --skipLibCheck --strictNullChecks true",
"lint": "eslint . --ext .ts",

@@ -29,0 +31,0 @@ "lint:fix": "eslint . --ext .ts --fix",

@@ -1,5 +0,9 @@

# Vonage Voice SDK
# Vonage Client SDK
The Client SDK is intended to provide a ready solution for developers to build Programmable Conversation applications across multiple Channels including: Messages, Voice, SIP, websockets, and App.
> **⚠️ Warning:** Chat Functionality (Beta)
>
> The chat functionality in our SDK is currently in beta. Methods related to chat may undergo changes as we refine and improve this feature. Please be aware of potential updates as we work towards its stability. Your feedback is valuable in shaping its development.
## Installation

@@ -9,3 +13,3 @@

```
```bash
npm i @vonage/client-sdk

@@ -16,22 +20,43 @@ ```

### With budler (webpack or vite)
### With bundler (Webpack, Vite, etc.) and React
```js
import './App.css';
import { VoiceClient, ClientConfig, ConfigRegion } from '@vonage/client-sdk';
import VoiceClient, { ClientConfig, ConfigRegion } from '@vonage/client-sdk/voice'; // NextJS/Webpack users see note below
import { VonageClient, ClientConfig, ConfigRegion } from '@vonage/client-sdk';
import { useState, useEffect } from 'react';
const client = new VoiceClient();
function App() {
// Config is optional but recomended, default region is US
const [config] = useState(() => new ClientConfig(ConfigRegion.US));
const [client] = useState(() => {
const client = new VonageClient();
client.setConfig(config);
return client;
});
const [session, setSession] = useState();
const [user, setUser] = useState();
const [error, setError] = useState();
// Config is optional but recomended, default region is US
const config = new ClientConfig(ConfigRegion.US);
client.setConfig(config);
// Create Session as soon as client is available
useEffect(() => {
if (!client) return;
client
.createSession('my-token')
.then((session) => setSession(session))
.catch((error) => setError(error));
}, [client]);
function App() {
const createSession = async () => {
const token = 'my-token';
await client.createSession(token);
};
// Get User as soon as a session is available
useEffect(() => {
if (!client || !session) return;
client
.getUser('me')
.then((user) => setUser(user))
.catch((error) => setError(error));
}, [client, session]);
return <button onClick={createSession}> create session </button>;
if (error) return <pre>{JSON.stringify(error)}</pre>;
if (!session || !user) return <div>Loading...</div>;
return <div>User {user.displayName || user.name} logged in</div>;
}

@@ -42,4 +67,2 @@

- **Node**: We have a known issue with NextJS / Webpack that means the main import from `@vonage/client-sdk` doesn't work, however if you import from `@vonage/client-sdk/voice` the voice client successfully imports. we are working on a fix.
### With script tag (UMD)

@@ -49,6 +72,6 @@

<!-- <script src="./node_modules/@vonage/client-sdk/dist/vonageClientSDK.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@vonage/client-sdk@0.1.4/dist/vonageClientSDK.min.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@vonage/client-sdk@1.0.0/dist/vonageClientSDK.min.js"></script> -->
<script src="./node_modules/@vonage/client-sdk/dist/vonageClientSDK.min.js"></script>
<script>
const token = 'some-token';
const token = 'my-token';
const client = new vonageClientSDK.VoiceClient();

@@ -68,8 +91,8 @@ const config = new vonageClientSDK.ClientConfig(

import {
VoiceClient,
VonageClient,
ClientConfig,
ConfigRegion
} from 'https://cdn.jsdelivr.net/npm/@vonage/client-sdk@0.1.4/dist/vonageClientSDK.esm.min.js';
} from 'https://cdn.jsdelivr.net/npm/@vonage/client-sdk@1.0.0/dist/vonageClientSDK.esm.min.js';
const client = new VoiceClient();
const client = new VonageClient();

@@ -80,16 +103,145 @@ // Config is optional but recomended, default region is US

const token = 'my-token';
client
.createSession(token)
.then((sessionId) => console.log(sessionId))
.catch((err) => console.log(err));
(async () => {
const token = 'my-token';
try {
// Create Session
const sessionId = await client.createSession(token);
// Get User
const user = await client.getUser('me');
console.log(
`User ${
user.displayName || user.name
} logged in with session ID: ${sessionId}`
);
} catch (error) {
// Log errors for either createSession or getUser
console.error(error);
}
})();
```
## Example Usage
Below are several typical scenarios where the SDK is commonly utilized.
### Make an Outbound Call
```ts
const call = await client.serverCall({
customData: {
callee: 'bob',
type: 'app'
}
});
console.log(call);
```
### Answer/Reject an Inbound Call
```ts
// Answer Call
client.on(
'callInvite',
async (callId: string, from: string, channelType: string) => {
client.answerCall(callId);
console.log(callId, from, channelType);
}
);
// ----
// Reject Call
client.on(
'callInvite',
async (callId: string, from: string, channelType: string) => {
client.rejectCall(callId);
console.log(callId, from, channelType);
}
);
```
### Hang-up and Collect Stats
```ts
// await client.hangup(call);
await client.hangup(call, 'reason-text', 'reason-code');
client.on('callHangup', async (callId: string, callQuality: RTCQuality) => {
if (callId == call) {
console.log(`Call ${callId} has hanged up, callQuality:${callQuality}`);
}
});
```
### Get Conversations
```ts
try {
let cursor: string | undefined | null = undefined;
const pageSize = 10;
const conversations: Conversation[] = [];
do {
const response: ConversationsPage = await client.getConversations(
PresentingOrder.ASC,
pageSize,
cursor
);
conversations.push(...response.conversations);
cursor = response.nextCursor;
} while (cursor !== null);
console.log(`Conversations successfully fetched: ${conversations}`);
} catch (e) {
console.log(`Error in fetching Conversations: ${e}`);
}
```
### Send Text Messages
```ts
try {
const timestamp = await client.sendTextMessage(
'conversationId',
'Hello there'
);
console.log(`Message successfully sent with timestamp ${timestamp}`);
} catch (e) {
console.log(`Error in sending Message: ${e}`);
}
```
### Listen for Conversation Events
```ts
client.on('conversationEvent', async (event) => {
if (event instanceof MemberInvitedEvent) {
console.log(
`User ${event.body.invitee.name} invited by ${event.body.inviter?.name} to Conversation ${event.conversationId}`
);
} else if (event instanceof MemberJoinedEvent) {
console.log(
`User ${event.body.user.name} joined Conversation ${event.conversationId}`
);
} else if (event instanceof MemberLeftEvent) {
console.log(
`User ${event.body.user.name} left Conversation ${event.conversationId}`
);
} else if (event instanceof TextMessageEvent) {
console.log(
`User ${event.body.sender.name} sent Text Message '${event.body.text}' in Conversation ${event.conversationId}`
);
} else if (event instanceof CustomMessageEvent) {
console.log(
`User ${event.body.sender} sent Custom Message '${event.body.customData}' in Conversation ${event.conversationId}`
);
}
});
```
## Documentation and examples
Visit [vonage website] (<https://developer.vonage.com/tools>)
Visit [Vonage website](https://developer.vonage.com/tools)
## License
Copyright (c) 2023 Vonage, Inc. All rights reserved. Licensed only under the Vonage Client SDK License Agreement (the "License") located at [LICENCE](https://github.com/nexmoinc/conversation-js-sdk/blob/master/LICENSE).
Copyright (c) 2023 Vonage, Inc. All rights reserved. Licensed only under the Vonage Client SDK License Agreement (the "License") located at [LICENSE](https://github.com/nexmoinc/conversation-js-sdk/blob/master/LICENSE).

@@ -96,0 +248,0 @@ By downloading or otherwise using our software or services, you acknowledge that you have read, understand and agree to be bound by the Vonage Client SDK License Agreement and Privacy Policy.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc