@vonage/client-sdk 0.1.3 → 0.1.4-alpha.3

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/README.md CHANGED
@@ -1,24 +1,54 @@
1
1
  # Vonage Voice SDK
2
2
 
3
- ## Install
3
+ 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.
4
4
 
5
- ### 1. Create a Personal Access Token
5
+ ## Installation
6
6
 
7
- - generate token, see [here](https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token ), you will need a PAT with `packages:read` scope enabled
8
- - enable SSO for new token, see [here](https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on)
9
-
10
- ### 2. Authenticate with Github packages
7
+ The SDK can be installed using the npm install command
11
8
 
12
9
  ```
13
- $ npm login --scope=@nexmoinc --registry=https://npm.pkg.github.com
14
-
15
- > Username: USERNAME //github user
16
- > Password: TOKEN // Personal access token
17
- > Email: github email
10
+ npm i @vonage/client-sdk
18
11
  ```
19
12
 
20
- ### 3. Add dependency
13
+ ## SDK setup
14
+
15
+ To use the client SDK in a Webpack or Vite project:
21
16
 
22
17
  ```
23
- npm install @nexmoinc/voice-sdk
18
+ import './App.css';
19
+ import VoiceClient, { ClientConfig, ConfigRegion } from '@vonage/client-sdk';
20
+
21
+ const client = new VoiceClient();
22
+
23
+ // Config is optional but recomended, default region is US
24
+ const config = new ClientConfig(ConfigRegion.US)
25
+ client.setConfig(config)
26
+
27
+ function App() {
28
+
29
+ const createSession = async () => {
30
+ const token = "my-token"
31
+ await client.createSession(token)
32
+ }
33
+
34
+ return (
35
+ <button onClick={createSession}> create session </button>
36
+ );
37
+ }
38
+
39
+ export default App;
24
40
  ```
41
+
42
+ ## Documentation and examples
43
+
44
+ Visit [vonage website] (https://developer.vonage.com/tools)
45
+
46
+ ## License
47
+
48
+ 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).
49
+
50
+ 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.
51
+
52
+ You may not use, exercise any rights with respect to or exploit this SDK, or any modifications or derivative works thereof, except in accordance with the License.
53
+
54
+ [<img src="https://developer.nexmo.com/images/logos/vbc-logo.svg" width="30%">](https://www.vonage.com/communications-apis/)
@@ -6,10 +6,13 @@ declare class MediaClient implements vonage.MediaClientJS {
6
6
  private audio;
7
7
  private stream;
8
8
  constructor();
9
- enableMedia(id: string, remoteDescription?: string): Promise<void>;
9
+ enableMediaInbound(closure: (err: unknown, offerSDP: KMPPackage.Nullable<string>) => void, offerSDP: string, rtcId: string): Promise<void>;
10
+ enableMediaOutbound(closure: (err: unknown, offerSDP: KMPPackage.Nullable<string>, callback: (legId: string) => void) => void): Promise<void>;
11
+ private getNewPC;
10
12
  mute(id: string): Promise<void>;
11
13
  unmute(id: string): Promise<void>;
12
- processAnswer(id: string, sdp: string, streamId: string, legId: string): void;
14
+ getPeerConnection(id: string): RTCPeerConnection | undefined;
15
+ processAnswer(id: string, sdp: string): void;
13
16
  disableMedia(id: string): void;
14
17
  private setMediaTracksEnabled;
15
18
  }
@@ -15,39 +15,58 @@ class MediaClient {
15
15
  this.pcs = new Map();
16
16
  this.audio = undefined;
17
17
  }
18
- enableMedia(id, remoteDescription) {
19
- var _a, _b;
18
+ enableMediaInbound(closure, offerSDP, rtcId) {
20
19
  return __awaiter(this, void 0, void 0, function* () {
20
+ let sdp;
21
+ let error;
21
22
  try {
22
- const pc = yield (0, createRtcAudioConnection_1.createRtcAudioConnection)();
23
- this.pcs.set(id, pc);
24
- pc.ontrack = (evt) => {
25
- const stream = evt.streams[0];
26
- if (stream) {
27
- const audio = new Audio();
28
- audio.srcObject = stream;
29
- audio.autoplay = true;
30
- this.audio = audio;
31
- this.stream = stream;
32
- }
33
- };
34
- if (remoteDescription) {
35
- const sdp = yield (0, createRtcAudioConnection_1.createAnswer)(pc, remoteDescription);
36
- // eslint-disable-next-line @typescript-eslint/no-empty-function
37
- (_a = this.delegate) === null || _a === void 0 ? void 0 : _a.onAnswer(id, '', sdp, () => { });
38
- }
39
- else {
40
- const sdp = yield (0, createRtcAudioConnection_1.createOffer)(pc);
41
- (_b = this.delegate) === null || _b === void 0 ? void 0 : _b.onOffer(id, '', sdp, () => {
42
- // Do we need to save the leg id for later?
43
- });
44
- }
23
+ const pc = yield this.getNewPC();
24
+ this.pcs.set(rtcId, pc);
25
+ sdp = yield (0, createRtcAudioConnection_1.createAnswer)(pc, offerSDP);
26
+ }
27
+ catch (err) {
28
+ error = err;
29
+ }
30
+ finally {
31
+ closure(error, sdp);
32
+ }
33
+ });
34
+ }
35
+ enableMediaOutbound(closure) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ let error;
38
+ let pc;
39
+ let sdp;
40
+ try {
41
+ pc = yield this.getNewPC();
42
+ sdp = yield (0, createRtcAudioConnection_1.createOffer)(pc);
43
+ }
44
+ catch (err) {
45
+ error = err;
45
46
  }
46
- catch (error) {
47
- // TODO
47
+ finally {
48
+ closure(error, sdp, (legId) => {
49
+ this.pcs.set(legId, pc);
50
+ });
48
51
  }
49
52
  });
50
53
  }
