drachtio-srf 5.0.13 → 5.0.14

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.
@@ -11,7 +11,7 @@ jobs:
11
11
  with:
12
12
  node-version: 20.x
13
13
  - run: npm install
14
- - run: npm run jslint
14
+ - run: npm run lint
15
15
  - name: Install Docker Compose
16
16
  run: |
17
17
  sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
package/README.md CHANGED
@@ -15,7 +15,7 @@ Please visit [drachtio.org](https://drachtio.org) for getting started instructio
15
15
  host: '192.168.32.5',
16
16
  port: 9022,
17
17
  secret: 'cymru'
18
- }) ;
18
+ });
19
19
 
20
20
  srf.invite((req, res) => {
21
21
  srf.proxyRequest(req, ['sip.example1.com', 'sip.example2.com'], {
@@ -37,7 +37,7 @@ Please visit [drachtio.org](https://drachtio.org) for getting started instructio
37
37
  host: '192.168.32.5',
38
38
  port: 9022,
39
39
  secret: 'cymru'
40
- }) ;
40
+ });
41
41
  const Srf = require('drachtio-srf');
42
42
  const srf = new Srf();
43
43
 
@@ -0,0 +1,134 @@
1
+ import globals from 'globals';
2
+ import pluginJs from '@eslint/js';
3
+ import pluginPromise from 'eslint-plugin-promise';
4
+ import stylisticJs from '@stylistic/eslint-plugin';
5
+
6
+ export default [
7
+ { files: ["**/*.js"], languageOptions: { sourceType: "commonjs" } },
8
+ {
9
+ languageOptions: {
10
+ globals: {
11
+ ...globals.node,
12
+ "DTRACE_HTTP_CLIENT_REQUEST": false,
13
+ "LTTNG_HTTP_CLIENT_REQUEST": false,
14
+ "COUNTER_HTTP_CLIENT_REQUEST": false,
15
+ "DTRACE_HTTP_CLIENT_RESPONSE": false,
16
+ "LTTNG_HTTP_CLIENT_RESPONSE": false,
17
+ "COUNTER_HTTP_CLIENT_RESPONSE": false,
18
+ "DTRACE_HTTP_SERVER_REQUEST": false,
19
+ "LTTNG_HTTP_SERVER_REQUEST": false,
20
+ "COUNTER_HTTP_SERVER_REQUEST": false,
21
+ "DTRACE_HTTP_SERVER_RESPONSE": false,
22
+ "LTTNG_HTTP_SERVER_RESPONSE": false,
23
+ "COUNTER_HTTP_SERVER_RESPONSE": false,
24
+ "DTRACE_NET_STREAM_END": false,
25
+ "LTTNG_NET_STREAM_END": false,
26
+ "COUNTER_NET_SERVER_CONNECTION_CLOSE": false,
27
+ "DTRACE_NET_SERVER_CONNECTION": false,
28
+ "LTTNG_NET_SERVER_CONNECTION": false,
29
+ "COUNTER_NET_SERVER_CONNECTION": false
30
+ },
31
+ parserOptions: {
32
+ ecmaFeatures: {
33
+ jsx: false,
34
+ modules: false
35
+ },
36
+ ecmaVersion: 2020
37
+ },
38
+ }
39
+ },
40
+ {
41
+ plugins: {
42
+ '@stylistic/js': stylisticJs
43
+ },
44
+ },
45
+ { ignores: ["test/**"] },
46
+ pluginJs.configs.recommended,
47
+ pluginPromise.configs['flat/recommended'],
48
+ { rules: {
49
+ "promise/always-return": "error",
50
+ "promise/no-return-wrap": "error",
51
+ "promise/param-names": "error",
52
+ "promise/catch-or-return": "error",
53
+ "promise/no-native": "off",
54
+ "promise/no-nesting": "warn",
55
+ "promise/no-promise-in-callback": "warn",
56
+ "promise/no-callback-in-promise": "warn",
57
+ "promise/no-return-in-finally": "warn",
58
+
59
+ // Possible Errors
60
+ "no-control-regex": 2,
61
+ "no-debugger": 2,
62
+ "no-dupe-args": 2,
63
+ "no-dupe-keys": 2,
64
+ "no-duplicate-case": 2,
65
+ "no-empty-character-class": 2,
66
+ "no-ex-assign": 2,
67
+ "no-extra-boolean-cast": 2,
68
+ "no-func-assign": 2,
69
+ "no-invalid-regexp": 2,
70
+ "no-irregular-whitespace": 2,
71
+ "no-negated-in-lhs": 2,
72
+ "no-obj-calls": 2,
73
+ "no-proto": 2,
74
+ "no-unexpected-multiline": 2,
75
+ "no-unreachable": 2,
76
+ "use-isnan": 2,
77
+ "valid-typeof": 2,
78
+
79
+ // Best Practices
80
+ "no-fallthrough": 2,
81
+ "no-octal": 2,
82
+ "no-redeclare": 2,
83
+ "no-self-assign": 2,
84
+ "no-unused-labels": 2,
85
+
86
+ // Strict Mode
87
+ "strict": [2, "never"],
88
+
89
+ // Variables
90
+ "no-delete-var": 2,
91
+ "no-undef": 2,
92
+ "no-unused-vars": [2, { args: "none" }],
93
+
94
+ // Node.js and CommonJS
95
+ "no-mixed-requires": 2,
96
+ "no-new-require": 2,
97
+ "no-path-concat": 2,
98
+ "no-restricted-modules": [2, "sys", "_linklist"],
99
+
100
+ // Stylistic Issues
101
+ "@stylistic/js/arrow-parens": [2, "always"],
102
+ "@stylistic/js/arrow-spacing": [2, { before: true, after: true }],
103
+ "@stylistic/js/comma-dangle": [2, "only-multiline"],
104
+ "@stylistic/js/comma-spacing": 2,
105
+ "@stylistic/js/eol-last": 2,
106
+ "@stylistic/js/indent": [2, 2, { SwitchCase: 1 }],
107
+ "@stylistic/js/keyword-spacing": 2,
108
+ "@stylistic/js/max-len": [2, 120, 2],
109
+ "@stylistic/js/new-parens": 2,
110
+ "@stylistic/js/no-extra-parens": [2, "functions"],
111
+ "@stylistic/js/no-extra-semi": 2,
112
+ "@stylistic/js/no-mixed-spaces-and-tabs": 2,
113
+ "@stylistic/js/no-multiple-empty-lines": [2, { max: 2 }],
114
+ "@stylistic/js/no-trailing-spaces": [2, { skipBlankLines: false }],
115
+ "@stylistic/js/quotes": [2, "single", { avoidEscape: true }],
116
+ "@stylistic/js/semi": 2,
117
+ "@stylistic/js/semi-spacing": ["error", {"before": false, "after": true}],
118
+ "@stylistic/js/space-before-blocks": [2, "always"],
119
+ "@stylistic/js/space-before-function-paren": [2, "never"],
120
+ "@stylistic/js/space-in-parens": [2, "never"],
121
+ "@stylistic/js/space-infix-ops": 2,
122
+ "@stylistic/js/space-unary-ops": 2,
123
+
124
+ // ECMAScript 6
125
+ "constructor-super": 2,
126
+ "no-class-assign": 2,
127
+ "no-confusing-arrow": 2,
128
+ "no-const-assign": 2,
129
+ "no-dupe-class-members": 2,
130
+ "no-new-symbol": 2,
131
+ "no-this-before-super": 2,
132
+ "prefer-const": 2
133
+ } }
134
+ ];
@@ -8,10 +8,10 @@ declare namespace Srf {
8
8
  type Via = { version: string; protocol: string; host: string; port: string; };
9
9
 
10
10
  export interface SrfConfig {
11
- apiSecret?: string;
12
11
  host?: string;
13
12
  port?: number;
14
13
  secret?: string;
14
+ logger?: (message: string) => void;
15
15
  }
16
16
 
17
17
  interface ParseUriResult {
@@ -32,7 +32,10 @@ declare namespace Srf {
32
32
  export interface SipMessage {
33
33
  type: "request" | "response";
34
34
  body: string;
35
- payload: object[];
35
+ payload: {
36
+ type: string | null;
37
+ content?: string;
38
+ }[];
36
39
  source: "network" | "application";
37
40
  source_address: string;
38
41
  source_port: string;
@@ -60,9 +63,9 @@ declare namespace Srf {
60
63
  callId: string;
61
64
  from: string;
62
65
  headers: Record<string, string>;
63
- msg: any;
66
+ msg: SipMessage;
64
67
  sdp: string;
65
- srf: any;
68
+ srf: Srf;
66
69
  to: string;
67
70
  uri: string;
68
71
  registration?: {
@@ -93,7 +96,7 @@ declare namespace Srf {
93
96
  end(): void;
94
97
  }
95
98
 
96
- export interface Dialog {
99
+ export class Dialog extends EventEmitter {
97
100
  sip: { callId: string; localTag: string; remoteTag: string; };
98
101
  onHold: boolean;
99
102
  other: Dialog;
@@ -106,19 +109,17 @@ declare namespace Srf {
106
109
  modify(opts: { noAck: boolean }): Promise<string>;
107
110
  modify(sdp: string, opts?: { noAck: boolean }, callback?: (err: any, msg: SrfResponse) => void): void;
108
111
  modify(opts: { noAck: boolean }, callback?: (err: any, resp?: string, resAck?: (sdp: string) => void) => void): void;
109
- on(messageType: "ack", callback: (msg: SrfRequest) => void): void;
110
- on(messageType: "destroy", callback: (msg: SrfRequest) => void): void;
111
- on(messageType: "info", callback: (req: SrfRequest, res: SrfResponse) => void): void;
112
- on(messageType: "message", callback: (req: SrfRequest, res: SrfResponse) => void): void;
113
- on(messageType: "modify", callback: (req: SrfRequest, res: SrfResponse) => void): void;
114
- on(messageType: "notify", callback: (req: SrfRequest, res: SrfResponse) => void): void;
115
- on(messageType: "options", callback: (req: SrfRequest, res: SrfResponse) => void): void;
116
- on(messageType: "refer", callback: (req: SrfRequest, res: SrfResponse) => void): void;
117
- on(messageType: "refresh", callback: (msg: SrfRequest) => void): void;
118
- on(messageType: "update", callback: (req: SrfRequest, res: SrfResponse) => void): void;
119
- on(messageType: "modify", callback: (req: SrfRequest, res: SrfResponse) => void): void;
120
- once(messageType: string, callback: (msg: SrfResponse) => void): void;
121
- listeners(messageType: string): any[];
112
+ on(messageType: "ack", callback: (msg: SrfRequest) => void): this;
113
+ on(messageType: "destroy", callback: (msg: SrfRequest) => void): this;
114
+ on(messageType: "info", callback: (req: SrfRequest, res: SrfResponse) => void): this;
115
+ on(messageType: "message", callback: (req: SrfRequest, res: SrfResponse) => void): this;
116
+ on(messageType: "modify", callback: (req: SrfRequest, res: SrfResponse) => void): this;
117
+ on(messageType: "notify", callback: (req: SrfRequest, res: SrfResponse) => void): this;
118
+ on(messageType: "options", callback: (req: SrfRequest, res: SrfResponse) => void): this;
119
+ on(messageType: "refer", callback: (req: SrfRequest, res: SrfResponse) => void): this;
120
+ on(messageType: "refresh", callback: (msg: SrfRequest) => void): this;
121
+ on(messageType: "update", callback: (req: SrfRequest, res: SrfResponse) => void): this;
122
+ once(messageType: string, callback: (msg: SrfResponse) => void): this;
122
123
  request(opts?: SrfRequest): Promise<SrfResponse>;
123
124
  request(opts: SrfRequest, callback?: (err: any, msg: SrfResponse) => void): void;
124
125
  }
@@ -155,6 +156,7 @@ declare class Srf extends EventEmitter {
155
156
  constructor();
156
157
  constructor(tags: string | string[]);
157
158
  connect(config?: Srf.SrfConfig): Promise<void>;
159
+ listen(opts?: Srf.SrfConfig): Promise<void>;
158
160
  disconnect(): void;
159
161
  use(callback: (req: Srf.SrfRequest, res: Srf.SrfResponse, next: Function) => void): void;
160
162
  use(messageType: string, callback: (req: Srf.SrfRequest, res: Srf.SrfResponse, next: Function) => void): void;
package/lib/connect.js CHANGED
@@ -1,7 +1,7 @@
1
- const EventEmitter = require('events').EventEmitter ;
2
- const proto = require('./proto') ;
1
+ const EventEmitter = require('events').EventEmitter;
2
+ const proto = require('./proto');
3
3
  const merge = require('utils-merge');
4
- const methods = require('sip-methods') ;
4
+ const methods = require('sip-methods');
5
5
 
6
6
  exports = module.exports = createServer;
7
7
 
@@ -21,8 +21,8 @@ function createServer() {
21
21
  merge(app, EventEmitter.prototype);
22
22
  app.stack = [];
23
23
  app.params = [];
24
- app._cachedEvents = [] ;
25
- app.routedMethods = {} ;
24
+ app._cachedEvents = [];
25
+ app.routedMethods = {};
26
26
  app.locals = Object.create(null);
27
27
  for (var i = 0; i < arguments.length; ++i) {
28
28
  app.use(arguments[i]);
@@ -30,30 +30,30 @@ function createServer() {
30
30
 
31
31
  //create methods app.invite, app.register, etc..
32
32
  methods.forEach((method) => {
33
- app[method.toLowerCase()] = app.use.bind(app, method.toLowerCase()) ;
34
- }) ;
33
+ app[method.toLowerCase()] = app.use.bind(app, method.toLowerCase());
34
+ });
35
35
 
36
36
  //special handling for cdr events
37
37
  app.on = function(event, listener) {
38
38
  if (0 === event.indexOf('cdr:')) {
39
39
  if (app.client) {
40
40
  app.client.on(event, function() {
41
- var args = Array.prototype.slice.call(arguments) ;
42
- EventEmitter.prototype.emit.apply(app, [event].concat(args)) ;
43
- }) ;
41
+ var args = Array.prototype.slice.call(arguments);
42
+ EventEmitter.prototype.emit.apply(app, [event].concat(args));
43
+ });
44
44
  }
45
45
  else {
46
- this._cachedEvents.push(event) ;
46
+ this._cachedEvents.push(event);
47
47
  }
48
48
  }
49
49
  //delegate all others to standard EventEmitter prototype
50
- return EventEmitter.prototype.addListener.call(app, event, listener) ;
51
- } ;
50
+ return EventEmitter.prototype.addListener.call(app, event, listener);
51
+ };
52
52
 
53
53
  return app;
54
54
  }
55
55
 
56
56
  createServer.Agent = require('./drachtio-agent');
57
- createServer.Request = require('./request') ;
58
- createServer.Response = require('./response') ;
59
- createServer.onSend = require('./on-send') ;
57
+ createServer.Request = require('./request');
58
+ createServer.Response = require('./response');
59
+ createServer.onSend = require('./on-send');