dolphin-server-modules 1.5.6 → 1.5.7

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.
@@ -1,7 +1,20 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { RealtimePlugin } from './plugins';
3
3
  /**
4
- * RealtimeCore - High performance unified pub/sub bus for Dolphin.
4
+ * File Metadata Interface
5
+ */
6
+ interface FileMetadata {
7
+ path: string;
8
+ size: number;
9
+ chunkSize: number;
10
+ totalChunks: number;
11
+ name: string;
12
+ hash?: string;
13
+ createdAt: number;
14
+ }
15
+ /**
16
+ * RealtimeCore v2.0 - High performance unified pub/sub bus for Dolphin
17
+ * Added Features: pubPush, subPull, pubFile, subFile, Resume, P2P Stream
5
18
  */
6
19
  export declare class RealtimeCore extends EventEmitter {
7
20
  private config;
@@ -11,6 +24,12 @@ export declare class RealtimeCore extends EventEmitter {
11
24
  private plugins;
12
25
  private pending;
13
26
  private msgId;
27
+ private highFreqBuffers;
28
+ private readonly MAX_BUFFER_SIZE;
29
+ private fileRegistry;
30
+ private fileProgress;
31
+ private readonly DEFAULT_CHUNK_SIZE;
32
+ private peerRegistry;
14
33
  private jsonCache;
15
34
  private readonly CACHE_TTL;
16
35
  private readonly MAX_CACHE_SIZE;
@@ -18,6 +37,7 @@ export declare class RealtimeCore extends EventEmitter {
18
37
  private redisSub?;
19
38
  private cleanupInterval?;
20
39
  private cacheCleanupInterval?;
40
+ private bufferCleanupInterval?;
21
41
  constructor(config?: {
22
42
  maxMessageSize?: number;
23
43
  redisUrl?: string;
@@ -28,12 +48,16 @@ export declare class RealtimeCore extends EventEmitter {
28
48
  enableJSONCache?: boolean;
29
49
  useBinaryProtocol?: boolean;
30
50
  debug?: boolean;
51
+ maxBufferPerTopic?: number;
52
+ defaultChunkSize?: number;
53
+ enableP2P?: boolean;
31
54
  });
32
55
  private log;
33
56
  private toJSON;
34
57
  private getCacheKey;
35
58
  private setCache;
36
59
  private cleanJSONCache;
60
+ private cleanupBuffers;
37
61
  private initRedis;
38
62
  subscribe(topic: string, fn: (data: any) => void, deviceId?: string): void;
39
63
  publish(topic: string, payload: any, opts?: {
@@ -42,8 +66,116 @@ export declare class RealtimeCore extends EventEmitter {
42
66
  }, deviceId?: string): void;
43
67
  private publishInternal;
44
68
  /**
45
- * Handle raw data from a socket with DJSON integration
69
+ * pubPush: अति उच्च गतिको डाटाको लागि (IoT Sensors, Live Graphs)
70
+ * - No JSON.stringify, No Redis, No ACL चेक
71
+ * - सिधै Trie मा भएका Subscribers लाई पठाउने
72
+ * - Memory-efficient: सीमित मात्र बफर राख्छ
73
+ */
74
+ pubPush(topic: string, payload: Buffer | Uint8Array | any): void;
75
+ /**
76
+ * subPull: क्लाइन्टले मागेपछि मात्र डाटा दिने (Data Saving)
77
+ * @param deviceId - कसलाई पठाउने
78
+ * @param topic - कुन टपिकको डाटा चाहियो
79
+ * @param count - कति वटा पछिल्ला डाटा चाहियो (default: 10)
80
+ */
81
+ subPull(deviceId: string, topic: string, count?: number): void;
82
+ /**
83
+ * pubFile: ठूलो फाइललाई टुक्रा-टुक्रा (Chunks) मा पठाउन तयार गर्ने
84
+ * - फाइललाई पूरै मेमोरीमा नराखी 'Stream' तयार पार्ने
85
+ * - हरेक टुक्रा 64KB (हल्का)
86
+ */
87
+ pubFile(fileId: string, filePath: string, chunkSize?: number): FileMetadata | null;
88
+ /**
89
+ * subFile: फाइलको निश्चित टुक्रा (Chunk) तान्ने - Resume Support सहित
90
+ * @param deviceId - कसलाई पठाउने
91
+ * @param fileId - कुन फाइल
92
+ * @param startChunk - कुन Chunk बाट सुरु गर्ने (Resume को लागि)
93
+ */
94
+ subFile(deviceId: string, fileId: string, startChunk?: number): Promise<boolean>;
95
+ /**
96
+ * resumeFile: पहिले रोकिएको ठाउँबाट फाइल फेरि सुरु गर्ने
97
+ */
98
+ resumeFile(deviceId: string, fileId: string): Promise<boolean>;
99
+ /**
100
+ * saveFileProgress: डाउनलोड प्रगति सेभ गर्ने
101
+ */
102
+ private saveFileProgress;
103
+ /**
104
+ * getFileProgress: पहिलेको प्रगति पुनः प्राप्त गर्ने (Resume को लागि)
105
+ */
106
+ getFileProgress(deviceId: string, fileId: string): number;
107
+ /**
108
+ * getFileInfo: फाइलको जानकारी लिने
109
+ */
110
+ getFileInfo(fileId: string): FileMetadata | undefined;
111
+ /**
112
+ * listFiles: सबै उपलब्ध फाइलहरूको सूची
113
+ */
114
+ listFiles(): Array<{
115
+ fileId: string;
116
+ name: string;
117
+ size: number;
118
+ totalChunks: number;
119
+ }>;
120
+ /**
121
+ * announceToPeers: फाइलको उपलब्धता सबै पीयरलाई जानकारी दिने
122
+ */
123
+ announceToPeers(fileId: string, availableAtDeviceId: string): void;
124
+ /**
125
+ * getPeersForFile: फाइल भएका पीयरहरूको सूची
126
+ */
127
+ getPeersForFile(fileId: string): string[];
128
+ /**
129
+ * requestFromPeer: पीयरबाट सिधै डाटा माग गर्ने
130
+ */
131
+ requestFromPeer(deviceId: string, peerId: string, fileId: string, chunkIndex: number): boolean;
132
+ /**
133
+ * sendToPeer: पीयरलाई सिधै डाटा पठाउने (Server Pass-through)
134
+ */
135
+ sendToPeer(fromDeviceId: string, toDeviceId: string, payload: any): boolean;
136
+ /**
137
+ * isReady: डिभाइस अनलाइन छ र मेसेज लिन तयार छ कि छैन चेक गर्ने
138
+ */
139
+ isReady(deviceId: string): boolean;
140
+ /**
141
+ * isOnline: डिभाइस अनलाइन छ कि छैन (साधारण चेक)
142
+ */
143
+ isOnline(deviceId: string): boolean;
144
+ /**
145
+ * sendTo: सिधै डिभाइसलाई मेसेज पठाउने (No Pub/Sub overhead)
146
+ */
147
+ sendTo(deviceId: string, payload: any): boolean;
148
+ /**
149
+ * kick: खराब वा अनधिकृत डिभाइसलाई हटाउने
150
+ */
151
+ kick(deviceId: string, reason?: string): void;
152
+ /**
153
+ * broadcastToGroup: कुनै विशेष ग्रुपलाई मात्र मेसेज पठाउने
154
+ */
155
+ broadcastToGroup(groupName: string, payload: any): void;
156
+ /**
157
+ * getOnlineDevices: सबै अनलाइन डिभाइसहरूको लिस्ट दिने
158
+ */
159
+ getOnlineDevices(): Array<{
160
+ id: string;
161
+ lastSeen: number;
162
+ group?: string;
163
+ }>;
164
+ /**
165
+ * ping: डिभाइसलाई Alive छ कि छैन भनेर चेक गर्न Ping पठाउने
166
+ */
167
+ ping(deviceId: string): boolean;
168
+ /**
169
+ * privateSub: केवल आफ्नो निजी च्यानलमा आउने मेसेज सुन्नको लागि
170
+ */
171
+ privateSub(deviceId: string, fn: (data: any) => void): void;
172
+ /**
173
+ * privatePub: कुनै विशेष डिभाइसको निजी च्यानलमा मात्र मेसेज पठाउन
46
174
  */
175
+ privatePub(targetId: string, payload: any, opts?: {
176
+ retain?: boolean;
177
+ ttl?: number;
178
+ }): void;
47
179
  handle(raw: Buffer, socket?: any, deviceId?: string): Promise<void>;
48
180
  broadcast(topic: string, payload: any, opts?: {
49
181
  exclude?: string[];
@@ -54,11 +186,16 @@ export declare class RealtimeCore extends EventEmitter {
54
186
  getSocket(deviceId: string): any;
55
187
  touch(deviceId: string): void;
56
188
  getStats(): {
189
+ version: string;
57
190
  cacheSize: number;
58
191
  devices: number;
59
192
  retained: number;
60
193
  plugins: number;
61
194
  cacheEnabled: boolean;
195
+ highFreqBuffers: number;
196
+ files: number;
197
+ activeTransfers: number;
198
+ peers: number;
62
199
  };
63
200
  /**
64
201
  * Clean up resources - Call this when shutting down
@@ -66,3 +203,7 @@ export declare class RealtimeCore extends EventEmitter {
66
203
  destroy(): Promise<void>;
67
204
  private startCleanup;
68
205
  }
206
+ export { TopicTrie } from './trie';
207
+ export { encode, decode, getSize } from './codec';
208
+ export { RealtimePlugin, RealtimeContext } from './plugins';
209
+ export { djson, toBuffer, toBase64 } from '../djson/djson';