ringcentral-softphone 0.4.8 → 0.5.1

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.
Files changed (126) hide show
  1. package/.ackrc +1 -0
  2. package/.eslintrc.json +3 -0
  3. package/.prettierrc.js +3 -0
  4. package/.vscode/settings.json +10 -0
  5. package/README.md +1 -7
  6. package/demos/browser/index.ts +35 -0
  7. package/demos/node/answer-and-save.ts +42 -0
  8. package/demos/node/answer-and-talk.js +3 -3
  9. package/demos/node/{text-to-speech.js → call-and-save.js} +20 -11
  10. package/demos/node/caller-cancel.js +3 -3
  11. package/demos/node/high-concurrency.js +3 -3
  12. package/demos/node/ignore.js +3 -3
  13. package/demos/node/outbound-call.ts +47 -0
  14. package/demos/node/send-audio.ts +40 -0
  15. package/demos/node/text-to-speech.ts +47 -0
  16. package/demos/node/to-voicemail.js +3 -3
  17. package/dist/demos/browser/index.d.ts +1 -0
  18. package/dist/demos/browser/index.js +37 -0
  19. package/dist/demos/browser/index.js.map +1 -0
  20. package/dist/demos/node/answer-and-save.d.ts +1 -0
  21. package/dist/demos/node/answer-and-save.js +45 -0
  22. package/dist/demos/node/answer-and-save.js.map +1 -0
  23. package/dist/demos/node/outbound-call.d.ts +1 -0
  24. package/dist/demos/node/outbound-call.js +49 -0
  25. package/dist/demos/node/outbound-call.js.map +1 -0
  26. package/dist/demos/node/send-audio.d.ts +1 -0
  27. package/dist/demos/node/send-audio.js +36 -0
  28. package/dist/demos/node/send-audio.js.map +1 -0
  29. package/dist/demos/node/text-to-speech.d.ts +1 -0
  30. package/dist/demos/node/text-to-speech.js +41 -0
  31. package/dist/demos/node/text-to-speech.js.map +1 -0
  32. package/dist/package.json +55 -0
  33. package/dist/src/index.d.ts +29 -0
  34. package/dist/src/index.js +255 -0
  35. package/dist/src/index.js.map +1 -0
  36. package/dist/src/rc-message/call-control-commands.d.ts +21 -0
  37. package/dist/src/rc-message/call-control-commands.js +36 -0
  38. package/dist/src/rc-message/call-control-commands.js.map +1 -0
  39. package/dist/src/rc-message/rc-message.d.ts +15 -0
  40. package/dist/src/rc-message/rc-message.js +36 -0
  41. package/dist/src/rc-message/rc-message.js.map +1 -0
  42. package/dist/src/rc-message/rc-requests.d.ts +52 -0
  43. package/dist/src/rc-message/rc-requests.js +18 -0
  44. package/dist/src/rc-message/rc-requests.js.map +1 -0
  45. package/dist/src/sip-message/inbound/inbound-sip-message.d.ts +5 -0
  46. package/dist/src/sip-message/inbound/inbound-sip-message.js +19 -0
  47. package/dist/src/sip-message/inbound/inbound-sip-message.js.map +1 -0
  48. package/{src/sip-message/index.js → dist/src/sip-message/index.d.ts} +3 -3
  49. package/dist/src/sip-message/index.js +13 -0
  50. package/dist/src/sip-message/index.js.map +1 -0
  51. package/dist/src/sip-message/outbound/outbound-sip-message.d.ts +5 -0
  52. package/dist/src/sip-message/outbound/outbound-sip-message.js +16 -0
  53. package/dist/src/sip-message/outbound/outbound-sip-message.js.map +1 -0
  54. package/dist/src/sip-message/outbound/request-sip-message.d.ts +8 -0
  55. package/dist/src/sip-message/outbound/request-sip-message.js +31 -0
  56. package/dist/src/sip-message/outbound/request-sip-message.js.map +1 -0
  57. package/dist/src/sip-message/outbound/response-sip-message.d.ts +6 -0
  58. package/dist/src/sip-message/outbound/response-sip-message.js +23 -0
  59. package/dist/src/sip-message/outbound/response-sip-message.js.map +1 -0
  60. package/dist/src/sip-message/response-codes.d.ts +5 -0
  61. package/dist/src/sip-message/response-codes.js +79 -0
  62. package/dist/src/sip-message/response-codes.js.map +1 -0
  63. package/dist/src/sip-message/sip-message.d.ts +11 -0
  64. package/dist/src/sip-message/sip-message.js +19 -0
  65. package/dist/src/sip-message/sip-message.js.map +1 -0
  66. package/dist/src/utils.d.ts +13 -0
  67. package/dist/src/utils.js +69 -0
  68. package/dist/src/utils.js.map +1 -0
  69. package/package.json +37 -34
  70. package/src/index.ts +338 -0
  71. package/src/rc-message/{call-control-commands.js → call-control-commands.ts} +5 -5
  72. package/src/rc-message/rc-message.ts +53 -0
  73. package/src/rc-message/rc-requests.ts +16 -0
  74. package/src/sip-message/inbound/inbound-sip-message.ts +17 -0
  75. package/src/sip-message/index.ts +3 -0
  76. package/src/sip-message/outbound/outbound-sip-message.ts +12 -0
  77. package/src/sip-message/outbound/request-sip-message.ts +38 -0
  78. package/src/sip-message/outbound/response-sip-message.ts +27 -0
  79. package/src/sip-message/{response-codes.js → response-codes.ts} +8 -4
  80. package/src/sip-message/sip-message.ts +26 -0
  81. package/src/types/node-webrtc-media-devices/index.d.ts +4 -0
  82. package/src/types/wrtc/index.d.ts +4 -0
  83. package/src/types/ws/index.d.ts +4 -0
  84. package/src/utils.ts +115 -0
  85. package/test/{rc-message.js → rc-message.spec.js} +1 -1
  86. package/tsconfig.json +19 -0
  87. package/webpack.config.babel.ts +29 -0
  88. package/.babelrc +0 -14
  89. package/demos/browser/index.js +0 -32
  90. package/demos/node/answer-and-save.js +0 -41
  91. package/demos/node/outbound-call.js +0 -38
  92. package/demos/node/send-audio.js +0 -33
  93. package/dist/index.js +0 -295
  94. package/dist/index.js.map +0 -1
  95. package/dist/rc-message/call-control-commands.js +0 -33
  96. package/dist/rc-message/call-control-commands.js.map +0 -1
  97. package/dist/rc-message/rc-message.js +0 -48
  98. package/dist/rc-message/rc-message.js.map +0 -1
  99. package/dist/rc-message/rc-requests.js +0 -60
  100. package/dist/rc-message/rc-requests.js.map +0 -1
  101. package/dist/sip-message/inbound/inbound-sip-message.js +0 -31
  102. package/dist/sip-message/inbound/inbound-sip-message.js.map +0 -1
  103. package/dist/sip-message/index.js +0 -32
  104. package/dist/sip-message/index.js.map +0 -1
  105. package/dist/sip-message/outbound/outbound-sip-message.js +0 -25
  106. package/dist/sip-message/outbound/outbound-sip-message.js.map +0 -1
  107. package/dist/sip-message/outbound/request-sip-message.js +0 -54
  108. package/dist/sip-message/outbound/request-sip-message.js.map +0 -1
  109. package/dist/sip-message/outbound/response-sip-message.js +0 -44
  110. package/dist/sip-message/outbound/response-sip-message.js.map +0 -1
  111. package/dist/sip-message/response-codes.js +0 -85
  112. package/dist/sip-message/response-codes.js.map +0 -1
  113. package/dist/sip-message/sip-message.js +0 -25
  114. package/dist/sip-message/sip-message.js.map +0 -1
  115. package/dist/utils.js +0 -94
  116. package/dist/utils.js.map +0 -1
  117. package/src/index.js +0 -233
  118. package/src/rc-message/rc-message.js +0 -32
  119. package/src/rc-message/rc-requests.js +0 -16
  120. package/src/sip-message/inbound/inbound-sip-message.js +0 -15
  121. package/src/sip-message/outbound/outbound-sip-message.js +0 -12
  122. package/src/sip-message/outbound/request-sip-message.js +0 -31
  123. package/src/sip-message/outbound/response-sip-message.js +0 -21
  124. package/src/sip-message/sip-message.js +0 -13
  125. package/src/utils.js +0 -63
  126. package/webpack.config.babel.js +0 -28
