@tarunzyraclavis/zyra-twilio-wrapper 1.0.0

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.
package/.eslint.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "env": {
3
+ "node": true,
4
+ "es2021": true
5
+ },
6
+ "extends": "eslint:recommended",
7
+ "parserOptions": {
8
+ "ecmaVersion": "latest",
9
+ "sourceType": "commonjs"
10
+ },
11
+ "rules": {
12
+ "semi": ["error", "always"],
13
+ "quotes": ["error", "double"]
14
+ }
15
+ }
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # VOIP
2
+ Voip sprint
@@ -0,0 +1,156 @@
1
+ import { Call } from '@twilio/voice-sdk';
2
+
3
+ interface Config {
4
+ serverUrl: string;
5
+ identity: string;
6
+ waitUrl?: string;
7
+ }
8
+ interface TwilioConferenceParticipant {
9
+ accountSid: string;
10
+ callSid: string;
11
+ callSidToCoach: string | null;
12
+ coaching: boolean;
13
+ conferenceSid: string;
14
+ dateCreated: string;
15
+ dateUpdated: string;
16
+ endConferenceOnExit: boolean;
17
+ hold: boolean;
18
+ label: string | null;
19
+ muted: boolean;
20
+ queueTime: string | null;
21
+ startConferenceOnEnter: boolean;
22
+ status: 'queued' | 'ringing' | 'in-progress' | 'connected' | 'completed' | string;
23
+ uri: string;
24
+ }
25
+ interface TwilioConference {
26
+ conferenceSid: string;
27
+ conferences: TwilioConferenceDetails;
28
+ }
29
+ interface TwilioConferenceDetails {
30
+ accountSid: string;
31
+ apiVersion: string;
32
+ callSidEndingConference: string | null;
33
+ dateCreated: string;
34
+ dateUpdated: string;
35
+ friendlyName: string;
36
+ reasonConferenceEnded: string | null;
37
+ region: string;
38
+ sid: string;
39
+ status: 'init' | 'in-progress' | 'completed' | 'terminated' | string;
40
+ subresourceUris: {
41
+ participants: string;
42
+ recordings: string;
43
+ [key: string]: string;
44
+ };
45
+ uri: string;
46
+ }
47
+ interface CallResult {
48
+ message: string;
49
+ status: boolean;
50
+ }
51
+ interface HoldAndAddResult extends CallResult {
52
+ holdResponse?: any;
53
+ addParticipantResponse?: any;
54
+ }
55
+ interface GetConferenceResult extends CallResult {
56
+ conferenceDetail?: TwilioConference;
57
+ }
58
+ interface GetParticipantsResult extends CallResult {
59
+ participants?: TwilioConferenceParticipant[];
60
+ }
61
+ interface RemoveParticipantResult extends CallResult {
62
+ data?: any;
63
+ }
64
+ type CallResponse<T = void> = {
65
+ success: true;
66
+ message: string;
67
+ data: T;
68
+ } | {
69
+ success: false;
70
+ error: Error;
71
+ };
72
+
73
+ declare class ZyraTwilioWrapper {
74
+ private readonly serverUrl;
75
+ private readonly identity;
76
+ private device;
77
+ private activeConnection;
78
+ private isInitialized;
79
+ private isInitializing;
80
+ activeCallSid: string | null;
81
+ conferenceName: string;
82
+ conferenceDetail: TwilioConference | null;
83
+ participants: TwilioConferenceParticipant[];
84
+ waitUrl: string;
85
+ onReady?: () => void;
86
+ onIncoming?: (conn: Call) => void;
87
+ onDisconnect?: () => void;
88
+ onError?: (error: Error) => void;
89
+ onConnect?: (conn: Call) => void;
90
+ onMissedCall?: () => void;
91
+ onAnswerOutGoing?: (conn: Call) => void;
92
+ constructor(configObj: Config);
93
+ /**
94
+ * Initialize the SDK. Can only be called once.
95
+ *
96
+ * @throws {Error} If already initialized or initialization fails
97
+ * @returns Promise that resolves when initialization is complete
98
+ */
99
+ init(): Promise<void>;
100
+ private generateToken;
101
+ private setupDeviceEventHandlers;
102
+ /**
103
+ * Check if SDK is initialized
104
+ */
105
+ get initialized(): boolean;
106
+ /**
107
+ * Destroy the SDK instance and clean up resources
108
+ */
109
+ destroy(): void;
110
+ /**
111
+ * Make an outgoing call or add participant to an existing call
112
+ */
113
+ makeCall(to: string): Promise<CallResponse<Call>>;
114
+ /**
115
+ * Accept incoming call
116
+ */
117
+ acceptCall(): CallResponse<Call>;
118
+ /**
119
+ * Hang up active call
120
+ */
121
+ hangup(): CallResponse<Call | null>;
122
+ /**
123
+ * Reject incoming call
124
+ */
125
+ rejectCall(): CallResponse<Call | null>;
126
+ /**
127
+ * Toggle mute/unmute
128
+ */
129
+ toggleMute(mute: boolean): CallResponse<Call>;
130
+ /**
131
+ * Hold a call
132
+ */
133
+ hold(callSid: string): Promise<CallResponse<Call>>;
134
+ /**
135
+ * Resume a held call
136
+ */
137
+ resume(callSid: string): Promise<CallResponse<Call>>;
138
+ /**
139
+ * Hold active call and add a new participant
140
+ */
141
+ holdAndAddParticipant(callSid: string, newParticipantNo: string): Promise<HoldAndAddResult | CallResponse>;
142
+ /**
143
+ * Fetch conference details
144
+ */
145
+ getConferenceId(): Promise<GetConferenceResult | CallResponse<TwilioConference>>;
146
+ /**
147
+ * Get participants of a conference
148
+ */
149
+ getParticipants(conferenceSid: string): Promise<GetParticipantsResult | CallResponse<TwilioConferenceParticipant[]>>;
150
+ /**
151
+ * Remove a participant from a conference
152
+ */
153
+ removeParticipant(conferenceSid: string, callSid: string): Promise<RemoveParticipantResult | CallResponse>;
154
+ }
155
+
156
+ export { ZyraTwilioWrapper as default };
@@ -0,0 +1,156 @@
1
+ import { Call } from '@twilio/voice-sdk';
2
+
3
+ interface Config {
4
+ serverUrl: string;
5
+ identity: string;
6
+ waitUrl?: string;
7
+ }
8
+ interface TwilioConferenceParticipant {
9
+ accountSid: string;
10
+ callSid: string;
11
+ callSidToCoach: string | null;
12
+ coaching: boolean;
13
+ conferenceSid: string;
14
+ dateCreated: string;
15
+ dateUpdated: string;
16
+ endConferenceOnExit: boolean;
17
+ hold: boolean;
18
+ label: string | null;
19
+ muted: boolean;
20
+ queueTime: string | null;
21
+ startConferenceOnEnter: boolean;
22
+ status: 'queued' | 'ringing' | 'in-progress' | 'connected' | 'completed' | string;
23
+ uri: string;
24
+ }
25
+ interface TwilioConference {
26
+ conferenceSid: string;
27
+ conferences: TwilioConferenceDetails;
28
+ }
29
+ interface TwilioConferenceDetails {
30
+ accountSid: string;
31
+ apiVersion: string;
32
+ callSidEndingConference: string | null;
33
+ dateCreated: string;
34
+ dateUpdated: string;
35
+ friendlyName: string;
36
+ reasonConferenceEnded: string | null;
37
+ region: string;
38
+ sid: string;
39
+ status: 'init' | 'in-progress' | 'completed' | 'terminated' | string;
40
+ subresourceUris: {
41
+ participants: string;
42
+ recordings: string;
43
+ [key: string]: string;
44
+ };
45
+ uri: string;
46
+ }
47
+ interface CallResult {
48
+ message: string;
49
+ status: boolean;
50
+ }
51
+ interface HoldAndAddResult extends CallResult {
52
+ holdResponse?: any;
53
+ addParticipantResponse?: any;
54
+ }
55
+ interface GetConferenceResult extends CallResult {
56
+ conferenceDetail?: TwilioConference;
57
+ }
58
+ interface GetParticipantsResult extends CallResult {
59
+ participants?: TwilioConferenceParticipant[];
60
+ }
61
+ interface RemoveParticipantResult extends CallResult {
62
+ data?: any;
63
+ }
64
+ type CallResponse<T = void> = {
65
+ success: true;
66
+ message: string;
67
+ data: T;
68
+ } | {
69
+ success: false;
70
+ error: Error;
71
+ };
72
+
73
+ declare class ZyraTwilioWrapper {
74
+ private readonly serverUrl;
75
+ private readonly identity;
76
+ private device;
77
+ private activeConnection;
78
+ private isInitialized;
79
+ private isInitializing;
80
+ activeCallSid: string | null;
81
+ conferenceName: string;
82
+ conferenceDetail: TwilioConference | null;
83
+ participants: TwilioConferenceParticipant[];
84
+ waitUrl: string;
85
+ onReady?: () => void;
86
+ onIncoming?: (conn: Call) => void;
87
+ onDisconnect?: () => void;
88
+ onError?: (error: Error) => void;
89
+ onConnect?: (conn: Call) => void;
90
+ onMissedCall?: () => void;
91
+ onAnswerOutGoing?: (conn: Call) => void;
92
+ constructor(configObj: Config);
93
+ /**
94
+ * Initialize the SDK. Can only be called once.
95
+ *
96
+ * @throws {Error} If already initialized or initialization fails
97
+ * @returns Promise that resolves when initialization is complete
98
+ */
99
+ init(): Promise<void>;
100
+ private generateToken;
101
+ private setupDeviceEventHandlers;
102
+ /**
103
+ * Check if SDK is initialized
104
+ */
105
+ get initialized(): boolean;
106
+ /**
107
+ * Destroy the SDK instance and clean up resources
108
+ */
109
+ destroy(): void;
110
+ /**
111
+ * Make an outgoing call or add participant to an existing call
112
+ */
113
+ makeCall(to: string): Promise<CallResponse<Call>>;
114
+ /**
115
+ * Accept incoming call
116
+ */
117
+ acceptCall(): CallResponse<Call>;
118
+ /**
119
+ * Hang up active call
120
+ */
121
+ hangup(): CallResponse<Call | null>;
122
+ /**
123
+ * Reject incoming call
124
+ */
125
+ rejectCall(): CallResponse<Call | null>;
126
+ /**
127
+ * Toggle mute/unmute
128
+ */
129
+ toggleMute(mute: boolean): CallResponse<Call>;
130
+ /**
131
+ * Hold a call
132
+ */
133
+ hold(callSid: string): Promise<CallResponse<Call>>;
134
+ /**
135
+ * Resume a held call
136
+ */
137
+ resume(callSid: string): Promise<CallResponse<Call>>;
138
+ /**
139
+ * Hold active call and add a new participant
140
+ */
141
+ holdAndAddParticipant(callSid: string, newParticipantNo: string): Promise<HoldAndAddResult | CallResponse>;
142
+ /**
143
+ * Fetch conference details
144
+ */
145
+ getConferenceId(): Promise<GetConferenceResult | CallResponse<TwilioConference>>;
146
+ /**
147
+ * Get participants of a conference
148
+ */
149
+ getParticipants(conferenceSid: string): Promise<GetParticipantsResult | CallResponse<TwilioConferenceParticipant[]>>;
150
+ /**
151
+ * Remove a participant from a conference
152
+ */
153
+ removeParticipant(conferenceSid: string, callSid: string): Promise<RemoveParticipantResult | CallResponse>;
154
+ }
155
+
156
+ export { ZyraTwilioWrapper as default };