tturn 0.1.1 → 0.1.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
@@ -29,11 +29,11 @@ import { Tturn } from "tturn";
29
29
 
30
30
  const turn = new Tturn({
31
31
  realm: "turn.example.com",
32
- authSecret: "replace-with-your-secret",
32
+ password: "replace-with-your-password",
33
33
  publicIp: "1.2.3.4",
34
34
  listenPort: 3478,
35
35
  username: "user-1001",
36
- ttlSec: 600
36
+ disableCredentialExpiry: true
37
37
  });
38
38
 
39
39
  const ice = await turn.start();
@@ -44,6 +44,13 @@ await turn.stop();
44
44
 
45
45
  `start()` now returns one ICE payload directly, so bootstrap can be only `new Tturn(...)` + `start()`.
46
46
 
47
+ For long-running sessions, set `disableCredentialExpiry: true` to issue non-expiring credentials.
48
+
49
+ With static password mode (`password` + `username`), what you set is what clients use:
50
+
51
+ - output `username` is exactly your configured username
52
+ - output `credential` is exactly your configured password
53
+
47
54
  ## Credential options
48
55
 
49
56
  `issueCredential(options)` supports:
@@ -69,31 +76,55 @@ TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret tturn credentia
69
76
 
70
77
  # Optional: provide custom username
71
78
  TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret TTURN_USERNAME=alice tturn credential
79
+
80
+ # Optional: disable credential expiry (long-lived credentials)
81
+ TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret TTURN_USERNAME=alice TTURN_DISABLE_CREDENTIAL_EXPIRY=1 tturn credential
82
+
83
+ # Static account/password (exact value, no rewrite)
84
+ TURN_REALM=turn.example.com TURN_USERNAME=alice TURN_PASSWORD=alice-pass TTURN_DISABLE_CREDENTIAL_EXPIRY=1 tturn start
72
85
  ```
73
86
 
74
87
  Required env:
75
88
 
76
89
  - `TURN_REALM`
77
- - `TURN_SECRET`
90
+ - `TURN_SECRET` or `TURN_PASSWORD`
78
91
 
79
92
  Optional env:
80
93
 
81
94
  - `TURN_PUBLIC_IP`
82
95
  - `TURN_PORT`
96
+ - `TURN_MIN_PORT`
97
+ - `TURN_MAX_PORT`
83
98
  - `TTURN_TTL_SEC`
84
99
  - `TTURN_USER_ID`
85
- - `TTURN_USERNAME`
100
+ - `TTURN_USERNAME` (or `TURN_USERNAME`)
101
+ - `TTURN_DISABLE_CREDENTIAL_EXPIRY` (`1` or `true`)
86
102
 
87
103
  ## API options
88
104
 
89
105
  - `realm` (required): TURN realm/domain.
90
- - `authSecret` (required): shared secret for dynamic credentials.
106
+ - `authSecret` (optional): shared secret for dynamic credentials.
107
+ - `password` (optional): static TURN password (when set, returned credential stays fixed).
91
108
  - `listenPort` (default `3478`): TURN listening port.
92
109
  - `publicIp` (optional, recommended): public relay IP exposed to clients.
93
110
  - `listeningIp` (default `0.0.0.0`): bind address.
94
111
  - `username` / `userId` (optional): default credential username seed. `username` has higher priority.
95
112
  - `ttlSec` (optional): default credential TTL used by `start()` and `issueCredential()`.
96
- - `minPort` / `maxPort`: reserved for relay port range control in next iterations.
113
+ - `disableCredentialExpiry` (optional): disable timestamp expiry check and issue non-expiring credentials.
114
+ - `minPort` / `maxPort`: relay allocation port range (effective in native TURN allocator).
115
+
116
+ At least one of `authSecret` or `password` must be provided.
117
+
118
+ ## Quick verify
119
+
120
+ ```bash
121
+ npm install
122
+ npm run build
123
+
124
+ TURN_REALM=turn.example.com TURN_PUBLIC_IP=1.2.3.4 TURN_USERNAME=alice TURN_PASSWORD=alice-pass TTURN_DISABLE_CREDENTIAL_EXPIRY=1 node dist/cli.js credential
125
+ ```
126
+
127
+ The returned JSON should keep `username = "alice"` and `credential = "alice-pass"`.
97
128
 
98
129
  ## Build from source
99
130
 
package/README.zh-CN.md CHANGED
@@ -32,11 +32,11 @@ import { Tturn } from "tturn";
32
32
 
33
33
  const turn = new Tturn({
34
34
  realm: "turn.example.com",
35
- authSecret: "replace-with-your-secret",
35
+ password: "replace-with-your-password",
36
36
  publicIp: "1.2.3.4",
37
37
  listenPort: 3478,
38
38
  username: "user-1001",
39
- ttlSec: 600
39
+ disableCredentialExpiry: true
40
40
  });
41
41
 
42
42
  const ice = await turn.start();
@@ -46,6 +46,13 @@ await turn.stop();
46
46
  ```