package/.ackrc CHANGED
@@ -1,3 +1,4 @@
1
1
  --ignore-file=match:/^yarn\.lock$/
2
2
  --ignore-dir=dist/
3
3
  --ignore-dir=test/
4
+ --ignore-dir=build/
package/.eslintrc.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./node_modules/gts/"
3
+ }
package/.prettierrc.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('gts/.prettierrc.json')
3
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "filewatcher.commands": [
3
+ {
4
+ "match": "\\.tsx?",
5
+ "isAsync": true,
6
+ "cmd": "cd '${workspaceRoot}' && yarn gts fix '${file}'",
7
+ "event": "onFileChange"
8
+ }
9
+ ]
10
+ }
package/README.md CHANGED
@@ -17,12 +17,6 @@ This project was originally designed for server and desktop. It doesn't require
17
17
  - Ignore inbound call
18
18
 
19
19
 
20
- ## Known issues
21
-
22
- - It doesn't work with Node.js 12. I only tested it against node 10.
23
- - Update: today I tested with Node.js 13.7, it worked like a charm!
24
-
25
-
26
20
  ## Demos
27
21
 
28
22
  - [browser demo](./demos/browser)
@@ -38,7 +32,7 @@ This project was originally designed for server and desktop. It doesn't require
38
32
  ## Install
