ringcentral-softphone 0.6.2 → 0.7.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/README.md +33 -2
- package/dist/call-session/inbound.d.ts +8 -0
- package/dist/call-session/inbound.js +48 -0
- package/dist/call-session/inbound.js.map +1 -0
- package/dist/call-session/index.d.ts +24 -0
- package/dist/call-session/index.js +113 -0
- package/dist/call-session/index.js.map +1 -0
- package/dist/call-session/outbound.d.ts +9 -0
- package/dist/call-session/outbound.js +52 -0
- package/dist/call-session/outbound.js.map +1 -0
- package/dist/dtmf.d.ts +1 -1
- package/dist/dtmf.js +20 -23
- package/dist/dtmf.js.map +1 -1
- package/dist/index.js +74 -60
- package/dist/index.js.map +1 -1
- package/dist/sip-message/inbound/index.js +10 -30
- package/dist/sip-message/inbound/index.js.map +1 -1
- package/dist/sip-message/index.d.ts +2 -2
- package/dist/sip-message/index.js +4 -4
- package/dist/sip-message/index.js.map +1 -1
- package/dist/sip-message/outbound/index.js +7 -28
- package/dist/sip-message/outbound/index.js.map +1 -1
- package/dist/sip-message/outbound/request.d.ts +7 -0
- package/dist/sip-message/outbound/request.js +29 -0
- package/dist/sip-message/outbound/request.js.map +1 -0
- package/dist/sip-message/outbound/response.d.ts +6 -0
- package/dist/sip-message/outbound/response.js +22 -0
- package/dist/sip-message/outbound/response.js.map +1 -0
- package/dist/sip-message/response-codes.js +1 -1
- package/dist/sip-message/response-codes.js.map +1 -1
- package/dist/sip-message/sip-message.js +16 -24
- package/dist/sip-message/sip-message.js.map +1 -1
- package/dist/softphone.d.ts +3 -1
- package/dist/softphone.js +134 -177
- package/dist/softphone.js.map +1 -1
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +20 -14
- package/dist/utils.js.map +1 -1
- package/package.json +6 -7
- package/src/call-session/inbound.ts +41 -0
- package/src/{inbound-call-session.ts → call-session/index.ts} +56 -80
- package/src/call-session/outbound.ts +39 -0
- package/src/dtmf.ts +3 -1
- package/src/index.ts +51 -11
- package/src/sip-message/index.ts +2 -2
- package/src/sip-message/outbound/{request-message.ts → request.ts} +3 -1
- package/src/sip-message/sip-message.ts +7 -1
- package/src/softphone.ts +57 -41
- package/src/utils.ts +9 -4
- package/tsconfig.json +3 -1
- /package/src/sip-message/outbound/{response-message.ts → response.ts} +0 -0
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ yarn install ringcentral-softphone
|
|
|
25
25
|
|
|
26
26
|
## Usage
|
|
27
27
|
|
|
28
|
-
```
|
|
28
|
+
```ts
|
|
29
29
|
import fs from 'fs';
|
|
30
30
|
import Softphone from 'ringcentral-softphone';
|
|
31
31
|
import type { RtpPacket } from 'werift-rtp';
|
|
@@ -35,6 +35,7 @@ const softphone = new Softphone({
|
|
|
35
35
|
password: process.env.SIP_INFO_PASSWORD,
|
|
36
36
|
authorizationId: process.env.SIP_INFO_AUTHORIZATION_ID,
|
|
37
37
|
});
|
|
38
|
+
softphone.enableDebugMode(); // optional, print all SIP messages
|
|
38
39
|
const main = async () => {
|
|
39
40
|
await softphone.register();
|
|
40
41
|
// inbound call
|
|
@@ -45,6 +46,10 @@ const main = async () => {
|
|
|
45
46
|
const writeStream = fs.createWriteStream(`${callSession.callId}.raw`, { flags: 'a' });
|
|
46
47
|
callSession.on('audioPacket', (rtpPacket: RtpPacket) => {
|
|
47
48
|
writeStream.write(rtpPacket.payload);
|
|
49
|
+
});
|
|
50
|
+
// either you or the peer hang up
|
|
51
|
+
callSession.on('disposed', () => {
|
|
52
|
+
writeStream.close();
|
|
48
53
|
});
|
|
49
54
|
// receive DTMF
|
|
50
55
|
callSession.on('dtmf', (digit) => {
|
|
@@ -58,6 +63,25 @@ main();
|
|
|
58
63
|
For a complete example, see [src/index.ts](src/index.ts)
|
|
59
64
|
|
|
60
65
|
|
|
66
|
+
## Supported features
|
|
67
|
+
|
|
68
|
+
- inbound call
|
|
69
|
+
- outbound call
|
|
70
|
+
- inbund DTMF
|
|
71
|
+
- outbound DTMF
|
|
72
|
+
- reject inbound call
|
|
73
|
+
- cancel outbound call
|
|
74
|
+
- hang up ongoing call
|
|
75
|
+
- receive remote autio stream
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## How to test
|
|
79
|
+
|
|
80
|
+
Make a phone call to you device's number.
|
|
81
|
+
|
|
82
|
+
There will be audio stream coming in. And you can also get the DTMF digits the caller pressed.
|
|
83
|
+
|
|
84
|
+
|
|
61
85
|
## Notes
|
|
62
86
|
|
|
63
87
|
### How to play saved audio file
|
|
@@ -75,7 +99,14 @@ play -b 8 -r 8000 -e mu-law test.raw
|
|
|
75
99
|
|
|
76
100
|
## Todo
|
|
77
101
|
|
|
78
|
-
- outbound call
|
|
79
102
|
- Try other payload types, such as OPUS
|
|
80
103
|
- support callerId
|
|
81
104
|
- do not hard code `domain` and `outboundProxy`
|
|
105
|
+
- send audio to remote peer
|
|
106
|
+
- check the code of PJSIP and refactor the code.
|
|
107
|
+
- Let user check the call info, such as who is calling, who is being called, etc.
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
## Dev Notes
|
|
111
|
+
|
|
112
|
+
- We don't need to explicitly tell remote server our local RTP port vis SIP SDP message. We will have to send a RTP message to the remote server first, so the remote server knows our IP and port. So the port number in SDP message could be fake.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type InboundMessage } from '../sip-message';
|
|
2
|
+
import type Softphone from '../softphone';
|
|
3
|
+
import CallSession from '.';
|
|
4
|
+
declare class InboundCallSession extends CallSession {
|
|
5
|
+
constructor(softphone: Softphone, inviteMessage: InboundMessage);
|
|
6
|
+
answer(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export default InboundCallSession;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const sip_message_1 = require("../sip-message");
|
|
16
|
+
const utils_1 = require("../utils");
|
|
17
|
+
const _1 = __importDefault(require("."));
|
|
18
|
+
class InboundCallSession extends _1.default {
|
|
19
|
+
constructor(softphone, inviteMessage) {
|
|
20
|
+
super(softphone, inviteMessage);
|
|
21
|
+
this.localPeer = inviteMessage.headers.To;
|
|
22
|
+
this.remotePeer = inviteMessage.headers.From;
|
|
23
|
+
}
|
|
24
|
+
answer() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const answerSDP = `
|
|
27
|
+
v=0
|
|
28
|
+
o=- ${(0, utils_1.randomInt)()} 0 IN IP4 127.0.0.1
|
|
29
|
+
s=rc-softphone-ts
|
|
30
|
+
c=IN IP4 127.0.0.1
|
|
31
|
+
t=0 0
|
|
32
|
+
m=audio ${(0, utils_1.randomInt)()} RTP/AVP 0 101
|
|
33
|
+
a=rtpmap:0 PCMU/8000
|
|
34
|
+
a=rtpmap:101 telephone-event/8000
|
|
35
|
+
a=fmtp:101 0-15
|
|
36
|
+
a=sendrecv
|
|
37
|
+
a=ssrc:${(0, utils_1.randomInt)()} cname:${(0, utils_1.uuid)()}
|
|
38
|
+
`.trim();
|
|
39
|
+
const newMessage = new sip_message_1.ResponseMessage(this.sipMessage, 200, {
|
|
40
|
+
'Content-Type': 'application/sdp',
|
|
41
|
+
}, answerSDP);
|
|
42
|
+
this.softphone.send(newMessage);
|
|
43
|
+
this.startLocalServices();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.default = InboundCallSession;
|
|
48
|
+
//# sourceMappingURL=inbound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbound.js","sourceRoot":"","sources":["../../src/call-session/inbound.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDAAsE;AACtE,oCAA2C;AAE3C,yCAA4B;AAE5B,MAAM,kBAAmB,SAAQ,UAAW;IAC1C,YAAmB,SAAoB,EAAE,aAA6B;QACpE,KAAK,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/C,CAAC;IAEY,MAAM;;YACjB,MAAM,SAAS,GAAG;;MAEhB,IAAA,iBAAS,GAAE;;;;UAIP,IAAA,iBAAS,GAAE;;;;;SAKZ,IAAA,iBAAS,GAAE,UAAU,IAAA,YAAI,GAAE;CACnC,CAAC,IAAI,EAAE,CAAC;YACL,MAAM,UAAU,GAAG,IAAI,6BAAe,CACpC,IAAI,CAAC,UAAU,EACf,GAAG,EACH;gBACE,cAAc,EAAE,iBAAiB;aAClC,EACD,SAAS,CACV,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAEhC,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC5B,CAAC;KAAA;CACF;AAED,kBAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
4
|
+
import EventEmitter from 'events';
|
|
5
|
+
import dgram from 'dgram';
|
|
6
|
+
import { type InboundMessage } from '../sip-message';
|
|
7
|
+
import type Softphone from '../softphone';
|
|
8
|
+
declare abstract class CallSession extends EventEmitter {
|
|
9
|
+
softphone: Softphone;
|
|
10
|
+
sipMessage: InboundMessage;
|
|
11
|
+
socket: dgram.Socket;
|
|
12
|
+
localPeer: string;
|
|
13
|
+
remotePeer: string;
|
|
14
|
+
remoteIP: string;
|
|
15
|
+
remotePort: number;
|
|
16
|
+
constructor(softphone: Softphone, sipMessage: InboundMessage);
|
|
17
|
+
get callId(): string;
|
|
18
|
+
send(data: string | Buffer): void;
|
|
19
|
+
hangup(): Promise<void>;
|
|
20
|
+
sendDTMF(char: '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '*' | '#'): Promise<void>;
|
|
21
|
+
protected startLocalServices(): Promise<void>;
|
|
22
|
+
private dispose;
|
|
23
|
+
}
|
|
24
|
+
export default CallSession;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const events_1 = __importDefault(require("events"));
|
|
16
|
+
const dgram_1 = __importDefault(require("dgram"));
|
|
17
|
+
const werift_rtp_1 = require("werift-rtp");
|
|
18
|
+
const sip_message_1 = require("../sip-message");
|
|
19
|
+
const utils_1 = require("../utils");
|
|
20
|
+
const dtmf_1 = __importDefault(require("../dtmf"));
|
|
21
|
+
class CallSession extends events_1.default {
|
|
22
|
+
constructor(softphone, sipMessage) {
|
|
23
|
+
super();
|
|
24
|
+
this.softphone = softphone;
|
|
25
|
+
this.sipMessage = sipMessage;
|
|
26
|
+
this.remoteIP = this.sipMessage.body.match(/c=IN IP4 ([\d.]+)/)[1];
|
|
27
|
+
this.remotePort = parseInt(this.sipMessage.body.match(/m=audio (\d+) /)[1], 10);
|
|
28
|
+
}
|
|
29
|
+
get callId() {
|
|
30
|
+
return this.sipMessage.headers['Call-Id'];
|
|
31
|
+
}
|
|
32
|
+
send(data) {
|
|
33
|
+
this.socket.send(data, this.remotePort, this.remoteIP);
|
|
34
|
+
}
|
|
35
|
+
hangup() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const requestMessage = new sip_message_1.RequestMessage(`BYE sip:${this.softphone.sipInfo.domain} SIP/2.0`, {
|
|
38
|
+
'Call-Id': this.callId,
|
|
39
|
+
From: this.localPeer,
|
|
40
|
+
To: this.remotePeer,
|
|
41
|
+
Via: `SIP/2.0/TCP ${this.softphone.fakeDomain};branch=${(0, utils_1.uuid)()}`,
|
|
42
|
+
});
|
|
43
|
+
this.softphone.send(requestMessage);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
sendDTMF(char) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const timestamp = Math.floor(Date.now() / 1000);
|
|
49
|
+
let sequenceNumber = timestamp % 65536;
|
|
50
|
+
const rtpHeader = new werift_rtp_1.RtpHeader({
|
|
51
|
+
version: 2,
|
|
52
|
+
padding: false,
|
|
53
|
+
paddingSize: 0,
|
|
54
|
+
extension: false,
|
|
55
|
+
marker: false,
|
|
56
|
+
payloadOffset: 12,
|
|
57
|
+
payloadType: 101,
|
|
58
|
+
sequenceNumber,
|
|
59
|
+
timestamp,
|
|
60
|
+
ssrc: (0, utils_1.randomInt)(),
|
|
61
|
+
csrcLength: 0,
|
|
62
|
+
csrc: [],
|
|
63
|
+
extensionProfile: 48862,
|
|
64
|
+
extensionLength: undefined,
|
|
65
|
+
extensions: [],
|
|
66
|
+
});
|
|
67
|
+
for (const payload of dtmf_1.default.charToPayloads(char)) {
|
|
68
|
+
rtpHeader.sequenceNumber = sequenceNumber++;
|
|
69
|
+
const rtpPacket = new werift_rtp_1.RtpPacket(rtpHeader, payload);
|
|
70
|
+
this.send(rtpPacket.serialize());
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
startLocalServices() {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
this.socket = dgram_1.default.createSocket('udp4');
|
|
77
|
+
this.socket.on('message', (message) => {
|
|
78
|
+
const rtpPacket = werift_rtp_1.RtpPacket.deSerialize(message);
|
|
79
|
+
this.emit('rtpPacket', rtpPacket);
|
|
80
|
+
if (rtpPacket.header.payloadType === 101) {
|
|
81
|
+
this.emit('dtmfPacket', rtpPacket);
|
|
82
|
+
const char = dtmf_1.default.payloadToChar(rtpPacket.payload);
|
|
83
|
+
if (char) {
|
|
84
|
+
this.emit('dtmf', char);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.emit('audioPacket', rtpPacket);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
this.socket.bind();
|
|
92
|
+
// send a message to remote server so that it knows where to reply
|
|
93
|
+
this.send('hello');
|
|
94
|
+
const byeHandler = (inboundMessage) => {
|
|
95
|
+
if (inboundMessage.headers['Call-Id'] !== this.callId) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (inboundMessage.headers.CSeq.endsWith(' BYE')) {
|
|
99
|
+
this.softphone.off('message', byeHandler);
|
|
100
|
+
this.dispose();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
this.softphone.on('message', byeHandler);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
dispose() {
|
|
107
|
+
this.emit('disposed');
|
|
108
|
+
this.socket.removeAllListeners();
|
|
109
|
+
this.socket.close();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.default = CallSession;
|
|
113
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/call-session/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,kDAA0B;AAC1B,2CAAkD;AAElD,gDAAqE;AAErE,oCAA2C;AAC3C,mDAA2B;AAE3B,MAAe,WAAY,SAAQ,gBAAY;IAS7C,YAAmB,SAAoB,EAAE,UAA0B;QACjE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAE,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnF,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAEM,IAAI,CAAC,IAAqB;QAC/B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACzD,CAAC;IAEY,MAAM;;YACjB,MAAM,cAAc,GAAG,IAAI,4BAAc,CA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;YACH,CAAC,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC3C,CAAC;KAAA;IAEO,OAAO;QACb,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF;AAED,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type InboundMessage } from '../sip-message';
|
|
2
|
+
import type Softphone from '../softphone';
|
|
3
|
+
import CallSession from '.';
|
|
4
|
+
declare class OutboundCallSession extends CallSession {
|
|
5
|
+
constructor(softphone: Softphone, answerMessage: InboundMessage);
|
|
6
|
+
init(): Promise<void>;
|
|
7
|
+
cancel(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export default OutboundCallSession;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const sip_message_1 = require("../sip-message");
|
|
16
|
+
const _1 = __importDefault(require("."));
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
class OutboundCallSession extends _1.default {
|
|
19
|
+
constructor(softphone, answerMessage) {
|
|
20
|
+
super(softphone, answerMessage);
|
|
21
|
+
this.localPeer = answerMessage.headers.From;
|
|
22
|
+
this.remotePeer = answerMessage.headers.To;
|
|
23
|
+
this.init();
|
|
24
|
+
}
|
|
25
|
+
init() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
// wait for user to answer the call
|
|
28
|
+
const answerHandler = (message) => {
|
|
29
|
+
if (message.headers.CSeq === this.sipMessage.headers.CSeq) {
|
|
30
|
+
this.softphone.off('message', answerHandler);
|
|
31
|
+
this.emit('answered');
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
this.softphone.on('message', answerHandler);
|
|
35
|
+
this.once('answered', () => __awaiter(this, void 0, void 0, function* () { return this.startLocalServices(); }));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
cancel() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const requestMessage = new sip_message_1.RequestMessage(`CANCEL ${(0, utils_1.extractAddress)(this.remotePeer)} SIP/2.0`, {
|
|
41
|
+
'Call-Id': this.callId,
|
|
42
|
+
From: this.localPeer,
|
|
43
|
+
To: (0, utils_1.withoutTag)(this.remotePeer),
|
|
44
|
+
Via: this.sipMessage.headers.Via,
|
|
45
|
+
CSeq: this.sipMessage.headers.CSeq.replace(' INVITE', ' CANCEL'),
|
|
46
|
+
});
|
|
47
|
+
this.softphone.send(requestMessage);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = OutboundCallSession;
|
|
52
|
+
//# sourceMappingURL=outbound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbound.js","sourceRoot":"","sources":["../../src/call-session/outbound.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,gDA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U,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,SAAS,CAAC;aACjE,CAAC,CAAC;YACH,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACtC,CAAC;KAAA;CACF;AAED,kBAAe,mBAAmB,CAAC"}
|
package/dist/dtmf.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
declare class DTMF {
|
|
3
|
-
|
|
3
|
+
static readonly phoneChars: string[];
|
|
4
4
|
private static readonly payloads;
|
|
5
5
|
static charToPayloads: (char: string) => Buffer[];
|
|
6
6
|
static payloadToChar: (payload: Buffer) => string;
|
package/dist/dtmf.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class DTMF {
|
|
4
|
+
}
|
|
5
|
+
DTMF.phoneChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '#'];
|
|
6
|
+
DTMF.payloads = [0x00060000, 0x000600a0, 0x00060140, 0x00860320, 0x00860320, 0x00860320];
|
|
7
|
+
DTMF.charToPayloads = (char) => {
|
|
8
|
+
const index = DTMF.phoneChars.indexOf(char[0]);
|
|
9
|
+
if (index === -1) {
|
|
10
|
+
throw new Error('invalid phone char');
|
|
5
11
|
}
|
|
6
|
-
DTMF.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
DTMF.payloadToChar = function (payload) {
|
|
21
|
-
var intBE = payload.readIntBE(0, 4);
|
|
22
|
-
var index = (intBE - 0x00060000) / 0x01000000;
|
|
23
|
-
return DTMF.phoneChars[index];
|
|
24
|
-
};
|
|
25
|
-
return DTMF;
|
|
26
|
-
}());
|
|
12
|
+
return DTMF.payloads.map((payload) => {
|
|
13
|
+
const temp = payload + index * 0x01000000;
|
|
14
|
+
const buffer = Buffer.alloc(4);
|
|
15
|
+
buffer.writeIntBE(temp, 0, 4);
|
|
16
|
+
return buffer;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
DTMF.payloadToChar = (payload) => {
|
|
20
|
+
const intBE = payload.readIntBE(0, 4);
|
|
21
|
+
const index = (intBE - 0x00060000) / 0x01000000;
|
|
22
|
+
return DTMF.phoneChars[index];
|
|
23
|
+
};
|
|
27
24
|
exports.default = DTMF;
|
|
28
25
|
//# sourceMappingURL=dtmf.js.map
|
package/dist/dtmf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dtmf.js","sourceRoot":"","sources":["../src/dtmf.ts"],"names":[],"mappings":";;AAAA
|
|
1
|
+
{"version":3,"file":"dtmf.js","sourceRoot":"","sources":["../src/dtmf.ts"],"names":[],"mappings":";;AAAA,MAAM,IAAI;;AACe,eAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACzE,aAAQ,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAE9F,mBAAc,GAAG,CAAC,IAAY,EAAE,EAAE;IAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE;QACnC,MAAM,IAAI,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9B,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEY,kBAAa,GAAG,CAAC,OAAe,EAAE,EAAE;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;IAChD,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC,CAAC;AAGJ,kBAAe,IAAI,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,75 +8,89 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
13
|
};
|
|
41
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
|
|
43
|
-
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const softphone_1 = __importDefault(require("./softphone"));
|
|
44
17
|
// import waitFor from 'wait-for-async';
|
|
45
|
-
|
|
18
|
+
const softphone = new softphone_1.default({
|
|
46
19
|
username: process.env.SIP_INFO_USERNAME,
|
|
47
20
|
password: process.env.SIP_INFO_PASSWORD,
|
|
48
21
|
authorizationId: process.env.SIP_INFO_AUTHORIZATION_ID,
|
|
49
22
|
});
|
|
50
23
|
softphone.enableDebugMode(); // print all SIP messages
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
24
|
+
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
yield softphone.register();
|
|
26
|
+
// inbound call
|
|
27
|
+
softphone.on('invite', (inviteMessage) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
// decline the call
|
|
29
|
+
// await waitFor({ interval: 1000 });
|
|
30
|
+
// await softphone.decline(inviteMessage);
|
|
31
|
+
// answer the call
|
|
32
|
+
const callSession = yield softphone.answer(inviteMessage);
|
|
33
|
+
// receive audio
|
|
34
|
+
const writeStream = fs_1.default.createWriteStream(`${callSession.callId}.raw`, { flags: 'a' });
|
|
35
|
+
callSession.on('audioPacket', (rtpPacket) => {
|
|
36
|
+
writeStream.write(rtpPacket.payload);
|
|
37
|
+
});
|
|
38
|
+
// either you or the peer hang up
|
|
39
|
+
callSession.once('disposed', () => {
|
|
40
|
+
writeStream.close();
|
|
41
|
+
});
|
|
42
|
+
// receive DTMF
|
|
43
|
+
callSession.on('dtmf', (digit) => {
|
|
44
|
+
console.log('dtmf', digit);
|
|
45
|
+
});
|
|
46
|
+
// // send DTMF
|
|
47
|
+
// setTimeout(() => {
|
|
48
|
+
// callSession.sendDTMF('1');
|
|
49
|
+
// }, 2000);
|
|
50
|
+
// setTimeout(() => {
|
|
51
|
+
// callSession.sendDTMF('#');
|
|
52
|
+
// }, 4000);
|
|
53
|
+
// // hang up the call
|
|
54
|
+
// setTimeout(() => {
|
|
55
|
+
// callSession.hangup();
|
|
56
|
+
// }, 5000);
|
|
57
|
+
}));
|
|
58
|
+
// outbound call
|
|
59
|
+
setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
// callee format sample: 16506668888
|
|
61
|
+
const callSession = yield softphone.call(parseInt(process.env.CALLEE_FOR_TESTING, 10));
|
|
62
|
+
// callee answers the call
|
|
63
|
+
callSession.once('answered', () => {
|
|
64
|
+
// receive audio
|
|
65
|
+
const writeStream = fs_1.default.createWriteStream(`${callSession.callId}.raw`, { flags: 'a' });
|
|
66
|
+
callSession.on('audioPacket', (rtpPacket) => {
|
|
67
|
+
writeStream.write(rtpPacket.payload);
|
|
68
|
+
});
|
|
69
|
+
// either you or the peer hang up
|
|
70
|
+
callSession.once('disposed', () => {
|
|
71
|
+
writeStream.close();
|
|
72
|
+
});
|
|
73
|
+
// receive DTMF
|
|
74
|
+
callSession.on('dtmf', (digit) => {
|
|
75
|
+
console.log('dtmf', digit);
|
|
76
|
+
});
|
|
77
|
+
// // send DTMF
|
|
78
|
+
// setTimeout(() => {
|
|
79
|
+
// callSession.sendDTMF('1');
|
|
80
|
+
// }, 2000);
|
|
81
|
+
// setTimeout(() => {
|
|
82
|
+
// callSession.sendDTMF('#');
|
|
83
|
+
// }, 4000);
|
|
84
|
+
// // hang up the call
|
|
85
|
+
// setTimeout(() => {
|
|
86
|
+
// callSession.hangup();
|
|
87
|
+
// }, 5000);
|
|
88
|
+
});
|
|
89
|
+
// // cancel the call (before the peer answers)
|
|
90
|
+
// setTimeout(() => {
|
|
91
|
+
// callSession.cancel();
|
|
92
|
+
// }, 8000);
|
|
93
|
+
}), 1000);
|
|
94
|
+
});
|
|
81
95
|
main();
|
|
82
96
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[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AY;QACd,CAAC,CAAC,CAAC;QAEH,+CAA+C;QAC/C,qBAAqB;QACrB,0BAA0B;QAC1B,YAAY;IACd,CAAC,CAAA,EAAE,IAAI,CAAC,CAAC;AACX,CAAC,CAAA,CAAC;AACF,IAAI,EAAE,CAAC"}
|
|
@@ -1,43 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
InboundMessage.fromString = function (str) {
|
|
29
|
-
var sipMessage = new sip_message_1.default();
|
|
30
|
-
var _a = str.split('\r\n\r\n'), init = _a[0], body = _a.slice(1);
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const sip_message_1 = __importDefault(require("../sip-message"));
|
|
8
|
+
class InboundMessage extends sip_message_1.default {
|
|
9
|
+
static fromString(str) {
|
|
10
|
+
const sipMessage = new sip_message_1.default();
|
|
11
|
+
const [init, ...body] = str.split('\r\n\r\n');
|
|
31
12
|
sipMessage.body = body.join('\r\n\r\n');
|
|
32
|
-
|
|
13
|
+
const [subject, ...headers] = init.split('\r\n');
|
|
33
14
|
sipMessage.subject = subject;
|
|
34
|
-
sipMessage.headers = Object.fromEntries(headers.map(
|
|
15
|
+
sipMessage.headers = Object.fromEntries(headers.map((line) => line.split(': ')));
|
|
35
16
|
if (sipMessage.headers.To && !sipMessage.headers.To.includes(';tag=')) {
|
|
36
17
|
sipMessage.headers.To += ';tag=' + (0, utils_1.uuid)(); // generate local tag
|
|
37
18
|
}
|
|
38
19
|
return sipMessage;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}(sip_message_1.default));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
42
22
|
exports.default = InboundMessage;
|
|
43
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sip-message/inbound/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sip-message/inbound/index.ts"],"names":[],"mappings":";;;;;AAAA,uCAAmC;AACnC,iEAAwC;AAExC,MAAM,cAAe,SAAQ,qBAAU;IAC9B,MAAM,CAAC,UAAU,CAAC,GAAW;QAClC,MAAM,UAAU,GAAG,IAAI,qBAAU,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC9C,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxC,MAAM,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACjD,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;QAC7B,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjF,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACtE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,OAAO,GAAG,IAAA,YAAI,GAAE,CAAC,CAAC,qBAAqB;QAClE,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|