54
+ getNewPC() {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const pc = yield (0, createRtcAudioConnection_1.createRtcAudioConnection)();
57
+ pc.ontrack = (evt) => {
58
+ const stream = evt.streams[0];
59
+ if (stream) {
60
+ const audio = new Audio();
61
+ audio.srcObject = stream;
62
+ audio.autoplay = true;
63
+ this.audio = audio;
64
+ this.stream = stream;
65
+ }
66
+ };
67
+ return pc;
68
+ });
69
+ }
51
70
  mute(id) {
52
71
  return __awaiter(this, void 0, void 0, function* () {
53
72
  this.setMediaTracksEnabled(id, false);
@@ -58,17 +77,17 @@ class MediaClient {
58
77
  this.setMediaTracksEnabled(id, true);
59
78
  });
60
79
  }
80
+ getPeerConnection(id) {
81
+ const pc = this.pcs.get(id);
82
+ return pc;
83
+ }
61
84
  // async getLocalStream(): Promise<MediaStream> {
62
85
  // return await navigator.mediaDevices.getUserMedia({
63
86
  // video: false,
64
87
  // audio: true
65
88
  // });
66
89
  // }
67
- processAnswer(id, sdp,
68
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
69
- streamId,
70
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
- legId) {
90
+ processAnswer(id, sdp) {
72
91
  const remoteDescription = new RTCSessionDescription({
73
92
  type: 'answer',
74
93
  sdp
@@ -6,5 +6,8 @@ declare module './kotlin/clientsdk-clientcore_js' {
6
6
  text: string;
7
7
  }): Promise<unknown>;
8
8
  }
9
+ interface CoreClientJS {
10
+ getPeerConnection(id: string): RTCPeerConnection;
11
+ }
9
12
  }
10
13
  }
@@ -12,14 +12,14 @@
12
12
  }(this, function (_, kotlin_kotlin) {
13
13
  'use strict';
14
14
  //region block: imports
15
- var classMeta = kotlin_kotlin.$_$.h5;
16
- var objectMeta = kotlin_kotlin.$_$.h6;
17
- var listOf = kotlin_kotlin.$_$.g4;
18
- var interfaceMeta = kotlin_kotlin.$_$.o5;
19
- var THROW_ISE = kotlin_kotlin.$_$.w7;
20
- var Unit_getInstance = kotlin_kotlin.$_$.o2;
21
- var Enum = kotlin_kotlin.$_$.q7;
22
- var stackTraceToString = kotlin_kotlin.$_$.m8;
15
+ var classMeta = kotlin_kotlin.$_$.j5;
16
+ var objectMeta = kotlin_kotlin.$_$.j6;
17
+ var listOf = kotlin_kotlin.$_$.h4;
18
+ var interfaceMeta = kotlin_kotlin.$_$.q5;
19
+ var THROW_ISE = kotlin_kotlin.$_$.z7;
20
+ var Unit_getInstance = kotlin_kotlin.$_$.p2;
21
+ var Enum = kotlin_kotlin.$_$.s7;
22
+ var stackTraceToString = kotlin_kotlin.$_$.p8;
23
23
  //endregion
24
24
  //region block: pre-declaration
25
25
  Companion.prototype = Object.create(Logger.prototype);
@@ -31,7 +31,7 @@
31
31
  //endregion
32
32
  function LogWriter() {
33
33
  }
34
- LogWriter.prototype.y19 = function (severity) {
34
+ LogWriter.prototype.a1a = function (severity) {
35
35
  return true;
36
36
  };
37
37
  LogWriter.$metadata$ = classMeta('LogWriter');
@@ -52,16 +52,16 @@
52
52
  }
53
53
  function Companion() {
54
54
  Companion_instance = this;
55
- var tmp = LoggerGlobal_getInstance().a1a_1;
55
+ var tmp = LoggerGlobal_getInstance().c1a_1;
56
56
  Logger_init_$Init$(tmp, null, 2, null, this);
57
57
  }
58
- Companion.prototype.d1a = function () {
58
+ Companion.prototype.f1a = function () {
59
59
  return get_defaultTag();
60
60
  };
61
- Companion.prototype.e1a = function (severity) {
62
- LoggerGlobal_getInstance().a1a_1.f1a(severity);
61
+ Companion.prototype.g1a = function (severity) {
62
+ LoggerGlobal_getInstance().c1a_1.h1a(severity);
63
63
  };
64
- Companion.prototype.g1a = function (tag) {
64
+ Companion.prototype.i1a = function (tag) {
65
65
  set_defaultTag(tag);
66
66
  };
67
67
  Companion.$metadata$ = objectMeta('Companion', undefined, undefined, undefined, undefined, Logger.prototype);
@@ -73,51 +73,51 @@
73
73
  }
74
74
  function Logger(config, tag) {
75
75
  Companion_getInstance();
76
- this.h1a_1 = config;
77
- this.i1a_1 = tag;
76
+ this.j1a_1 = config;
77
+ this.k1a_1 = tag;
78
78
  }
79
- Logger.prototype.j1a = function () {
80
- return this.h1a_1;
79
+ Logger.prototype.l1a = function () {
80
+ return this.j1a_1;
81
81
  };
82
- Logger.prototype.d1a = function () {
83
- return this.i1a_1;
82
+ Logger.prototype.f1a = function () {
83
+ return this.k1a_1;
84
84
  };
85
- Logger.prototype.k1a = function (tag) {
86
- return new Logger(this.h1a_1, tag);
85
+ Logger.prototype.m1a = function (tag) {
86
+ return new Logger(this.j1a_1, tag);
87
87
  };
88
- Logger.prototype.l1a = function (message) {
89
- if (this.h1a_1.p1a().r3(Severity_Info_getInstance()) <= 0) {
90
- this.o1a(Severity_Info_getInstance(), this.d1a(), null, message());
88
+ Logger.prototype.n1a = function (message) {
89
+ if (this.j1a_1.r1a().s3(Severity_Info_getInstance()) <= 0) {
90
+ this.q1a(Severity_Info_getInstance(), this.f1a(), null, message());
91
91
  }
92
92
  };
93
- Logger.prototype.m1a = function (message) {
94
- if (this.h1a_1.p1a().r3(Severity_Error_getInstance()) <= 0) {
95
- this.o1a(Severity_Error_getInstance(), this.d1a(), null, message());
93
+ Logger.prototype.o1a = function (message) {
94
+ if (this.j1a_1.r1a().s3(Severity_Error_getInstance()) <= 0) {
95
+ this.q1a(Severity_Error_getInstance(), this.f1a(), null, message());
96
96
  }
97
97
  };
98
- Logger.prototype.n1a = function (message) {
99
- if (this.h1a_1.p1a().r3(Severity_Error_getInstance()) <= 0) {
100
- this.o1a(Severity_Error_getInstance(), this.d1a(), null, message);
98
+ Logger.prototype.p1a = function (message) {
99
+ if (this.j1a_1.r1a().s3(Severity_Error_getInstance()) <= 0) {
100
+ this.q1a(Severity_Error_getInstance(), this.f1a(), null, message);
101
101
  }
102
102
  };
103
- Logger.prototype.o1a = function (severity, tag, throwable, message) {
103
+ Logger.prototype.q1a = function (severity, tag, throwable, message) {
104
104
  // Inline function 'co.touchlab.kermit.Logger.processLog' call
105
105
  // Inline function 'kotlin.collections.forEach' call
106
- var tmp0_forEach = this.h1a_1.q1a();
106
+ var tmp0_forEach = this.j1a_1.s1a();
107
107
  var tmp0_iterator = tmp0_forEach.g();
108
108
  while (tmp0_iterator.h()) {
109
109
  var element = tmp0_iterator.i();
110
110
  // Inline function 'co.touchlab.kermit.Logger.processLog.<anonymous>' call
111
- if (element.y19(severity)) {
111
+ if (element.a1a(severity)) {
112
112
  // Inline function 'co.touchlab.kermit.Logger.log.<anonymous>' call
113
- element.z19(severity, message, tag, throwable);
113
+ element.b1a(severity, message, tag, throwable);
114
114
  }
115
115
  }
116
116
  };
117
117
  Logger.$metadata$ = classMeta('Logger');
118
118
  function LoggerGlobal() {
119
119
  LoggerGlobal_instance = this;
120
- this.a1a_1 = mutableKermitConfigInit(listOf(platformLogWriter()));
120
+ this.c1a_1 = mutableKermitConfigInit(listOf(platformLogWriter()));
121
121
  }
122
122
  LoggerGlobal.$metadata$ = objectMeta('LoggerGlobal');
123
123
  var LoggerGlobal_instance;
@@ -209,7 +209,7 @@
209
209
  function ConsoleWriter() {
210
210
  LogWriter.call(this);
211
211
  }
212
- ConsoleWriter.prototype.z19 = function (severity, message, tag, throwable) {
212
+ ConsoleWriter.prototype.b1a = function (severity, message, tag, throwable) {
213
213
  var output = '[' + tag + '] ' + message;
214
214
  var tmp0_safe_receiver = throwable;
215
215
  if (tmp0_safe_receiver == null)
@@ -222,7 +222,7 @@
222
222
  tmp$ret$0 = Unit_getInstance();
223
223
  }
224
224
  var tmp1_subject = severity;
225
- var tmp0 = tmp1_subject.p3_1;
225
+ var tmp0 = tmp1_subject.q3_1;
226
226
  switch (tmp0) {
227
227
  case 5:
228
228
  case 4:
@@ -246,17 +246,17 @@
246
246
  };
247
247
  ConsoleWriter.$metadata$ = classMeta('ConsoleWriter', undefined, undefined, undefined, undefined, LogWriter.prototype);
248
248
  function JsMutableLoggerConfig(logWriters) {
249
- this.r1a_1 = get_DEFAULT_MIN_SEVERITY();
250
- this.s1a_1 = logWriters;
249
+ this.t1a_1 = get_DEFAULT_MIN_SEVERITY();
250
+ this.u1a_1 = logWriters;
251
251
  }
252
- JsMutableLoggerConfig.prototype.f1a = function (_set____db54di) {
253
- this.r1a_1 = _set____db54di;
252
+ JsMutableLoggerConfig.prototype.h1a = function (_set____db54di) {
253
+ this.t1a_1 = _set____db54di;
254
254
  };
255
- JsMutableLoggerConfig.prototype.p1a = function () {
256
- return this.r1a_1;
255
+ JsMutableLoggerConfig.prototype.r1a = function () {
256
+ return this.t1a_1;
257
257
  };
258
- JsMutableLoggerConfig.prototype.q1a = function () {
259
- return this.s1a_1;
258
+ JsMutableLoggerConfig.prototype.s1a = function () {
259
+ return this.u1a_1;
260
260
  };
261
261
  JsMutableLoggerConfig.$metadata$ = classMeta('JsMutableLoggerConfig', [MutableLoggerConfig]);
262
262
  function set_defaultTag(_set____db54di) {