47
47
 
48
48
  `start()` 会直接返回一组 ICE,因此最简流程只需要 `new Tturn(...)` 和 `start()`。
49
+
50
+ 如果你需要长时间持续连接,可设置 `disableCredentialExpiry: true`,生成不过期凭证。
51
+
52
+ 在静态账号密码模式(`password` + `username`)下:
53
+
54
+ - 输出的 `username` 就是你配置的账号
55
+ - 输出的 `credential` 就是你配置的密码
49
56
 
50
57
  ## 5)CLI 用法
51
58
 
@@ -58,6 +65,12 @@ TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret tturn credentia
58
65
 
59
66
  # 可选:传入自定义 username
60
67
  TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret TTURN_USERNAME=alice tturn credential
68
+
69
+ # 可选:禁用凭证过期(长期凭证)
70
+ TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret TTURN_USERNAME=alice TTURN_DISABLE_CREDENTIAL_EXPIRY=1 tturn credential
71
+
72
+ # 静态账号密码(原样输出,不改写)
73
+ TURN_REALM=turn.example.com TURN_USERNAME=alice TURN_PASSWORD=alice-pass TTURN_DISABLE_CREDENTIAL_EXPIRY=1 tturn start
61
74
  ```
62
75
 
63
76
  ## 5.1)凭证参数补充(username)
@@ -70,14 +83,29 @@ TURN_REALM=turn.example.com TURN_SECRET=replace-with-your-secret TTURN_USERNAME=
70
83
 
71
84
  ## 6)配置参数说明
72
85
 
73
- - `realm`(必填):TURN realm / 域名。
74
- - `authSecret`(必填):动态凭证签名密钥。
86
+ - `realm`(必填):TURN realm / 域名。
87
+ - `authSecret`(可选):动态凭证签名密钥。
88
+ - `password`(可选):静态 TURN 密码(设置后返回值保持固定)。
75
89
  - `listenPort`(默认 `3478`):TURN 监听端口。
76
90
  - `publicIp`(建议配置):客户端访问的公网 IP。
77
91
  - `listeningIp`(默认 `0.0.0.0`):本地绑定地址。
78
92
  - `username` / `userId`(可选):默认凭证用户名种子,`username` 优先级更高。
79
93
  - `ttlSec`(可选):`start()` 与 `issueCredential()` 的默认凭证时效。
80
- - `minPort` / `maxPort`:预留给后续中继端口范围控制。
94
+ - `disableCredentialExpiry`(可选):禁用时间戳过期校验,生成不过期凭证。
95
+ - `minPort` / `maxPort`:中继分配端口范围(已在 native TURN 分配器中生效)。
96
+
97
+ `authSecret` 和 `password` 至少需要提供一个。
98
+
99
+ ## 6.1)快速验证
100
+
101
+ ```bash
102
+ npm install
103
+ npm run build
104
+
105
+ TURN_REALM=turn.example.com TURN_PUBLIC_IP=1.2.3.4 TURN_USERNAME=alice TURN_PASSWORD=alice-pass TTURN_DISABLE_CREDENTIAL_EXPIRY=1 node dist/cli.js credential
106
+ ```
107
+
108
+ 返回 JSON 中应保持 `username = "alice"`、`credential = "alice-pass"`。
81
109
 
82
110
  ## 7)源码构建
83
111
 
package/dist/app.js CHANGED
@@ -3,20 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_1 = require("./index");
4
4
  const APP_CONFIG = {
5
5
  realm: "turn.example.com",
6
- authSecret: "replace-with-your-secret",
6
+ authSecret: "",
7
+ password: "replace-with-your-password",
7
8
  publicIp: "1.2.3.4",
8
9
  listenPort: 3478,
9
10
  username: "google-test",
10
- ttlSec: 600
11
+ ttlSec: 600,
12
+ disableCredentialExpiry: true
11
13
  };
12
14
  async function main() {
13
15
  const service = new index_1.Tturn({
14
16
  realm: APP_CONFIG.realm,
15
17
  authSecret: APP_CONFIG.authSecret,
18
+ password: APP_CONFIG.password,
16
19
  publicIp: APP_CONFIG.publicIp,
17
20
  listenPort: APP_CONFIG.listenPort,
18
21
  username: APP_CONFIG.username,
19
- ttlSec: APP_CONFIG.ttlSec
22
+ ttlSec: APP_CONFIG.ttlSec,
23
+ disableCredentialExpiry: APP_CONFIG.disableCredentialExpiry
20
24
  });
21
25
  const ice = await service.start();
22
26
  console.log("[tturn] started.");
package/dist/cli.js CHANGED
@@ -5,28 +5,41 @@ const index_1 = require("./index");
5
5
  async function run() {
6
6
  const command = process.argv[2];
7
7
  if (command === "credential") {
8
- const secret = mustGetEnv("TURN_SECRET");
9
8
  const realm = mustGetEnv("TURN_REALM");
10
- const service = (0, index_1.createTurnService)({ realm, authSecret: secret, publicIp: process.env.TURN_PUBLIC_IP });
9
+ const authOptions = resolveAuthOptions();
10
+ const service = (0, index_1.createTurnService)({
11
+ realm,
12
+ authSecret: authOptions.authSecret,
13
+ password: authOptions.password,
14
+ publicIp: process.env.TURN_PUBLIC_IP,
15
+ listenPort: process.env.TURN_PORT ? Number(process.env.TURN_PORT) : 3478,
16
+ minPort: process.env.TURN_MIN_PORT ? Number(process.env.TURN_MIN_PORT) : undefined,
17
+ maxPort: process.env.TURN_MAX_PORT ? Number(process.env.TURN_MAX_PORT) : undefined,
18
+ disableCredentialExpiry: readBoolEnv("TTURN_DISABLE_CREDENTIAL_EXPIRY") ?? Boolean(authOptions.password)
19
+ });
11
20
  const ice = service.issueCredential({
12
21
  ttlSec: process.env.TTURN_TTL_SEC ? Number(process.env.TTURN_TTL_SEC) : 3600,
13
22
  userId: process.env.TTURN_USER_ID,
14
- username: process.env.TTURN_USERNAME
23
+ username: readUsernameEnv()
15
24
  });
16
25
  process.stdout.write(`${JSON.stringify(ice, null, 2)}\n`);
17
26
  return;
18
27
  }
19
28
  if (command === "start") {
20
- const secret = mustGetEnv("TURN_SECRET");
21
29
  const realm = mustGetEnv("TURN_REALM");
30
+ const authOptions = resolveAuthOptions();
22
31
  const service = (0, index_1.createTurnService)({
23
32
  realm,
24
- authSecret: secret,
33
+ authSecret: authOptions.authSecret,
34
+ password: authOptions.password,
25
35
  publicIp: process.env.TURN_PUBLIC_IP,
26
36
  listenPort: process.env.TURN_PORT ? Number(process.env.TURN_PORT) : 3478,
37
+ minPort: process.env.TURN_MIN_PORT ? Number(process.env.TURN_MIN_PORT) : undefined,
38
+ maxPort: process.env.TURN_MAX_PORT ? Number(process.env.TURN_MAX_PORT) : undefined,
27
39
  ttlSec: process.env.TTURN_TTL_SEC ? Number(process.env.TTURN_TTL_SEC) : 3600,
28
- username: process.env.TTURN_USERNAME,
29
- userId: process.env.TTURN_USER_ID
40
+ username: readUsernameEnv(),
41
+ userId: process.env.TTURN_USER_ID,
42
+ disableCredentialExpiry: readBoolEnv("TTURN_DISABLE_CREDENTIAL_EXPIRY") ?? Boolean(authOptions.password)
30
43
  });
31
44
  const ice = await service.start();
32
45
  process.stdout.write("tturn started\n");
@@ -53,11 +66,33 @@ function printUsage() {
53
66
  " tturn credential # prints one ICE server credential JSON",
54
67
  "",
55
68
  "required env:",
56
- " TURN_REALM, TURN_SECRET",
69
+ " TURN_REALM",
70
+ " TURN_SECRET or TURN_PASSWORD",
57
71
  "optional env:",
58
- " TURN_PUBLIC_IP, TURN_PORT, TTURN_TTL_SEC, TTURN_USER_ID, TTURN_USERNAME"
72
+ " TURN_PUBLIC_IP, TURN_PORT, TURN_MIN_PORT, TURN_MAX_PORT, TTURN_TTL_SEC, TTURN_USER_ID, TTURN_USERNAME (or TURN_USERNAME), TTURN_DISABLE_CREDENTIAL_EXPIRY"
59
73
  ].join("\n") + "\n");
60
74
  }
75
+ function readUsernameEnv() {
76
+ return process.env.TTURN_USERNAME ?? process.env.TURN_USERNAME;
77
+ }
78
+ function resolveAuthOptions() {
79
+ const authSecret = process.env.TURN_SECRET;
80
+ const password = process.env.TURN_PASSWORD;
81
+ if (!authSecret && !password) {
82
+ throw new Error("Missing required env: TURN_SECRET or TURN_PASSWORD");
83
+ }
84
+ return {
85
+ authSecret: authSecret ?? "",
86
+ password
87
+ };
88
+ }
89
+ function readBoolEnv(name) {
90
+ const value = process.env[name];
91
+ if (!value) {
92
+ return undefined;
93
+ }
94
+ return value === "1" || value.toLowerCase() === "true";
95
+ }
61
96
  function waitForSignal() {
62
97
  return new Promise((resolve) => {
63
98
  const keepAlive = setInterval(() => {
@@ -6,9 +6,9 @@ const node_path_1 = require("node:path");
6
6
  function loadNativeBinding() {
7
7
  const root = (0, node_path_1.join)(__dirname, "..");
8
8
  const candidates = [
9
+ (0, node_path_1.join)(root, binaryName()),
9
10
  (0, node_path_1.join)(root, "index.node"),
10
- (0, node_path_1.join)(root, "native", "index.node"),
11
- (0, node_path_1.join)(root, binaryName())
11
+ (0, node_path_1.join)(root, "native", "index.node")
12
12
  ];
13
13
  for (const filePath of candidates) {
14
14
  if (!(0, node_fs_1.existsSync)(filePath)) {
package/dist/service.js CHANGED
@@ -4,14 +4,19 @@ exports.TurnService = void 0;
4
4
  const native_binding_1 = require("./native-binding");
5
5
  class TurnService {
6
6
  constructor(options) {
7
- const { username, userId, ttlSec, ...nativeOptions } = options;
7
+ const { username, password, userId, ttlSec, ...nativeOptions } = options;
8
+ const disableCredentialExpiry = options.disableCredentialExpiry ?? Boolean(password);
8
9
  this.native = new native_binding_1.binding.NativeTurnService({
9
10
  ...nativeOptions,
11
+ authSecret: nativeOptions.authSecret ?? "",
10
12
  listenPort: nativeOptions.listenPort ?? 3478,
11
13
  minPort: nativeOptions.minPort ?? 49152,
12
14
  maxPort: nativeOptions.maxPort ?? 65535,
13
15
  publicIp: nativeOptions.publicIp ?? nativeOptions.realm,
14
- listeningIp: nativeOptions.listeningIp ?? "0.0.0.0"
16
+ listeningIp: nativeOptions.listeningIp ?? "0.0.0.0",
17
+ username,
18
+ password,
19
+ disableCredentialExpiry
15
20
  });
16
21
  this.defaultIssueOptions = {
17
22
  ttlSec,
package/dist/types.d.ts CHANGED
@@ -16,15 +16,17 @@ export interface IssueCredentialOptions {
16
16
  }
17
17
  export interface TurnServiceOptions {
18
18
  realm: string;
19
- authSecret: string;
19
+ authSecret?: string;
20
20
  listenPort?: number;
21
21
  minPort?: number;
22
22
  maxPort?: number;
23
23
  publicIp?: string;
24
24
  listeningIp?: string;
25
25
  username?: string;
26
+ password?: string;
26
27
  userId?: string;
27
28
  ttlSec?: number;
29
+ disableCredentialExpiry?: boolean;
28
30
  }
29
31
  export interface StartOptions {
30
32
  detached?: boolean;
package/index.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tturn",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "High-performance TURN server for Node.js with embedded native core",
5
5
  "keywords": [
6
6
  "turn",
Binary file