@fuzionx/core 0.1.22 → 0.1.24

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.
Files changed (2) hide show
  1. package/lib/ws.js +28 -13
  2. package/package.json +2 -2
package/lib/ws.js CHANGED
@@ -14,39 +14,40 @@
14
14
  * 개별 WebSocket 연결을 나타내는 래퍼.
15
15
  */
16
16
  class FuzionXSocket {
17
- constructor(sessionId, bridge) {
17
+ constructor(sessionId, bridge, namespace) {
18
18
  this._bridge = bridge;
19
+ this._namespace = namespace || null;
19
20
  this.sessionId = sessionId;
20
21
  }
21
22
 
22
23
  /** 이 소켓에 메시지 전송 */
23
24
  send(data) {
24
25
  const msg = typeof data === 'string' ? data : JSON.stringify(data);
25
- this._bridge.wsSendTo(this.sessionId, msg);
26
+ this._bridge.wsSendTo(this.sessionId, msg, this._namespace);
26
27
  }
27
28
 
28
- /** 전체 연결에 브로드캐스트 */
29
+ /** 전체 연결에 브로드캐스트 (네임스페이스 범위) */
29
30
  broadcast(data) {
30
31
  const msg = typeof data === 'string' ? data : JSON.stringify(data);
31
- this._bridge.wsBroadcast(msg);
32
+ this._bridge.wsBroadcast(msg, this._namespace);
32
33
  }
33
34
 
34
- /** 자신을 제외하고 브로드캐스트 */
35
+ /** 자신을 제외하고 브로드캐스트 (네임스페이스 범위) */
35
36
  broadcastExcluding(data) {
36
37
  const msg = typeof data === 'string' ? data : JSON.stringify(data);
37
- this._bridge.wsBroadcastExcluding(msg, this.sessionId);
38
+ this._bridge.wsBroadcastExcluding(msg, this.sessionId, this._namespace);
38
39
  }
39
40
 
40
- /** 여러 세션에 전송 */
41
+ /** 여러 세션에 전송 (네임스페이스 범위) */
41
42
  sendToMany(sessionIds, data) {
42
43
  const msg = typeof data === 'string' ? data : JSON.stringify(data);
43
- this._bridge.wsSendToMany(sessionIds, msg);
44
+ this._bridge.wsSendToMany(sessionIds, msg, this._namespace);
44
45
  }
45
46
 
46
- /** 메타데이터 매칭 세션에 전송 */
47
+ /** 메타데이터 매칭 세션에 전송 (네임스페이스 범위) */
47
48
  sendToMatch(key, value, data) {
48
49
  const msg = typeof data === 'string' ? data : JSON.stringify(data);
49
- this._bridge.wsSendToMetadataMatch(key, value, msg);
50
+ this._bridge.wsSendToMetadataMatch(key, value, msg, this._namespace);
50
51
  }
51
52
 
52
53
  /** 메타데이터 설정 */
@@ -59,6 +60,20 @@ class FuzionXSocket {
59
60
  return this._bridge.wsGetMetadata(this.sessionId, key);
60
61
  }
61
62
 
63
+ /** 네임스페이스별 접속자 수 */
64
+ get onlineCount() {
65
+ return this._namespace
66
+ ? this._bridge.wsGetOnlineCountNs(this._namespace)
67
+ : this._bridge.wsGetOnlineCount();
68
+ }
69
+
70
+ /** 네임스페이스별 세션 ID 목록 */
71
+ get sessionIds() {
72
+ return this._namespace
73
+ ? this._bridge.wsGetSessionIdsNs(this._namespace)
74
+ : this._bridge.wsGetSessionIds();
75
+ }
76
+
62
77
  /** 연결 끊기 */
63
78
  disconnect() {
64
79
  this._bridge.wsDisconnect(this.sessionId);
@@ -111,7 +126,7 @@ export function createWs(bridge) {
111
126
  bridge.wsOnConnect((namespace, sessionId) => {
112
127
  const ns = namespaces.get(namespace);
113
128
  if (ns && ns._handlers.connect) {
114
- ns._handlers.connect(new FuzionXSocket(sessionId, bridge));
129
+ ns._handlers.connect(new FuzionXSocket(sessionId, bridge, namespace));
115
130
  }
116
131
  });
117
132
 
@@ -119,7 +134,7 @@ export function createWs(bridge) {
119
134
  bridge.wsOnMessage((namespace, sessionId, message) => {
120
135
  const ns = namespaces.get(namespace);
121
136
  if (ns && ns._handlers.message) {
122
- ns._handlers.message(new FuzionXSocket(sessionId, bridge), message);
137
+ ns._handlers.message(new FuzionXSocket(sessionId, bridge, namespace), message);
123
138
  }
124
139
  });
125
140
 
@@ -127,7 +142,7 @@ export function createWs(bridge) {
127
142
  bridge.wsOnDisconnect((namespace, sessionId) => {
128
143
  const ns = namespaces.get(namespace);
129
144
  if (ns && ns._handlers.disconnect) {
130
- ns._handlers.disconnect(new FuzionXSocket(sessionId, bridge));
145
+ ns._handlers.disconnect(new FuzionXSocket(sessionId, bridge, namespace));
131
146
  }
132
147
  });
133
148
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuzionx/core",
3
- "version": "0.1.22",
3
+ "version": "0.1.24",
4
4
  "type": "module",
5
5
  "description": "Express-style Node.js framework powered by FuzionX native bridge — 167K RPS single process",
6
6
  "main": "index.js",
@@ -18,7 +18,7 @@
18
18
  "url": "https://github.com/saytohenry/fuzionx"
19
19
  },
20
20
  "dependencies": {
21
- "@fuzionx/bridge": "^0.1.22"
21
+ "@fuzionx/bridge": "^0.1.24"
22
22
  },
23
23
  "files": [
24
24
  "index.js",