@vogent/vogent-web-client 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- export * from "./gql";
@@ -1,130 +0,0 @@
1
- import { VogentAudioConn } from './VogentDevice';
2
- import {
3
- createLocalAudioTrack,
4
- DisconnectReason,
5
- RemoteParticipant,
6
- RemoteTrack,
7
- RemoteTrackPublication,
8
- Room,
9
- RoomEvent,
10
- Track,
11
- } from 'livekit-client';
12
-
13
- export class LivekitCall {
14
- _room: Room;
15
- _params: any;
16
- _handlers: {
17
- ev: 'mute' | 'disconnect' | 'track-added';
18
- fn: (...args: any[]) => void;
19
- }[];
20
-
21
- constructor(room: Room) {
22
- this._room = room;
23
- this._params = {};
24
- this._handlers = [];
25
- }
26
-
27
- mute(status: boolean) {
28
- if (status) {
29
- this._room.localParticipant.setMicrophoneEnabled(false).then(() => {
30
- this.sendEvent('mute', true);
31
- });
32
- } else {
33
- this._room.localParticipant.setMicrophoneEnabled(true).then(() => {
34
- this.sendEvent('mute', false);
35
- });
36
- }
37
- }
38
-
39
- sendDigits(k: string) {
40
- if (k.length != 1) {
41
- throw new Error('Invalid DTMF digit');
42
- }
43
-
44
- const code = k === '*' ? 10 : k === '#' ? 11 : parseInt(k);
45
-
46
- this._room.localParticipant.publishDtmf(code, k);
47
- }
48
-
49
- disconnect() {
50
- this._room.disconnect();
51
- }
52
-
53
- sendEvent(evName: string, ...args: any[]) {
54
- for (const { ev, fn } of this._handlers) {
55
- if (ev === evName) {
56
- fn(...args);
57
- }
58
- }
59
- }
60
-
61
- on(ev: 'mute' | 'disconnect' | 'track-added', fn: (...args: any[]) => void) {
62
- this._handlers.push({
63
- ev,
64
- fn,
65
- });
66
- }
67
- }
68
-
69
- export class LivekitDevice {
70
- _room: Room;
71
- _token: string;
72
- _url: string;
73
-
74
- private constructor(room: Room, token: string, url: string) {
75
- this._room = room;
76
- this._token = token;
77
- this._url = url;
78
-
79
- // speeds up connection attempt
80
- this._room.prepareConnection(this._url, this._token);
81
-
82
- this._room
83
- .on(RoomEvent.TrackSubscribed, this.handleTrackSubscribed)
84
- .on(RoomEvent.TrackUnsubscribed, this.handleTrackUnsubscribed)
85
- .on(RoomEvent.Disconnected, (reason?: DisconnectReason) => {
86
- console.log('Disconnected', reason);
87
- this.disconnect();
88
- });
89
- }
90
-
91
- static async getDevice(sessionToken: string, url: string): Promise<LivekitDevice> {
92
- const room = new Room();
93
- return new LivekitDevice(room, sessionToken, url);
94
- }
95
-
96
- disconnect() {
97
- this._room.disconnect();
98
- }
99
-
100
- handleTrackSubscribed(
101
- track: RemoteTrack,
102
- _publication: RemoteTrackPublication,
103
- _participant: RemoteParticipant
104
- ) {
105
- if (track.kind === 'audio') {
106
- const audioElement = track.attach();
107
- document.body.appendChild(audioElement);
108
- audioElement.style.display = 'none';
109
- }
110
- }
111
-
112
- handleTrackUnsubscribed(
113
- track: RemoteTrack,
114
- _publication: RemoteTrackPublication,
115
- _participant: RemoteParticipant
116
- ) {
117
- if (track.kind === 'audio') {
118
- // console.log('Track unsubscribed', track);
119
- }
120
- }
121
-
122
- async connect(_p: any): Promise<VogentAudioConn> {
123
- await this._room.connect(this._url, this._token, {});
124
- const lkcall = new LivekitCall(this._room);
125
-
126
- await this._room.localParticipant.setMicrophoneEnabled(true);
127
-
128
- return lkcall;
129
- }
130
- }
@@ -1,49 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
-
3
- /**
4
- * Interface representing an active audio connection to a Vogent call.
5
- * Returned by VogentCall.connectAudio()
6
- */
7
- export interface VogentAudioConn {
8
- /**
9
- * Register event handlers for connection events
10
- * @param ev - Event type to listen for
11
- * - 'mute': Fired when the connection's mute state changes
12
- * - 'disconnect': Fired when the connection is terminated
13
- * @param fn - Callback function to handle the event
14
- */
15
- on: (ev: 'mute' | 'disconnect' | 'track-added', fn: (...args: any[]) => void) => void;
16
-
17
- /**
18
- * Mute or unmute the audio connection
19
- * @param status - True to mute, false to unmute
20
- */
21
- mute: (status: boolean) => void;
22
-
23
- /**
24
- * Terminate the audio connection
25
- */
26
- disconnect: () => void;
27
-
28
- /**
29
- * Send DTMF digits through the connection
30
- * @param k - String of DTMF digits to send (0-9, *, #)
31
- */
32
- sendDigits: (k: string) => void;
33
- }
34
-
35
- /**
36
- * Interface representing a device that can establish audio connections
37
- * Currently implemented by VonageDevice
38
- */
39
- export interface VogentDevice {
40
- /**
41
- * Establish an audio connection with the specified parameters
42
- * @param p - Connection parameters object containing:
43
- * - params.EltoDialSessionID: The session ID for the call
44
- * - params.LiveListen: Whether this is a monitoring connection
45
- * - params.DialID: The ID of the dial to connect to
46
- * @returns Promise resolving to an active audio connection
47
- */
48
- connect: (p: any) => Promise<VogentAudioConn>;
49
- }
@@ -1,104 +0,0 @@
1
- import { VogentAudioConn } from './VogentDevice';
2
- import { VonageClient, LoggingLevel } from '@vonage/client-sdk';
3
-
4
- export class VonageCall {
5
- _callId: string;
6
- _client: VonageClient;
7
- _liveListen: boolean;
8
- _params: any;
9
- _handlers: {
10
- ev: 'mute' | 'disconnect' | 'track-added';
11
- fn: (...args: any[]) => void;
12
- }[];
13
-
14
- constructor(callId: string, client: VonageClient, params: any) {
15
- this._callId = callId;
16
- this._client = client;
17
- this._params = params;
18
- this._handlers = [];
19
- this._liveListen = false;
20
-
21
- this._client.on('callHangup', (callId, _, reason) => {
22
- if (callId !== this._callId) {
23
- return;
24
- }
25
-
26
- console.log('Call status changed', reason, callId);
27
-
28
- if (
29
- !this._liveListen &&
30
- (reason === 'REMOTE_HANGUP' || reason === 'REMOTE_NO_ANSWER_TIMEOUT')
31
- ) {
32
- console.log('Reconnecting');
33
- this._client
34
- .serverCall(this._params)
35
- .then((cid: string) => {
36
- this._callId = cid;
37
- })
38
- .catch((err) => {
39
- console.error('Error reconnecting', err);
40
- this.sendEvent('disconnect');
41
- });
42
- } else {
43
- this.sendEvent('disconnect');
44
- }
45
- });
46
- }
47
-
48
- mute(status: boolean) {
49
- if (status) {
50
- this._client.mute(this._callId).then(() => {
51
- this.sendEvent('mute', true);
52
- });
53
- } else {
54
- this._client.unmute(this._callId).then(() => {
55
- this.sendEvent('mute', false);
56
- });
57
- }
58
- }
59
-
60
- sendDigits(k: string) {
61
- this._client.sendDTMF(this._callId, k);
62
- }
63
-
64
- disconnect() {
65
- this._client.hangup(this._callId);
66
- }
67
-
68
- sendEvent(evName: string, ...args: any[]) {
69
- for (const { ev, fn } of this._handlers) {
70
- if (ev === evName) {
71
- fn(...args);
72
- }
73
- }
74
- }
75
-
76
- on(ev: 'mute' | 'disconnect' | 'track-added', fn: (...args: any[]) => void) {
77
- this._handlers.push({
78
- ev,
79
- fn,
80
- });
81
- }
82
- }
83
-
84
- export class VonageDevice {
85
- _sessionId: string;
86
- _client: VonageClient;
87
-
88
- private constructor(sessionId: string, client: VonageClient, liveListen = false) {
89
- this._sessionId = sessionId;
90
- this._client = client;
91
- }
92
-
93
- static async getDevice(sessionToken: string, disableEffects = false): Promise<VonageDevice> {
94
- const client = new VonageClient({ loggingLevel: LoggingLevel.Warn });
95
- const sessId = await client.createSession(sessionToken);
96
- return new VonageDevice(sessId, client, disableEffects);
97
- }
98
-
99
- async connect(p: any): Promise<VogentAudioConn> {
100
- const call = await this._client.serverCall(p.params);
101
- const v = new VonageCall(call, this._client, p.params);
102
- return v;
103
- }
104
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { VogentCall } from './VogentCall';
2
- export * from './devices/VogentDevice';
3
- export { dialStatusIsComplete } from './utils';
package/src/queries.ts DELETED
@@ -1,75 +0,0 @@
1
- import { gql } from './__generated__';
2
-
3
- export const AI_START_DIAL_SESSION = gql(`
4
- mutation StartDialSession($sessionId: ID!) {
5
- startDialSession(dialSessionId: $sessionId)
6
- }
7
- `);
8
-
9
- export const AI_HANGUP_CALL = gql(`
10
- mutation HangupCall($dialId: ID!, $dropVoicemail: Boolean, $transferNumber: String) {
11
- hangupCall(dialId: $dialId, dropVoicemail: $dropVoicemail, transferNumber: $transferNumber)
12
- }
13
- `);
14
-
15
- export const AI_SET_PAUSED = gql(`
16
- mutation SetPaused($dialId: ID!, $pauseStatus: Boolean!) {
17
- pauseAI(dialId: $dialId, pauseStatus: $pauseStatus) {
18
- id
19
- }
20
- }
21
- `);
22
-
23
- export const REFRESH_TRANSCRIPT = gql(`
24
- subscription RefreshTranscript($dialId: ID!) {
25
- watchTranscript(dialId: $dialId) {
26
- speaker
27
- text
28
- detailType
29
- }
30
- }
31
- `);
32
-
33
- export const AI_GET_TOKEN = gql(`
34
- mutation BrowserDialToken($input: BrowserDialTokenInput!) {
35
- browserDialToken(input: $input) {
36
- token
37
- iceConfig
38
- telephonyProvider
39
- url
40
- }
41
- }
42
- `);
43
-
44
- export const AI_CONNECT_SESSION = gql(`
45
- subscription ConnectSession($sessionId: ID!) {
46
- connectSession(sessionId: $sessionId) {
47
- messageType
48
- content {
49
- __typename
50
- ... on DialsUpdatedMessage {
51
- contactId
52
- dials {
53
- id
54
- status
55
- answerType
56
- callDispositionId
57
- systemResultType
58
- toNumber
59
- }
60
- contactComplete
61
- }
62
- ... on DialConnectMessage {
63
- dialId
64
- }
65
- ... on SessionUpdatedMessage {
66
- dialSession {
67
- id
68
- status
69
- }
70
- reason
71
- }
72
- }
73
- }
74
- }
75
- `);
package/src/utils.ts DELETED
@@ -1,16 +0,0 @@
1
- export function dialStatusIsComplete(status: string) {
2
- switch (status) {
3
- case 'completed':
4
- return true;
5
- case 'canceled':
6
- return true;
7
- case 'no-answer':
8
- return true;
9
- case 'failed':
10
- return true;
11
- case 'busy':
12
- return true;
13
- default:
14
- return false;
15
- }
16
- }