Skip to content

Commit 200b150

Browse files
stun.request now supports promise interface
1 parent a76b02d commit 200b150

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"is-stun": "^2.0.0",
4444
"meow": "^5.0.0",
4545
"parse-url": "^5.0.1",
46-
"turbo-crc32": "^1.0.0"
46+
"turbo-crc32": "^1.0.0",
47+
"universalify": "^0.1.2"
4748
},
4849
"engines": {
4950
"node": ">=8.3"

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ stun.request('stun.l.google.com:19302', (err, res) => {
3333
console.log('your ip', address);
3434
}
3535
});
36+
37+
// or with promise
38+
39+
const res = await stun.request('stun.l.google.com:19302');
40+
console.log('your ip', res.getXorAddress().address);
3641
```
3742

3843
## CLI
@@ -170,6 +175,7 @@ stunServer.on('bindingResponse', (msg) => {
170175
<a name="request" />
171176

172177
#### `request(url: string, [options: RequestOptions], callback: function): void`
178+
#### `request(url: string, [options: RequestOptions]): Promise`
173179

174180
Create a request `STUN_BINDING_REQUEST` to stun server, follow [RFC5389](https://tools.ietf.org/html/rfc5389). The first argument may be a host (`stun.example.com`), host with port (`stun.example.com:1234`) or host with port and protocol (`stun://stun.example.com:1234`). By default, port is 3478.
175181

src/node_modules/net/request.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/net/request.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ test('should work', done => {
1818
});
1919
});
2020

21+
test('should work as promise', async () => {
22+
const res = await request('stun://stun.l.google.com:19302');
23+
expect(res).toBeInstanceOf(StunResponse);
24+
});
25+
2126
test('url normalization should work', done => {
2227
expect.assertions(2);
2328

0 commit comments

Comments
 (0)