39
33
 
40
34
  ```
41
- yarn add ringcentral-softphone @ringcentral/sdk
35
+ yarn add ringcentral-softphone @rc-ex/core
42
36
  ```
43
37
 
44
38
  For node.js you also need to:
@@ -0,0 +1,35 @@
1
+ import RingCentral from '@rc-ex/core';
2
+
3
+ import Softphone from '../../src/index';
4
+
5
+ const rc = new RingCentral({
6
+ server: process.env.RINGCENTRAL_SERVER_URL,
7
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
8
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
9
+ });
10
+
11
+ (async () => {
12
+ await rc.authorize({
13
+ username: process.env.RINGCENTRAL_USERNAME!,
14
+ extension: process.env.RINGCENTRAL_EXTENSION,
15
+ password: process.env.RINGCENTRAL_PASSWORD!,
16
+ });
17
+ const softphone = new Softphone(rc);
18
+ await softphone.register();
19
+ await rc.revoke(); // rc is no longer needed
20
+
21
+ const audioElement = document.getElementById('audio') as HTMLAudioElement;
22
+ softphone.on('INVITE', async sipMessage => {
23
+ const inputAudioStream = await navigator.mediaDevices.getUserMedia({
24
+ audio: true,
25
+ video: false,
26
+ });
27
+ softphone.answer(sipMessage, inputAudioStream);
28
+ softphone.once('track', e => {
29
+ audioElement.srcObject = e.streams[0];
30
+ softphone.once('BYE', () => {
31
+ audioElement.srcObject = null;
32
+ });
33
+ });
34
+ });
35
+ })();
@@ -0,0 +1,42 @@
1
+ import RingCentral from '@rc-ex/core';
2
+ // eslint-disable-next-line node/no-unpublished-import
3
+ import wrtc from 'wrtc';
4
+ import fs from 'fs';
5
+
6
+ import Softphone from '../../src/index';
7
+
8
+ const rc = new RingCentral({
9
+ server: process.env.RINGCENTRAL_SERVER_URL,
10
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
11
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
12
+ });
13
+
14
+ (async () => {
15
+ await rc.authorize({
16
+ username: process.env.RINGCENTRAL_USERNAME!,
17
+ extension: process.env.RINGCENTRAL_EXTENSION,
18
+ password: process.env.RINGCENTRAL_PASSWORD!,
19
+ });
20
+ const softphone = new Softphone(rc);
21
+ await softphone.register();
22
+ await rc.revoke(); // rc is no longer needed
23
+ softphone.on('INVITE', async sipMessage => {
24
+ softphone.answer(sipMessage);
25
+ softphone.once('track', e => {
26
+ const audioFilePath = 'audio.raw';
27
+ if (fs.existsSync(audioFilePath)) {
28
+ fs.unlinkSync(audioFilePath);
29
+ }
30
+ const writeStream = fs.createWriteStream(audioFilePath, {flags: 'a'});
31
+ const audioSink = new wrtc.nonstandard.RTCAudioSink(e.track);
32
+ audioSink.ondata = (data: any) => {
33
+ writeStream.write(Buffer.from(data.samples.buffer));
34
+ };
35
+ softphone.once('BYE', () => {
36
+ audioSink.stop();
37
+ writeStream.end();
38
+ });
39
+ });
40
+ });
41
+ })();
42
+ // You can play the saved audio by: play -b 16 -e signed -c 1 -r 48000 audio.raw
@@ -1,4 +1,4 @@
1
- import RingCentral from '@ringcentral/sdk'
1
+ import RingCentral from '@rc-ex/core'
2
2
  import { nonstandard } from 'wrtc'
3
3
  import mediaDevices from 'node-webrtc-media-devices'
4
4
  import Speaker from 'speaker'
@@ -12,14 +12,14 @@ const rc = new RingCentral({
12
12
  })
13
13
 
