@tachybase/plugin-online-user 0.23.22 → 0.23.35

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 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/schema"),require("react/jsx-runtime"),require("react"),require("antd"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/schema","react/jsx-runtime","react","antd","lodash"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@tachybase/plugin-online-user"]={},n["@tachybase/client"],n["@tachybase/schema"],n.jsxRuntime,n.react,n.antd,n.lodash))})(this,function(n,e,t,o,r,d,h){"use strict";var q=Object.defineProperty;var k=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var x=(n,e,t)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,S=(n,e)=>{for(var t in e||(e={}))w.call(e,t)&&x(n,t,e[t]);if(k)for(var t of k(e))A.call(e,t)&&x(n,t,e[t]);return n};var l=(n,e,t)=>new Promise((o,r)=>{var d=s=>{try{a(t.next(s))}catch(u){r(u)}},h=s=>{try{a(t.throw(s))}catch(u){r(u)}},a=s=>s.done?o(s.value):Promise.resolve(s.value).then(d,h);a((t=t.apply(n,e)).next())});const a="online-user",s=()=>{const{i18n:i}=e.useApp();return{t:(f,y={})=>i.t(f,S({ns:a},y))}},u=()=>{const i=e.useApp(),[c,f]=r.useState([]),y=e.useAPIClient(),{token:U}=e.useToken(),{t:b}=s();return r.useEffect(()=>{i.ws.on("message",m=>{var O;const p=JSON.parse(m.data);if((p==null?void 0:p.type)==="plugin-online-user"){const j=(O=p.payload.users)==null?void 0:O.map(P=>{if(P)return{key:t.uid(),label:P.nickname}});f(j)}})},[i]),r.useEffect(()=>{const m={type:"plugin-online-user:client",payload:{token:y.auth.getToken()}};i.ws.send(JSON.stringify(m))},[]),o.jsx(d.Dropdown,{menu:{items:c},children:o.jsx(d.Button,{style:{width:"auto",color:U.colorTextHeaderMenu},type:"text",children:b("{{num}} people online",{num:h.size(c)})})})},T=i=>o.jsx(e.PinnedPluginListProvider,{items:{ou:{order:230,component:"OnlineUserManger",pin:!0,isPublic:!0}},children:o.jsx(e.SchemaComponentOptions,{components:{OnlineUserManger:u},children:i.children})});class g extends e.Plugin{afterAdd(){return l(this,null,function*(){})}beforeLoad(){return l(this,null,function*(){})}load(){return l(this,null,function*(){this.app.use(T),t.autorun(()=>{if(this.app.ws.connected){const c={type:"plugin-online-user:client",payload:{token:this.app.apiClient.auth.getToken()}};this.app.ws.send(JSON.stringify(c))}})})}}n.PluginOnlineUserClient=g,n.default=g,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/schema"),require("react/jsx-runtime"),require("react"),require("antd"),require("lodash")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/schema","react/jsx-runtime","react","antd","lodash"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@tachybase/plugin-online-user"]={},n["@tachybase/client"],n["@tachybase/schema"],n.jsxRuntime,n.react,n.antd,n.lodash))})(this,function(n,e,t,o,r,d,h){"use strict";var q=Object.defineProperty;var T=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var b=(n,e,t)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,k=(n,e)=>{for(var t in e||(e={}))w.call(e,t)&&b(n,t,e[t]);if(T)for(var t of T(e))A.call(e,t)&&b(n,t,e[t]);return n};var l=(n,e,t)=>new Promise((o,r)=>{var d=s=>{try{a(t.next(s))}catch(u){r(u)}},h=s=>{try{a(t.throw(s))}catch(u){r(u)}},a=s=>s.done?o(s.value):Promise.resolve(s.value).then(d,h);a((t=t.apply(n,e)).next())});const a="online-user",s=()=>{const{i18n:i}=e.useApp();return{t:(f,y={})=>i.t(f,k({ns:a},y))}},u=()=>{const i=e.useApp(),[c,f]=r.useState([]),y=e.useAPIClient(),{token:S}=e.useToken(),{t:U}=s();return r.useEffect(()=>{i.ws.on("message",m=>{var O;const p=JSON.parse(m.data);if((p==null?void 0:p.type)==="plugin-online-user"){const j=(O=p.payload.users)==null?void 0:O.map(P=>{if(P)return{key:t.uid(),label:P.nickname}});f(j)}})},[i]),r.useEffect(()=>{const m={type:"plugin-online-user:client",payload:{token:y.auth.getToken()}};i.ws.send(JSON.stringify(m))},[]),o.jsx(d.Dropdown,{menu:{items:c},children:o.jsx(d.Button,{style:{width:"auto",color:S.colorTextHeaderMenu},type:"text",children:U("{{num}} people online",{num:h.size(c)})})})},x=i=>o.jsx(e.PinnedPluginListProvider,{items:{ou:{order:230,component:"OnlineUserManger",pin:!0,isPublic:!0,belongTo:"pinnedmenu"}},children:o.jsx(e.SchemaComponentOptions,{components:{OnlineUserManger:u},children:i.children})});class g extends e.Plugin{afterAdd(){return l(this,null,function*(){})}beforeLoad(){return l(this,null,function*(){})}load(){return l(this,null,function*(){this.app.use(x),t.autorun(()=>{if(this.app.ws.connected){const c={type:"plugin-online-user:client",payload:{token:this.app.apiClient.auth.getToken()}};this.app.ws.send(JSON.stringify(c))}})})}}n.PluginOnlineUserClient=g,n.default=g,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,10 +1,10 @@
1
1
  module.exports = {
2
2
  "react": "18.3.1",
3
- "@tachybase/client": "0.23.22",
4
- "@tachybase/schema": "0.23.22",
3
+ "@tachybase/client": "0.23.35",
4
+ "@tachybase/schema": "0.23.35",
5
5
  "antd": "5.22.5",
6
6
  "lodash": "4.17.21",
7
- "@tachybase/server": "0.23.22",
8
- "@tachybase/utils": "0.23.22",
7
+ "@tachybase/server": "0.23.35",
8
+ "@tachybase/utils": "0.23.35",
9
9
  "jsonwebtoken": "8.5.1"
10
10
  };
@@ -1 +1 @@
1
- {"name":"redis","description":"A modern, high performance Redis client","version":"4.7.0","license":"MIT","main":"./dist/index.js","types":"./dist/index.d.ts","files":["dist/"],"workspaces":["./packages/*"],"scripts":{"test":"npm run test -ws --if-present","build:client":"npm run build -w ./packages/client","build:test-utils":"npm run build -w ./packages/test-utils","build:tests-tools":"npm run build:client && npm run build:test-utils","build:modules":"find ./packages -mindepth 1 -maxdepth 1 -type d ! -name 'client' ! -name 'test-utils' -exec npm run build -w {} \\;","build":"tsc","build-all":"npm run build:client && npm run build:test-utils && npm run build:modules && npm run build","documentation":"npm run documentation -ws --if-present","gh-pages":"gh-pages -d ./documentation -e ./documentation -u 'documentation-bot <documentation@bot>'"},"dependencies":{"@redis/bloom":"1.2.0","@redis/client":"1.6.0","@redis/graph":"1.1.1","@redis/json":"1.0.7","@redis/search":"1.2.0","@redis/time-series":"1.1.0"},"devDependencies":{"@tsconfig/node14":"^14.1.0","gh-pages":"^6.0.0","release-it":"^16.1.5","typescript":"^5.2.2"},"repository":{"type":"git","url":"git://github.com/redis/node-redis.git"},"bugs":{"url":"https://github.com/redis/node-redis/issues"},"homepage":"https://github.com/redis/node-redis","keywords":["redis"],"_lastModified":"2024-12-30T04:25:21.143Z"}
1
+ {"name":"redis","description":"A modern, high performance Redis client","version":"4.7.0","license":"MIT","main":"./dist/index.js","types":"./dist/index.d.ts","files":["dist/"],"workspaces":["./packages/*"],"scripts":{"test":"npm run test -ws --if-present","build:client":"npm run build -w ./packages/client","build:test-utils":"npm run build -w ./packages/test-utils","build:tests-tools":"npm run build:client && npm run build:test-utils","build:modules":"find ./packages -mindepth 1 -maxdepth 1 -type d ! -name 'client' ! -name 'test-utils' -exec npm run build -w {} \\;","build":"tsc","build-all":"npm run build:client && npm run build:test-utils && npm run build:modules && npm run build","documentation":"npm run documentation -ws --if-present","gh-pages":"gh-pages -d ./documentation -e ./documentation -u 'documentation-bot <documentation@bot>'"},"dependencies":{"@redis/bloom":"1.2.0","@redis/client":"1.6.0","@redis/graph":"1.1.1","@redis/json":"1.0.7","@redis/search":"1.2.0","@redis/time-series":"1.1.0"},"devDependencies":{"@tsconfig/node14":"^14.1.0","gh-pages":"^6.0.0","release-it":"^16.1.5","typescript":"^5.2.2"},"repository":{"type":"git","url":"git://github.com/redis/node-redis.git"},"bugs":{"url":"https://github.com/redis/node-redis/issues"},"homepage":"https://github.com/redis/node-redis","keywords":["redis"],"_lastModified":"2025-01-16T06:27:26.484Z"}
@@ -1 +1 @@
1
- {"name":"ws","version":"8.18.0","description":"Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js","keywords":["HyBi","Push","RFC-6455","WebSocket","WebSockets","real-time"],"homepage":"https://github.com/websockets/ws","bugs":"https://github.com/websockets/ws/issues","repository":{"type":"git","url":"git+https://github.com/websockets/ws.git"},"author":"Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)","license":"MIT","main":"index.js","exports":{".":{"browser":"./browser.js","import":"./wrapper.mjs","require":"./index.js"},"./package.json":"./package.json"},"browser":"browser.js","engines":{"node":">=10.0.0"},"files":["browser.js","index.js","lib/*.js","wrapper.mjs"],"scripts":{"test":"nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js","integration":"mocha --throw-deprecation test/*.integration.js","lint":"eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""},"peerDependencies":{"bufferutil":"^4.0.1","utf-8-validate":">=5.0.2"},"peerDependenciesMeta":{"bufferutil":{"optional":true},"utf-8-validate":{"optional":true}},"devDependencies":{"benchmark":"^2.1.4","bufferutil":"^4.0.1","eslint":"^9.0.0","eslint-config-prettier":"^9.0.0","eslint-plugin-prettier":"^5.0.0","globals":"^15.0.0","mocha":"^8.4.0","nyc":"^15.0.0","prettier":"^3.0.0","utf-8-validate":"^6.0.0"},"_lastModified":"2024-12-30T04:25:21.387Z"}
1
+ {"name":"ws","version":"8.18.0","description":"Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js","keywords":["HyBi","Push","RFC-6455","WebSocket","WebSockets","real-time"],"homepage":"https://github.com/websockets/ws","bugs":"https://github.com/websockets/ws/issues","repository":{"type":"git","url":"git+https://github.com/websockets/ws.git"},"author":"Einar Otto Stangvik <einaros@gmail.com> (http://2x.io)","license":"MIT","main":"index.js","exports":{".":{"browser":"./browser.js","import":"./wrapper.mjs","require":"./index.js"},"./package.json":"./package.json"},"browser":"browser.js","engines":{"node":">=10.0.0"},"files":["browser.js","index.js","lib/*.js","wrapper.mjs"],"scripts":{"test":"nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js","integration":"mocha --throw-deprecation test/*.integration.js","lint":"eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\""},"peerDependencies":{"bufferutil":"^4.0.1","utf-8-validate":">=5.0.2"},"peerDependenciesMeta":{"bufferutil":{"optional":true},"utf-8-validate":{"optional":true}},"devDependencies":{"benchmark":"^2.1.4","bufferutil":"^4.0.1","eslint":"^9.0.0","eslint-config-prettier":"^9.0.0","eslint-plugin-prettier":"^5.0.0","globals":"^15.0.0","mocha":"^8.4.0","nyc":"^15.0.0","prettier":"^3.0.0","utf-8-validate":"^6.0.0"},"_lastModified":"2025-01-16T06:27:26.761Z"}
@@ -1,7 +1,4 @@
1
1
  export declare class ConnectionManager {
2
- private redisClient;
3
- private redisPubClient;
4
- private redisSubClient;
5
2
  private app;
6
3
  unload(): Promise<void>;
7
4
  load(): Promise<void>;
@@ -84,34 +84,41 @@ const KEY_ONLINE_USERS = "online_users";
84
84
  _ConnectionManager_decorators = [(0, import_utils.Service)()], _app_dec = [(0, import_utils.App)()];
85
85
  class ConnectionManager {
86
86
  constructor() {
87
- __publicField(this, "redisClient", (0, import_redis.createClient)({
88
- url: process.env.REDIS_URL ?? "redis://127.0.0.1:6379"
89
- }));
90
- __publicField(this, "redisPubClient", this.redisClient.duplicate());
91
- __publicField(this, "redisSubClient", this.redisClient.duplicate());
92
87
  __publicField(this, "app", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
93
88
  }
94
89
  async unload() {
95
- for (const client of [this.redisClient, this.redisPubClient, this.redisSubClient]) {
90
+ for (const client of [this.app.online.all, this.app.online.pub, this.app.online.sub]) {
96
91
  if (client.isOpen) {
97
92
  await client.disconnect();
98
93
  }
99
94
  }
100
95
  }
101
96
  async load() {
102
- if (this.redisClient.isOpen) {
103
- return;
97
+ if (!this.app.online) {
98
+ const all = (0, import_redis.createClient)({
99
+ url: process.env.REDIS_URL ?? "redis://127.0.0.1:6379"
100
+ });
101
+ const pub = all.duplicate();
102
+ const sub = all.duplicate();
103
+ this.app.online = {
104
+ all,
105
+ pub,
106
+ sub
107
+ };
104
108
  }
105
- await this.redisClient.connect();
106
- await this.redisPubClient.connect();
107
- await this.redisSubClient.connect();
108
109
  this.app.on("afterStop", () => {
109
110
  this.unload();
110
111
  });
112
+ if (this.app.online.all.isOpen) {
113
+ return;
114
+ }
115
+ await this.app.online.all.connect();
116
+ await this.app.online.pub.connect();
117
+ await this.app.online.sub.connect();
111
118
  if ((0, import_utils.isMain)()) {
112
- const keysToDelete = await this.redisClient.KEYS(`${KEY_ONLINE_USERS}*`);
119
+ const keysToDelete = await this.app.online.all.KEYS(`${KEY_ONLINE_USERS}*`);
113
120
  if (keysToDelete.length > 0) {
114
- await this.redisClient.DEL(...keysToDelete);
121
+ await this.app.online.all.DEL(...keysToDelete);
115
122
  }
116
123
  }
117
124
  await this.loadWsServer();
@@ -120,13 +127,13 @@ class ConnectionManager {
120
127
  const appName = this.app.name;
121
128
  const gateway = import_server.Gateway.getInstance();
122
129
  const ws = gateway["wsServer"];
123
- await this.redisSubClient.SUBSCRIBE(KEY_ONLINE_USERS + appName, async (num) => {
130
+ await this.app.online.sub.SUBSCRIBE(KEY_ONLINE_USERS + appName, async (num) => {
124
131
  if (num !== (0, import_utils.currentProcessNum)()) {
125
132
  await notifyAllClients(false);
126
133
  }
127
134
  });
128
135
  const notifyAllClients = async (broadcast = true) => {
129
- const users = (await this.redisClient.HVALS(KEY_ONLINE_USERS + appName)).map((u) => JSON.parse(u));
136
+ const users = (await this.app.online.all.HVALS(KEY_ONLINE_USERS + appName)).map((u) => JSON.parse(u));
130
137
  ws.sendToConnectionsByTag("app", appName, {
131
138
  type: "plugin-online-user",
132
139
  payload: {
@@ -134,7 +141,7 @@ class ConnectionManager {
134
141
  }
135
142
  });
136
143
  if (broadcast) {
137
- await this.redisPubClient.PUBLISH(KEY_ONLINE_USERS + appName, (0, import_utils.currentProcessNum)());
144
+ await this.app.online.pub.PUBLISH(KEY_ONLINE_USERS + appName, (0, import_utils.currentProcessNum)());
138
145
  }
139
146
  };
140
147
  const getUserById = async (id) => {
@@ -149,7 +156,7 @@ class ConnectionManager {
149
156
  await notifyAllClients();
150
157
  });
151
158
  ws2.on("close", async () => {
152
- await this.redisClient.HDEL(KEY_ONLINE_USERS + appName, ws2.id);
159
+ await this.app.online.all.HDEL(KEY_ONLINE_USERS + appName, ws2.id);
153
160
  await notifyAllClients();
154
161
  });
155
162
  ws2.on("message", async (data) => {
@@ -160,7 +167,7 @@ class ConnectionManager {
160
167
  const analysis = import_jsonwebtoken.default.verify(userMeg.payload.token, process.env.APP_KEY);
161
168
  const userId = analysis.userId;
162
169
  const user = await getUserById(userId);
163
- await this.redisClient.HSET(KEY_ONLINE_USERS + appName, ws2.id, JSON.stringify(user));
170
+ await this.app.online.all.HSET(KEY_ONLINE_USERS + appName, ws2.id, JSON.stringify(user));
164
171
  await notifyAllClients();
165
172
  } catch (error) {
166
173
  console.warn(error.message);
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-online-user",
3
- "version": "0.23.22",
3
+ "version": "0.23.35",
4
4
  "main": "dist/server/index.js",
5
5
  "dependencies": {},
6
6
  "devDependencies": {
@@ -12,11 +12,11 @@
12
12
  "ws": "^8.18.0"
13
13
  },
14
14
  "peerDependencies": {
15
- "@tachybase/client": "0.23.22",
16
- "@tachybase/schema": "0.23.22",
17
- "@tachybase/server": "0.23.22",
18
- "@tachybase/test": "0.23.22",
19
- "@tachybase/utils": "0.23.22"
15
+ "@tachybase/client": "0.23.35",
16
+ "@tachybase/server": "0.23.35",
17
+ "@tachybase/test": "0.23.35",
18
+ "@tachybase/schema": "0.23.35",
19
+ "@tachybase/utils": "0.23.35"
20
20
  },
21
21
  "description.zh-CN": "在线用户管理(建设中)",
22
22
  "displayName.zh-CN": "在线用户管理(建设中)",