@9c5s/node-tcnet 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.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2021 Christopher Dziomba
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.MD ADDED
@@ -0,0 +1,76 @@
1
+ # node-tcnet
2
+
3
+ > フォーク元: <https://github.com/chdxD1/node-tcnet>
4
+
5
+ TCNetプロトコルのNode.js実装。Pioneer DJ / ShowKontrol / Event Imagineering GroupのTCNet仕様に準拠。
6
+
7
+ ## インストール
8
+
9
+ ```bash
10
+ npm install @9c5s/node-tcnet
11
+ ```
12
+
13
+ ## 使い方
14
+
15
+ ```typescript
16
+ import { TCNetClient, TCNetConfiguration, TCNetDataPacketType, TCNetDataPacketMetadata } from "@9c5s/node-tcnet";
17
+
18
+ async function main() {
19
+ const config = new TCNetConfiguration();
20
+ config.broadcastInterface = "10GbE"; // ネットワークインターフェース名
21
+
22
+ const client = new TCNetClient(config);
23
+
24
+ client.on("broadcast", (packet) => console.log(packet));
25
+ client.on("data", (packet) => console.log(packet));
26
+
27
+ await client.connect();
28
+
29
+ // メタデータ取得 (layer: 0-based)
30
+ const meta = await client.requestData(TCNetDataPacketType.MetaData, 0);
31
+ if (meta instanceof TCNetDataPacketMetadata && meta.info) {
32
+ console.log(meta.info.trackArtist, meta.info.trackTitle);
33
+ }
34
+
35
+ await client.disconnect();
36
+ }
37
+
38
+ main().catch(console.error);
39
+ ```
40
+
41
+ ## 前提条件
42
+
43
+ 以下のいずれかが必要:
44
+
45
+ - [PRO DJ LINK Bridge](https://www.pioneerdj.com/en/product/software/pro-dj-link-bridge/software/) (Windows / Mac)
46
+ - [ShowKontrol / Beatkontrol](https://www.tc-supply.com/home) (Mac)
47
+
48
+ ## 機能
49
+
50
+ - [x] TCNetネットワーク接続
51
+ - [x] ステータスイベント受信
52
+ - [x] メタデータリクエスト (アーティスト名、曲名)
53
+ - [x] メトリクスリクエスト
54
+ - [x] タイムスタンプ受信
55
+ - [ ] Time Sync (NTP/PTP相当)
56
+ - [ ] Beat Grid / Wave Formリクエスト
57
+ - [ ] Control機能 (レイヤー制御)
58
+
59
+ ## ドキュメント
60
+
61
+ 詳細は[Wiki](https://github.com/9c5s/node-tcnet/wiki)を参照:
62
+
63
+ - [Getting Started](https://github.com/9c5s/node-tcnet/wiki/Getting-Started) -- 導入ガイド
64
+ - [API Reference](https://github.com/9c5s/node-tcnet/wiki/API-Reference) -- APIリファレンス
65
+ - [PRO DJ LINK Bridge](https://github.com/9c5s/node-tcnet/wiki/PRO-DJ-LINK-Bridge) -- Bridge固有の制限
66
+ - [TCNet Protocol](https://github.com/9c5s/node-tcnet/wiki/TCNet-Protocol) -- プロトコル仕様
67
+ - [Contributing](https://github.com/9c5s/node-tcnet/wiki/Contributing) -- 開発への参加
68
+
69
+ ## 関連プロジェクト
70
+
71
+ - [prolink-connect](https://github.com/EvanPurkhiser/prolink-connect) (JS) -- Pro DJ Linkプロトコル直接実装
72
+ - [dysentery](https://github.com/Deep-Symmetry/dysentery) (Java) -- 同上
73
+
74
+ ## 免責事項
75
+
76
+ Pioneer DJおよびEvent Imagineering Groupの支援・承認を受けていない。製品名・企業名は各所有者の商標または登録商標。
@@ -0,0 +1,325 @@
1
+ import EventEmitter from 'events';
2
+
3
+ declare enum TCNetMessageType {
4
+ OptIn = 2,
5
+ OptOut = 3,
6
+ Status = 5,
7
+ TimeSync = 10,
8
+ Error = 13,
9
+ Request = 20,
10
+ ApplicationData = 30,
11
+ Control = 101,
12
+ Text = 128,
13
+ Keyboard = 132,
14
+ Data = 200,
15
+ File = 204,
16
+ Time = 254
17
+ }
18
+ declare enum TCNetDataPacketType {
19
+ MetricsData = 2,
20
+ MetaData = 4,
21
+ BeatGridData = 8,
22
+ CUEData = 12,
23
+ SmallWaveFormData = 16,
24
+ BigWaveFormData = 32,
25
+ MixerData = 150
26
+ }
27
+ declare enum NodeType {
28
+ Auto = 1,
29
+ Master = 2,
30
+ Slave = 4,
31
+ Repeater = 8
32
+ }
33
+ interface TCNetReaderWriter {
34
+ read(): void;
35
+ write(): void;
36
+ }
37
+ declare abstract class TCNetPacket implements TCNetReaderWriter {
38
+ buffer: Buffer;
39
+ header: TCNetManagementHeader;
40
+ abstract read(): void;
41
+ abstract write(): void;
42
+ abstract length(): number;
43
+ abstract type(): number;
44
+ }
45
+ declare class TCNetManagementHeader implements TCNetReaderWriter {
46
+ static MAJOR_VERSION: number;
47
+ static MAGIC_HEADER: string;
48
+ buffer: Buffer;
49
+ nodeId: number;
50
+ minorVersion: number;
51
+ messageType: TCNetMessageType;
52
+ nodeName: string;
53
+ seq: number;
54
+ nodeType: number;
55
+ nodeOptions: number;
56
+ timestamp: number;
57
+ constructor(buffer: Buffer);
58
+ read(): void;
59
+ write(): void;
60
+ }
61
+ declare class TCNetOptInPacket extends TCNetPacket {
62
+ nodeCount: number;
63
+ nodeListenerPort: number;
64
+ uptime: number;
65
+ vendorName: string;
66
+ appName: string;
67
+ majorVersion: number;
68
+ minorVersion: number;
69
+ bugVersion: number;
70
+ read(): void;
71
+ write(): void;
72
+ length(): number;
73
+ type(): number;
74
+ }
75
+ declare class TCNetOptOutPacket extends TCNetPacket {
76
+ nodeCount: number;
77
+ nodeListenerPort: number;
78
+ read(): void;
79
+ write(): void;
80
+ length(): number;
81
+ type(): number;
82
+ }
83
+ declare enum TCNetLayerStatus {
84
+ IDLE = 0,
85
+ PLAYING = 3,
86
+ LOOPING = 4,
87
+ PAUSED = 5,
88
+ STOPPED = 6,
89
+ CUEDOWN = 7,
90
+ PLATTERDOWN = 8,
91
+ FFWD = 9,
92
+ FFRV = 10,
93
+ HOLD = 11
94
+ }
95
+ declare class TCNetStatusPacket extends TCNetPacket {
96
+ data: null | {
97
+ nodeCount: number;
98
+ nodeListenerPort: number;
99
+ smpteMode: number;
100
+ autoMasterMode: number;
101
+ };
102
+ layers: Array<{
103
+ source: number;
104
+ status: TCNetLayerStatus;
105
+ trackID: number;
106
+ name: string;
107
+ }>;
108
+ read(): void;
109
+ write(): void;
110
+ length(): number;
111
+ type(): number;
112
+ }
113
+ declare class TCNetRequestPacket extends TCNetPacket {
114
+ dataType: number;
115
+ layer: number;
116
+ read(): void;
117
+ write(): void;
118
+ length(): number;
119
+ type(): number;
120
+ }
121
+ declare enum TCNetTimecodeState {
122
+ Stopped = 0,
123
+ Running = 1,
124
+ ForceReSync = 2
125
+ }
126
+ declare class TCNetTimecode {
127
+ mode: number;
128
+ state: TCNetTimecodeState;
129
+ hours: number;
130
+ minutes: number;
131
+ seconds: number;
132
+ frames: number;
133
+ read(buffer: Buffer, offset: number): void;
134
+ }
135
+ type TCNetTimePacketLayer = {
136
+ currentTimeMillis: number;
137
+ totalTimeMillis: number;
138
+ beatMarker: number;
139
+ state: TCNetLayerStatus;
140
+ onAir: number;
141
+ };
142
+ declare class TCNetTimePacket extends TCNetPacket {
143
+ private _layers;
144
+ private _generalSMPTEMode;
145
+ read(): void;
146
+ write(): void;
147
+ length(): number;
148
+ type(): number;
149
+ get layers(): TCNetTimePacketLayer[];
150
+ get generalSMPTEMode(): number;
151
+ }
152
+ declare class TCNetDataPacket extends TCNetPacket {
153
+ dataType: TCNetDataPacketType;
154
+ /**
155
+ * 0-indexed layer ID (0-7)
156
+ */
157
+ layer: number;
158
+ read(): void;
159
+ write(): void;
160
+ length(): number;
161
+ type(): number;
162
+ }
163
+ declare enum TCNetLayerSyncMaster {
164
+ Slave = 0,
165
+ Master = 1
166
+ }
167
+ declare class TCNetDataPacketMetrics extends TCNetDataPacket {
168
+ data: {
169
+ state: TCNetLayerStatus;
170
+ syncMaster: TCNetLayerSyncMaster;
171
+ beatMarker: number;
172
+ trackLength: number;
173
+ currentPosition: number;
174
+ speed: number;
175
+ beatNumber: number;
176
+ bpm: number;
177
+ pitchBend: number;
178
+ trackID: number;
179
+ } | null;
180
+ read(): void;
181
+ write(): void;
182
+ length(): number;
183
+ }
184
+ declare class TCNetDataPacketMetadata extends TCNetDataPacket {
185
+ info: {
186
+ trackArtist: string;
187
+ trackTitle: string;
188
+ trackKey: number;
189
+ trackID: number;
190
+ } | null;
191
+ read(): void;
192
+ write(): void;
193
+ length(): number;
194
+ }
195
+ interface Constructable<T> {
196
+ new (...args: unknown[]): T;
197
+ }
198
+ declare const TCNetPackets: Record<TCNetMessageType, Constructable<TCNetPacket> | null>;
199
+ declare const TCNetDataPackets: Record<TCNetDataPacketType, typeof TCNetDataPacket | null>;
200
+
201
+ type TCNetLogger = {
202
+ error: (error: Error) => void;
203
+ debug: (message: string) => void;
204
+ };
205
+ declare class TCNetConfiguration {
206
+ logger: TCNetLogger | null;
207
+ unicastPort: number;
208
+ applicationCode: number;
209
+ nodeId: number;
210
+ nodeName: string;
211
+ vendorName: string;
212
+ appName: string;
213
+ broadcastInterface: string | null;
214
+ broadcastAddress: string;
215
+ broadcastListeningAddress: string;
216
+ requestTimeout: number;
217
+ }
218
+ /**
219
+ * Low level implementation of the TCNet protocol
220
+ */
221
+ declare class TCNetClient extends EventEmitter {
222
+ private config;
223
+ private broadcastSocket;
224
+ private unicastSocket;
225
+ private timestampSocket;
226
+ private server;
227
+ private seq;
228
+ private uptime;
229
+ private connected;
230
+ private connectedHandler;
231
+ private requests;
232
+ private announcementInterval;
233
+ /**
234
+ *
235
+ * @param config configuration for TCNet access
236
+ */
237
+ constructor(config?: TCNetConfiguration);
238
+ get log(): TCNetLogger | null;
239
+ /**
240
+ * Wrapper method to bind a socket with a Promise
241
+ * @param socket socket to bind
242
+ * @param port port to bind to
243
+ * @param address address to bind to
244
+ * @returns Promise which always resolves (no errors in callback)
245
+ */
246
+ private bindSocket;
247
+ /**
248
+ * Connect to the TCNet networks
249
+ */
250
+ connect(): Promise<void>;
251
+ /**
252
+ * Disconnects from TCNet network
253
+ */
254
+ disconnect(): Promise<void>;
255
+ /**
256
+ * Waiting for unicast from a master
257
+ */
258
+ private waitConnected;
259
+ /**
260
+ * Parse a packet from a ManagementHeader
261
+ * @param header the received management header
262
+ * @returns the parsed packet
263
+ */
264
+ private parsePacket;
265
+ /**
266
+ * Callback method to receive datagrams on the broadcast socket
267
+ *
268
+ * @param msg datagram buffer
269
+ * @param rinfo remoteinfo
270
+ */
271
+ private receiveBroadcast;
272
+ /**
273
+ * Callback method to receive datagrams on the unicast socket
274
+ *
275
+ * @param msg datagram buffer
276
+ * @param rinfo remoteinfo
277
+ */
278
+ private receiveUnicast;
279
+ /**
280
+ * Callback method to receive datagrams on the timestamp socket
281
+ * @param msg datagram buffer
282
+ * @param rinfo remoteinfo
283
+ */
284
+ private receiveTimestamp;
285
+ /**
286
+ * Fill headers of a packet
287
+ *
288
+ * @param packet Packet that needs header information
289
+ */
290
+ private fillHeader;
291
+ /**
292
+ * Generalized method to send packets to a given destination on a given socket
293
+ *
294
+ * @param packet Packet to send
295
+ * @param socket Socket to send on
296
+ * @param port Destination Port
297
+ * @param address Destination Address
298
+ */
299
+ private sendPacket;
300
+ /**
301
+ * Sends a packet to the discovered server
302
+ * @param packet Packet to send
303
+ */
304
+ sendServer(packet: TCNetPacket): Promise<void>;
305
+ /**
306
+ * Called every second to announce our app on the network
307
+ */
308
+ private announceApp;
309
+ /**
310
+ * Broadcasts a packet to the network
311
+ *
312
+ * @param packet packet to broadcast
313
+ */
314
+ broadcastPacket(packet: TCNetPacket): Promise<void>;
315
+ /**
316
+ * Sends a request packet to the discovered server
317
+ *
318
+ * @param dataType requested data type
319
+ * @param layer requested layer
320
+ * @returns Promise to wait for answer on request
321
+ */
322
+ requestData(dataType: number, layer: number): Promise<TCNetDataPacket>;
323
+ }
324
+
325
+ export { type Constructable, NodeType, TCNetClient, TCNetConfiguration, TCNetDataPacket, TCNetDataPacketMetadata, TCNetDataPacketMetrics, TCNetDataPacketType, TCNetDataPackets, TCNetLayerStatus, TCNetLayerSyncMaster, TCNetManagementHeader, TCNetMessageType, TCNetOptInPacket, TCNetOptOutPacket, TCNetPacket, TCNetPackets, TCNetRequestPacket, TCNetStatusPacket, TCNetTimePacket, type TCNetTimePacketLayer, TCNetTimecode, TCNetTimecodeState };