14
14
  ;(async () => {
15
- await rc.login({
15
+ await rc.authorize({
16
16
  username: process.env.RINGCENTRAL_USERNAME,
17
17
  extension: process.env.RINGCENTRAL_EXTENSION,
18
18
  password: process.env.RINGCENTRAL_PASSWORD
19
19
  })
20
20
  const softphone = new Softphone(rc)
21
21
  await softphone.register()
22
- await rc.logout() // rc is no longer needed
22
+ await rc.revoke() // rc is no longer needed
23
23
  softphone.on('INVITE', async sipMessage => {
24
24
  const inputAudioStream = await mediaDevices.getUserMedia({ audio: true, video: false })
25
25
  softphone.answer(sipMessage, inputAudioStream)
@@ -1,8 +1,7 @@
1
- import RingCentral from '@ringcentral/sdk'
2
- import { MediaStream } from 'wrtc'
3
- import RTCAudioStreamSource from 'node-webrtc-audio-stream-source'
1
+ import RingCentral from '@rc-ex/core'
2
+ import { nonstandard, MediaStream } from 'wrtc'
4
3
  import fs from 'fs'
5
- import { exec } from 'child_process'
4
+ import RTCAudioStreamSource from 'node-webrtc-audio-stream-source'
6
5
 
7
6
  import Softphone from '../../src/index'
8
7
 
@@ -13,25 +12,35 @@ const rc = new RingCentral({
13
12
  })
14
13
 
15
14
  ;(async () => {
16
- await rc.login({
15
+ await rc.authorize({
17
16
  username: process.env.RINGCENTRAL_USERNAME,
18
17
  extension: process.env.RINGCENTRAL_EXTENSION,
19
18
  password: process.env.RINGCENTRAL_PASSWORD
20
19
  })
21
20
  const softphone = new Softphone(rc)
22
21
  await softphone.register()
23
- await rc.logout() // rc is no longer needed
22
+ await rc.revoke() // rc is no longer needed
24
23
 
25
24
  const rtcAudioStreamSource = new RTCAudioStreamSource()
26
25
  const track = rtcAudioStreamSource.createTrack()
27
26
  const inputAudioStream = new MediaStream()
28
27
  inputAudioStream.addTrack(track)
29
28
  softphone.invite(process.env.CALLEE_FOR_TESTING, inputAudioStream)
30
- softphone.on('track', e => {
31
- const text = 'Hello Tyler, you need to give a talk to the AI RTC conference today at 3PM, don\'t forget!'
32
- const process = exec(`say -o temp.wav --data-format=LEI16@48000 "${text + ' ' + text}"`)
33
- process.on('exit', () => {
34
- rtcAudioStreamSource.addStream(fs.createReadStream('temp.wav'), 16, 48000, 1)
29
+
30
+ softphone.once('track', e => {
31
+ const audioFilePath = 'audio.raw'
32
+ if (fs.existsSync(audioFilePath)) {
33
+ fs.unlinkSync(audioFilePath)
34
+ }
35
+ const writeStream = fs.createWriteStream(audioFilePath, { flags: 'a' })
36
+ const audioSink = new nonstandard.RTCAudioSink(e.track)
37
+ audioSink.ondata = data => {
38
+ writeStream.write(Buffer.from(data.samples.buffer))
39
+ }
40
+ softphone.once('BYE', () => {
41
+ audioSink.stop()
42
+ writeStream.end()
35
43
  })
36
44
  })
37
45
  })()
46
+ // You can play the saved audio by: play -b 16 -e signed -c 1 -r 48000 audio.raw
@@ -1,4 +1,4 @@
1
- import RingCentral from '@ringcentral/sdk'
1
+ import RingCentral from '@rc-ex/core'
2
2
 
3
3
  import Softphone from '../../src/index'
4
4
 
@@ -9,13 +9,13 @@ const rc = new RingCentral({
9
9
  })
10
10
 
11
11
  ;(async () => {
12
- await rc.login({
12
+ await rc.authorize({
13
13
  username: process.env.RINGCENTRAL_USERNAME,
14
14
  extension: process.env.RINGCENTRAL_EXTENSION,
15
15
  password: process.env.RINGCENTRAL_PASSWORD
16
16
  })
17
17
  const softphone = new Softphone(rc)
18
18
  await softphone.register()
19
- await rc.logout() // rc is no longer needed
19
+ await rc.revoke() // rc is no longer needed
20
20
  // do nothing, caller should cancel the call
21
21
  })()
@@ -1,4 +1,4 @@
1
- import RingCentral from '@ringcentral/sdk'
1
+ import RingCentral from '@rc-ex/core'
2
2
  import { nonstandard } from 'wrtc'
3
3
  import fs from 'fs'
4
4
 
@@ -14,14 +14,14 @@ const rc = new RingCentral({
14
14
  })
15
15
 
16
16
  ;(async () => {
17
- await rc.login({
17
+ await rc.authorize({
18
18
  username: process.env.RINGCENTRAL_USERNAME,
19
19
  extension: process.env.RINGCENTRAL_EXTENSION,
20
20
  password: process.env.RINGCENTRAL_PASSWORD
21
21
  })
22
22
  const softphone = new Softphone(rc)
23
23
  await softphone.register()
24
- await rc.logout() // rc is no longer needed
24
+ await rc.revoke() // rc is no longer needed
25
25
  softphone.on('INVITE', async sipMessage => {
26
26
  console.log(sipMessage.headers)
27
27
  softphone.answer(sipMessage)
@@ -1,4 +1,4 @@
1
- import RingCentral from '@ringcentral/sdk'
1
+ import RingCentral from '@rc-ex/core'
2
2
 
3
3
  import Softphone from '../../src/index'
4
4
 
@@ -9,14 +9,14 @@ const rc = new RingCentral({
9
9
  })
10
10
 
11
11
  ;(async () => {
12
- await rc.login({
12
+ await rc.authorize({
13
13
  username: process.env.RINGCENTRAL_USERNAME,
14
14
  extension: process.env.RINGCENTRAL_EXTENSION,
15
15
  password: process.env.RINGCENTRAL_PASSWORD
16
16
  })
17
17
  const softphone = new Softphone(rc)
18
18
  await softphone.register()
19
- await rc.logout() // rc is no longer needed
19
+ await rc.revoke() // rc is no longer needed
20
20
  softphone.on('INVITE', async sipMessage => {
21
21
  softphone.ignore(sipMessage)
22
22
  })
@@ -0,0 +1,47 @@
1
+ /* eslint-disable node/no-unpublished-import */
2
+ import RingCentral from '@rc-ex/core';
3
+ import mediaDevices from 'node-webrtc-media-devices';
4
+ import Speaker from 'speaker';
5
+ import wrtc from 'wrtc';
6
+
7
+ import Softphone from '../../src/index';
8
+
9
+ const {RTCAudioSink} = wrtc.nonstandard;
10
+
11
+ const rc = new RingCentral({
12
+ server: process.env.RINGCENTRAL_SERVER_URL,
13
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
14
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
15
+ });
16
+
17
+ (async () => {
18
+ await rc.authorize({
19
+ username: process.env.RINGCENTRAL_USERNAME!,
20
+ extension: process.env.RINGCENTRAL_EXTENSION,
21
+ password: process.env.RINGCENTRAL_PASSWORD!,
22
+ });
23
+ const softphone = new Softphone(rc);
24
+ await softphone.register();
25
+ await rc.revoke(); // rc is no longer needed
26
+ softphone.on('track', e => {
27
+ const speaker = new Speaker({
28
+ channels: 1,
29
+ bitDepth: 16,
30
+ sampleRate: 48000,
31
+ // signed: true,
32
+ });
33
+ const audioSink = new RTCAudioSink(e.track);
34
+ audioSink.ondata = (data: any) => {
35
+ speaker.write(Buffer.from(data.samples.buffer));
36
+ };
37
+ softphone.once('BYE', () => {
38
+ audioSink.stop();
39
+ speaker.close(true);
40
+ });
41
+ });
42
+ const inputAudioStream = await mediaDevices.getUserMedia({
43
+ audio: true,
44
+ video: false,
45
+ });
46
+ softphone.invite(process.env.CALLEE_FOR_TESTING!, inputAudioStream);
47
+ })();
@@ -0,0 +1,40 @@
1
+ import RingCentral from '@rc-ex/core';
2
+ // eslint-disable-next-line node/no-unpublished-import
3
+ import wrtc from 'wrtc';
4
+ // eslint-disable-next-line node/no-unpublished-import
5
+ import RTCAudioStreamSource from 'node-webrtc-audio-stream-source';
6
+ import fs from 'fs';
7
+
8
+ import Softphone from '../../src/index';
9
+
10
+ const rc = new RingCentral({
11
+ server: process.env.RINGCENTRAL_SERVER_URL,
12
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
13
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
14
+ });
15
+
16
+ (async () => {
17
+ await rc.authorize({
18
+ username: process.env.RINGCENTRAL_USERNAME!,
19
+ extension: process.env.RINGCENTRAL_EXTENSION,
20
+ password: process.env.RINGCENTRAL_PASSWORD!,
21
+ });
22
+ const softphone = new Softphone(rc);
23
+ await softphone.register();
24
+ await rc.revoke(); // rc is no longer needed
25
+
26
+ const rtcAudioStreamSource = new RTCAudioStreamSource();
27
+ const track = rtcAudioStreamSource.createTrack();
28
+ const inputAudioStream = new wrtc.MediaStream();
29
+ inputAudioStream.addTrack(track);
30
+ softphone.invite(process.env.CALLEE_FOR_TESTING!, inputAudioStream);
31
+
32
+ softphone.once('track', (e: any) => {
33
+ rtcAudioStreamSource.addStream(
34
+ fs.createReadStream('test.wav'),
35
+ 16,
36
+ 48000,
37
+ 1
38
+ );
39
+ });
40
+ })();
@@ -0,0 +1,47 @@
1
+ import RingCentral from '@rc-ex/core';
2
+ // eslint-disable-next-line node/no-unpublished-import
3
+ import wrtc from 'wrtc';
4
+ // eslint-disable-next-line node/no-unpublished-import
5
+ import RTCAudioStreamSource from 'node-webrtc-audio-stream-source';
6
+ import fs from 'fs';
7
+ import {exec} from 'child_process';
8
+
9
+ import Softphone from '../../src/index';
10
+
11
+ const rc = new RingCentral({
12
+ server: process.env.RINGCENTRAL_SERVER_URL,
13
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
14
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
15
+ });
16
+
17
+ (async () => {
18
+ await rc.authorize({
19
+ username: process.env.RINGCENTRAL_USERNAME!,
20
+ extension: process.env.RINGCENTRAL_EXTENSION,
21
+ password: process.env.RINGCENTRAL_PASSWORD!,
22
+ });
23
+ const softphone = new Softphone(rc);
24
+ await softphone.register();
25
+ await rc.revoke(); // rc is no longer needed
26
+
27
+ const rtcAudioStreamSource = new RTCAudioStreamSource();
28
+ const track = rtcAudioStreamSource.createTrack();
29
+ const inputAudioStream = new wrtc.MediaStream();
30
+ inputAudioStream.addTrack(track);
31
+ softphone.invite(process.env.CALLEE_FOR_TESTING!, inputAudioStream);
32
+ softphone.on('track', e => {
33
+ const text =
34
+ "Hello Tyler, you need to give a talk to the AI RTC conference today at 3PM, don't forget!";
35
+ const process = exec(
36
+ `say -o temp.wav --data-format=LEI16@48000 "${text + ' ' + text}"`
37
+ );
38
+ process.on('exit', () => {
39
+ rtcAudioStreamSource.addStream(
40
+ fs.createReadStream('temp.wav'),
41
+ 16,
42
+ 48000,
43
+ 1
44
+ );
45
+ });
46
+ });
47
+ })();
@@ -1,4 +1,4 @@
1
- import RingCentral from '@ringcentral/sdk'
1
+ import RingCentral from '@rc-ex/core'
2
2
 
3
3
  import Softphone from '../../src/index'
4
4
 
@@ -9,14 +9,14 @@ const rc = new RingCentral({
9
9
  })
10
10
 
11
11
  ;(async () => {
12
- await rc.login({
12
+ await rc.authorize({
13
13
  username: process.env.RINGCENTRAL_USERNAME,
14
14
  extension: process.env.RINGCENTRAL_EXTENSION,
15
15
  password: process.env.RINGCENTRAL_PASSWORD
16
16
  })
17
17
  const softphone = new Softphone(rc)
18
18
  await softphone.register()
19
- await rc.logout() // rc is no longer needed
19
+ await rc.revoke() // rc is no longer needed
20
20
  softphone.on('INVITE', async sipMessage => {
21
21
  softphone.toVoicemail(sipMessage)
22
22
  })
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = __importDefault(require("@rc-ex/core"));
7
+ const index_1 = __importDefault(require("../../src/index"));
8
+ const rc = new core_1.default({
9
+ server: process.env.RINGCENTRAL_SERVER_URL,
10
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
11
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
12
+ });
13
+ (async () => {
14
+ await rc.authorize({
15
+ username: process.env.RINGCENTRAL_USERNAME,
16
+ extension: process.env.RINGCENTRAL_EXTENSION,
17
+ password: process.env.RINGCENTRAL_PASSWORD,
18
+ });
19
+ const softphone = new index_1.default(rc);
20
+ await softphone.register();
21
+ await rc.revoke(); // rc is no longer needed
22
+ const audioElement = document.getElementById('audio');
23
+ softphone.on('INVITE', async (sipMessage) => {
24
+ const inputAudioStream = await navigator.mediaDevices.getUserMedia({
25
+ audio: true,
26
+ video: false,
27
+ });
28
+ softphone.answer(sipMessage, inputAudioStream);
29
+ softphone.once('track', e => {
30
+ audioElement.srcObject = e.streams[0];
31
+ softphone.once('BYE', () => {
32
+ audioElement.srcObject = null;
33
+ });
34
+ });
35
+ });
36
+ })();
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../demos/browser/index.ts"],"names":[],"mappings":";;;;;AAAA,uDAAsC;AAEtC,4DAAwC;AAExC,MAAM,EAAE,GAAG,IAAI,cAAW,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAC1C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;IAC3C,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;CACpD,CAAC,CAAC;AAEH,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,EAAE,CAAC,SAAS,CAAC;QACjB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;QAC3C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;QAC5C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;KAC5C,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,eAAS,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,yBAAyB;IAE5C,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAqB,CAAC;IAC1E,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAC,UAAU,EAAC,EAAE;QACxC,MAAM,gBAAgB,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC;YACjE,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;QACH,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAC/C,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YAC1B,YAAY,CAAC,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YACtC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;gBACzB,YAAY,CAAC,SAAS,GAAG,IAAI,CAAC;YAChC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = __importDefault(require("@rc-ex/core"));
7
+ // eslint-disable-next-line node/no-unpublished-import
8
+ const wrtc_1 = __importDefault(require("wrtc"));
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const index_1 = __importDefault(require("../../src/index"));
11
+ const rc = new core_1.default({
12
+ server: process.env.RINGCENTRAL_SERVER_URL,
13
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
14
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
15
+ });
16
+ (async () => {
17
+ await rc.authorize({
18
+ username: process.env.RINGCENTRAL_USERNAME,
19
+ extension: process.env.RINGCENTRAL_EXTENSION,
20
+ password: process.env.RINGCENTRAL_PASSWORD,
21
+ });
22
+ const softphone = new index_1.default(rc);
23
+ await softphone.register();
24
+ await rc.revoke(); // rc is no longer needed
25
+ softphone.on('INVITE', async (sipMessage) => {
26
+ softphone.answer(sipMessage);
27
+ softphone.once('track', e => {
28
+ const audioFilePath = 'audio.raw';
29
+ if (fs_1.default.existsSync(audioFilePath)) {
30
+ fs_1.default.unlinkSync(audioFilePath);
31
+ }
32
+ const writeStream = fs_1.default.createWriteStream(audioFilePath, { flags: 'a' });
33
+ const audioSink = new wrtc_1.default.nonstandard.RTCAudioSink(e.track);
34
+ audioSink.ondata = (data) => {
35
+ writeStream.write(Buffer.from(data.samples.buffer));
36
+ };
37
+ softphone.once('BYE', () => {
38
+ audioSink.stop();
39
+ writeStream.end();
40
+ });
41
+ });
42
+ });
43
+ })();
44
+ // You can play the saved audio by: play -b 16 -e signed -c 1 -r 48000 audio.raw
45
+ //# sourceMappingURL=answer-and-save.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answer-and-save.js","sourceRoot":"","sources":["../../../demos/node/answer-and-save.ts"],"names":[],"mappings":";;;;;AAAA,uDAAsC;AACtC,sDAAsD;AACtD,gDAAwB;AACxB,4CAAoB;AAEpB,4DAAwC;AAExC,MAAM,EAAE,GAAG,IAAI,cAAW,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAC1C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;IAC3C,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;CACpD,CAAC,CAAC;AAEH,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,EAAE,CAAC,SAAS,CAAC;QACjB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;QAC3C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;QAC5C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;KAC5C,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,eAAS,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,yBAAyB;IAC5C,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAC,UAAU,EAAC,EAAE;QACxC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7B,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YAC1B,MAAM,aAAa,GAAG,WAAW,CAAC;YAClC,IAAI,YAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;gBAChC,YAAE,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;aAC9B;YACD,MAAM,WAAW,GAAG,YAAE,CAAC,iBAAiB,CAAC,aAAa,EAAE,EAAC,KAAK,EAAE,GAAG,EAAC,CAAC,CAAC;YACtE,MAAM,SAAS,GAAG,IAAI,cAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAC7D,SAAS,CAAC,MAAM,GAAG,CAAC,IAAS,EAAE,EAAE;gBAC/B,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;YACtD,CAAC,CAAC;YACF,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;gBACzB,SAAS,CAAC,IAAI,EAAE,CAAC;gBACjB,WAAW,CAAC,GAAG,EAAE,CAAC;YACpB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC;AACL,gFAAgF"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /* eslint-disable node/no-unpublished-import */
7
+ const core_1 = __importDefault(require("@rc-ex/core"));
8
+ const node_webrtc_media_devices_1 = __importDefault(require("node-webrtc-media-devices"));
9
+ const speaker_1 = __importDefault(require("speaker"));
10
+ const wrtc_1 = __importDefault(require("wrtc"));
11
+ const index_1 = __importDefault(require("../../src/index"));
12
+ const { RTCAudioSink } = wrtc_1.default.nonstandard;
13
+ const rc = new core_1.default({
14
+ server: process.env.RINGCENTRAL_SERVER_URL,
15
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
16
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
17
+ });
18
+ (async () => {
19
+ await rc.authorize({
20
+ username: process.env.RINGCENTRAL_USERNAME,
21
+ extension: process.env.RINGCENTRAL_EXTENSION,
22
+ password: process.env.RINGCENTRAL_PASSWORD,
23
+ });
24
+ const softphone = new index_1.default(rc);
25
+ await softphone.register();
26
+ await rc.revoke(); // rc is no longer needed
27
+ softphone.on('track', e => {
28
+ const speaker = new speaker_1.default({
29
+ channels: 1,
30
+ bitDepth: 16,
31
+ sampleRate: 48000,
32
+ // signed: true,
33
+ });
34
+ const audioSink = new RTCAudioSink(e.track);
35
+ audioSink.ondata = (data) => {
36
+ speaker.write(Buffer.from(data.samples.buffer));
37
+ };
38
+ softphone.once('BYE', () => {
39
+ audioSink.stop();
40
+ speaker.close(true);
41
+ });
42
+ });
43
+ const inputAudioStream = await node_webrtc_media_devices_1.default.getUserMedia({
44
+ audio: true,
45
+ video: false,
46
+ });
47
+ softphone.invite(process.env.CALLEE_FOR_TESTING, inputAudioStream);
48
+ })();
49
+ //# sourceMappingURL=outbound-call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outbound-call.js","sourceRoot":"","sources":["../../../demos/node/outbound-call.ts"],"names":[],"mappings":";;;;;AAAA,+CAA+C;AAC/C,uDAAsC;AACtC,0FAAqD;AACrD,sDAA8B;AAC9B,gDAAwB;AAExB,4DAAwC;AAExC,MAAM,EAAC,YAAY,EAAC,GAAG,cAAI,CAAC,WAAW,CAAC;AAExC,MAAM,EAAE,GAAG,IAAI,cAAW,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAC1C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;IAC3C,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;CACpD,CAAC,CAAC;AAEH,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,EAAE,CAAC,SAAS,CAAC;QACjB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;QAC3C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;QAC5C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;KAC5C,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,eAAS,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,yBAAyB;IAC5C,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;QACxB,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC;YAC1B,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,KAAK;YACjB,gBAAgB;SACjB,CAAC,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC5C,SAAS,CAAC,MAAM,GAAG,CAAC,IAAS,EAAE,EAAE;YAC/B,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC;QACF,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;YACzB,SAAS,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,MAAM,mCAAY,CAAC,YAAY,CAAC;QACvD,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IACH,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAmB,EAAE,gBAAgB,CAAC,CAAC;AACtE,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const core_1 = __importDefault(require("@rc-ex/core"));
7
+ // eslint-disable-next-line node/no-unpublished-import
8
+ const wrtc_1 = __importDefault(require("wrtc"));
9
+ // eslint-disable-next-line node/no-unpublished-import
10
+ const node_webrtc_audio_stream_source_1 = __importDefault(require("node-webrtc-audio-stream-source"));
11
+ const fs_1 = __importDefault(require("fs"));
12
+ const index_1 = __importDefault(require("../../src/index"));
13
+ const rc = new core_1.default({
14
+ server: process.env.RINGCENTRAL_SERVER_URL,
15
+ clientId: process.env.RINGCENTRAL_CLIENT_ID,
16
+ clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET,
17
+ });
18
+ (async () => {
19
+ await rc.authorize({
20
+ username: process.env.RINGCENTRAL_USERNAME,
21
+ extension: process.env.RINGCENTRAL_EXTENSION,
22
+ password: process.env.RINGCENTRAL_PASSWORD,
23
+ });
24
+ const softphone = new index_1.default(rc);
25
+ await softphone.register();
26
+ await rc.revoke(); // rc is no longer needed
27
+ const rtcAudioStreamSource = new node_webrtc_audio_stream_source_1.default();
28
+ const track = rtcAudioStreamSource.createTrack();
29
+ const inputAudioStream = new wrtc_1.default.MediaStream();
30
+ inputAudioStream.addTrack(track);
31
+ softphone.invite(process.env.CALLEE_FOR_TESTING, inputAudioStream);
32
+ softphone.once('track', (e) => {
33
+ rtcAudioStreamSource.addStream(fs_1.default.createReadStream('test.wav'), 16, 48000, 1);
34
+ });
35
+ })();
36
+ //# sourceMappingURL=send-audio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send-audio.js","sourceRoot":"","sources":["../../../demos/node/send-audio.ts"],"names":[],"mappings":";;;;;AAAA,uDAAsC;AACtC,sDAAsD;AACtD,gDAAwB;AACxB,sDAAsD;AACtD,sGAAmE;AACnE,4CAAoB;AAEpB,4DAAwC;AAExC,MAAM,EAAE,GAAG,IAAI,cAAW,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB;IAC1C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;IAC3C,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB;CACpD,CAAC,CAAC;AAEH,CAAC,KAAK,IAAI,EAAE;IACV,MAAM,EAAE,CAAC,SAAS,CAAC;QACjB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;QAC3C,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB;QAC5C,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAqB;KAC5C,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,eAAS,CAAC,EAAE,CAAC,CAAC;IACpC,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,yBAAyB;IAE5C,MAAM,oBAAoB,GAAG,IAAI,yCAAoB,EAAE,CAAC;IACxD,MAAM,KAAK,GAAG,oBAAoB,CAAC,WAAW,EAAE,CAAC;IACjD,MAAM,gBAAgB,GAAG,IAAI,cAAI,CAAC,WAAW,EAAE,CAAC;IAChD,gBAAgB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAmB,EAAE,gBAAgB,CAAC,CAAC;IAEpE,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAM,EAAE,EAAE;QACjC,oBAAoB,CAAC,SAAS,CAC5B,YAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAC/B,EAAE,EACF,KAAK,EACL,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};