@ozdao/martyrs 0.2.468 → 0.2.470
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/dist/{Media-DwVcRIAX.mjs → Media-C4Ges_Sd.mjs} +1 -1
- package/dist/{Media-DCGbUujy.js → Media-CR0V1zvB.js} +1 -1
- package/dist/chats.server.js +14 -13
- package/dist/chats.server.mjs +14 -13
- package/dist/globals.server.js +20 -12
- package/dist/globals.server.mjs +20 -12
- package/dist/{main-DEHjtgLs.mjs → main-CTcal9qN.mjs} +900 -884
- package/dist/{main-UVdexuMN.js → main-CsZAG5Wz.js} +5 -5
- package/dist/martyrs/src/components/Block/Block.vue.cjs +1 -1
- package/dist/martyrs/src/components/Block/Block.vue.js +1 -1
- package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.cjs → SelectMulti.vue.cjs} +2 -2
- package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.js.map → SelectMulti.vue.cjs.map} +1 -1
- package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.js → SelectMulti.vue.js} +2 -2
- package/dist/martyrs/src/components/SelectMulti/SelectMulti.vue.js.map +1 -0
- package/dist/martyrs/src/components/Tooltip/{Tooltip.vue.cjs → Tooltip.vue2.cjs} +2 -2
- package/dist/martyrs/src/components/Tooltip/Tooltip.vue2.cjs.map +1 -0
- package/dist/martyrs/src/components/Tooltip/{Tooltip.vue.js → Tooltip.vue2.js} +2 -2
- package/dist/martyrs/src/components/Tooltip/{Tooltip.vue.cjs.map → Tooltip.vue2.js.map} +1 -1
- package/dist/martyrs/src/modules/backoffice/components/partials/Sidebar.vue.cjs +1 -1
- package/dist/martyrs/src/modules/backoffice/components/partials/Sidebar.vue.js +1 -1
- package/dist/martyrs/src/modules/chats/store/chat.store.cjs +47 -16
- package/dist/martyrs/src/modules/chats/store/chat.store.cjs.map +1 -1
- package/dist/martyrs/src/modules/chats/store/chat.store.js +47 -16
- package/dist/martyrs/src/modules/chats/store/chat.store.js.map +1 -1
- package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.cjs +1 -1
- package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.js +1 -1
- package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.js.map +1 -1
- package/dist/martyrs/src/modules/community/components/pages/Blog.vue.cjs +1 -1
- package/dist/martyrs/src/modules/community/components/pages/Blog.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/community/components/pages/Blog.vue.js +1 -1
- package/dist/martyrs/src/modules/community/components/pages/Blog.vue.js.map +1 -1
- package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.cjs +4 -1
- package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.js +4 -1
- package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.js.map +1 -1
- package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.cjs +3 -3
- package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.js +3 -3
- package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.js.map +1 -1
- package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.cjs +1 -1
- package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.js +1 -1
- package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.js.map +1 -1
- package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.cjs +9 -9
- package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.js +9 -9
- package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.js.map +1 -1
- package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.cjs +2 -2
- package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.js +2 -2
- package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.js.map +1 -1
- package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
- package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.js +1 -1
- package/dist/martyrs/src/modules/globals/globals.client.cjs +0 -9
- package/dist/martyrs/src/modules/globals/globals.client.cjs.map +1 -1
- package/dist/martyrs/src/modules/globals/globals.client.js +0 -9
- package/dist/martyrs/src/modules/globals/globals.client.js.map +1 -1
- package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.cjs +40 -97
- package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.cjs.map +1 -1
- package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.js +40 -97
- package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.js.map +1 -1
- package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.cjs +1 -1
- package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.js +1 -1
- package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.cjs +1 -1
- package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.js +1 -1
- package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.js.map +1 -1
- package/dist/martyrs/src/modules/notifications/notifications.client.cjs +35 -9
- package/dist/martyrs/src/modules/notifications/notifications.client.cjs.map +1 -1
- package/dist/martyrs/src/modules/notifications/notifications.client.js +35 -9
- package/dist/martyrs/src/modules/notifications/notifications.client.js.map +1 -1
- package/dist/martyrs/src/modules/orders/components/blocks/CardOrderUser.vue.cjs +1 -1
- package/dist/martyrs/src/modules/orders/components/blocks/CardOrderUser.vue.js +1 -1
- package/dist/martyrs/src/modules/orders/components/pages/OrderBackoffice.vue.cjs +1 -1
- package/dist/martyrs/src/modules/orders/components/pages/OrderBackoffice.vue.js +1 -1
- package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs +7 -7
- package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js +8 -8
- package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js.map +1 -1
- package/dist/martyrs/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
- package/dist/martyrs/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +1 -1
- package/dist/martyrs/src/modules/organizations/components/pages/Members.vue.cjs +1 -1
- package/dist/martyrs/src/modules/organizations/components/pages/Members.vue.js +1 -1
- package/dist/martyrs/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs +1 -1
- package/dist/martyrs/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js +1 -1
- package/dist/martyrs/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
- package/dist/martyrs/src/modules/organizations/components/pages/OrganizationEdit.vue.js +1 -1
- package/dist/martyrs/src/modules/pages/views/components/pages/PageEdit.vue.cjs +1 -1
- package/dist/martyrs/src/modules/pages/views/components/pages/PageEdit.vue.js +1 -1
- package/dist/martyrs/src/modules/products/components/blocks/CardPosition.vue.cjs +1 -1
- package/dist/martyrs/src/modules/products/components/blocks/CardPosition.vue.js +1 -1
- package/dist/martyrs/src/modules/products/components/pages/EditLeftover.vue.cjs +1 -1
- package/dist/martyrs/src/modules/products/components/pages/EditLeftover.vue.js +1 -1
- package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs +6 -5
- package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs.map +1 -1
- package/dist/martyrs/src/modules/products/components/pages/Product.vue.js +6 -5
- package/dist/martyrs/src/modules/products/components/pages/Product.vue.js.map +1 -1
- package/dist/martyrs/src/modules/rents/views/components/pages/RentsEdit.vue.cjs +1 -1
- package/dist/martyrs/src/modules/rents/views/components/pages/RentsEdit.vue.js +1 -1
- package/dist/martyrs.cjs.js +1 -1
- package/dist/martyrs.css +1 -1
- package/dist/martyrs.es.js +1 -1
- package/dist/notifications.server.js +69 -13
- package/dist/notifications.server.mjs +69 -13
- package/dist/orders.server.js +1 -0
- package/dist/orders.server.mjs +1 -0
- package/package.json +1 -1
- package/src/components/Shader/Shader.vue +44 -25
- package/src/modules/chats/routes/chats.routes.js +21 -17
- package/src/modules/chats/store/chat.store.js +55 -28
- package/src/modules/community/components/blocks/CardBlogpost.vue +1 -1
- package/src/modules/community/components/pages/Blog.vue +1 -1
- package/src/modules/community/components/pages/BlogPost.vue +1 -0
- package/src/modules/community/components/pages/CreateBlogPost.vue +3 -3
- package/src/modules/constructor/components/elements/VideoPlayer.vue +1 -1
- package/src/modules/constructor/components/sections/Constructor.vue +9 -9
- package/src/modules/events/components/pages/EditEvent.vue +1 -1
- package/src/modules/globals/controllers/classes/globals.websocket.js +29 -21
- package/src/modules/globals/globals.client.js +0 -12
- package/src/modules/globals/views/classes/globals.websocket.js +46 -146
- package/src/modules/icons/skeletons/SkeletonBlogpost.vue +2 -2
- package/src/modules/notifications/controllers/notifications.controller.js +2 -2
- package/src/modules/notifications/notifications.client.js +57 -19
- package/src/modules/notifications/notifications.server.js +3 -1
- package/src/modules/notifications/routes/notifications.routes.js +2 -2
- package/src/modules/notifications/services/notification.service.js +34 -15
- package/src/modules/notifications/services/web-push.service.js +7 -6
- package/src/modules/orders/components/pages/OrderCreate.vue +3 -4
- package/src/modules/orders/controllers/orders.controller.js +2 -0
- package/src/modules/products/components/pages/Product.vue +7 -6
- package/dist/martyrs/src/components/SelectMulti/SelectMulti.vue2.cjs.map +0 -1
- package/dist/martyrs/src/components/Tooltip/Tooltip.vue.js.map +0 -1
- package/src/modules/notifications/notifications2.client.js +0 -256
- package/src/modules/notifications/services/websocket.service.js +0 -100
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref as u, computed as m, onMounted as N, onUnmounted as P, createElementBlock as c, openBlock as d, createCommentVNode as f, mergeProps as V, createElementVNode as S, toDisplayString as q } from "vue";
|
|
2
|
-
import { _ as z } from "./main-
|
|
2
|
+
import { _ as z } from "./main-CTcal9qN.mjs";
|
|
3
3
|
const D = { class: "media-container" }, T = ["src", "data-src", "alt"], U = ["controls", "loop", "muted", "autoplay", "playsinline", "preload"], _ = ["src", "type"], $ = {
|
|
4
4
|
key: 2,
|
|
5
5
|
class: "media-placeholder"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),V=require("./main-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),V=require("./main-CsZAG5Wz.js"),C={class:"media-container"},M=["src","data-src","alt"],j=["controls","loop","muted","autoplay","playsinline","preload"],N=["src","type"],O={key:2,class:"media-placeholder"},P={key:3,class:"media-error"},S={__name:"Media",props:{url:{type:String,required:!0},options:{type:Object,default:()=>({muted:!0,loop:!0,playsinline:!0,preload:"metadata"})}},setup(t){const m=t,l=e.ref(null),p=e.ref(null),s=e.ref(!1),u=e.ref(null),v=e.ref(!1);let i=null,f=!1;const d=e.computed(()=>{var o,a,n;return(n=(a=(o=m.url)==null?void 0:o.split("."))==null?void 0:a.pop())==null?void 0:n.toLowerCase()}),g=e.computed(()=>["jpg","jpeg","png","gif","webp","svg","avif"].includes(d.value)),y=e.computed(()=>["mp4","webm","ogg"].includes(d.value)),x=e.computed(()=>({mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg"})[d.value]||"");function E(){s.value=!0}function I(o){u.value=`Ошибка загрузки медиа: ${o.message}`,s.value=!1}async function w(){if(l.value)try{l.value.paused&&!f&&(await l.value.play(),f=!0)}catch(o){I(o)}}function L(){const o={root:null,rootMargin:"50px",threshold:.1};i=new IntersectionObserver(n=>{n.forEach(r=>{var c;v.value=r.isIntersecting,r.isIntersecting&&(y.value&&((c=m.options)!=null&&c.autoplay)&&w(),i.disconnect())})},o);const a=g.value?p.value:l.value;a&&i.observe(a)}return e.onMounted(()=>{L()}),e.onUnmounted(()=>{i&&i.disconnect()}),(o,a)=>{var n,r,c,k,h,b,B;return e.openBlock(),e.createElementBlock("div",C,[g.value?(e.openBlock(),e.createElementBlock("img",e.mergeProps({key:0,src:v.value?t.url:"","data-src":t.url,alt:((n=t.options)==null?void 0:n.alt)||"Image",class:["media-item",{loading:!s.value}],loading:"lazy",onLoad:E},t.options,{ref_key:"imageElement",ref:p}),null,16,M)):y.value?(e.openBlock(),e.createElementBlock("video",e.mergeProps({key:1,ref_key:"videoElement",ref:l,class:[{loading:!s.value},"media-item"],controls:!((r=t.options)!=null&&r.hideControls),loop:((c=t.options)==null?void 0:c.loop)!==!1,muted:((k=t.options)==null?void 0:k.muted)!==!1,autoplay:(h=t.options)==null?void 0:h.autoplay,playsinline:((b=t.options)==null?void 0:b.playsinline)!==!1,preload:((B=t.options)==null?void 0:B.preload)||"metadata",onLoadeddata:E},t.options),[e.createElementVNode("source",{src:t.url,type:x.value},null,8,N)],16,j)):e.createCommentVNode("",!0),s.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",O," Loading... ")),u.value?(e.openBlock(),e.createElementBlock("div",P,e.toDisplayString(u.value),1)):e.createCommentVNode("",!0)])}}},q=V._export_sfc(S,[["__scopeId","data-v-1f94a0e9"]]);exports.default=q;
|
package/dist/chats.server.js
CHANGED
|
@@ -47,17 +47,23 @@ function requireChats_routes() {
|
|
|
47
47
|
const { verifySignUp, verifyUser } = middlewareFactory(db);
|
|
48
48
|
wss.registerModule("chat", async (ws, msg) => {
|
|
49
49
|
if (msg.type === "joinChat") {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
if (!msg.chatId) return;
|
|
51
|
+
if (!ws.activeChats) ws.activeChats = /* @__PURE__ */ new Set();
|
|
52
|
+
ws.activeChats.add(msg.chatId);
|
|
53
|
+
}
|
|
54
|
+
if (msg.type === "message") {
|
|
52
55
|
const savedMessage = await controller.saveMessage(msg);
|
|
53
|
-
wss.broadcastToModuleWithFilter(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
savedMessage
|
|
57
|
-
);
|
|
56
|
+
wss.broadcastToModuleWithFilter("chat", (client) => {
|
|
57
|
+
return client.activeChats?.has(msg.chatId);
|
|
58
|
+
}, savedMessage);
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
|
-
app.
|
|
61
|
+
app.get("/messages/:chatId", async (req, res) => {
|
|
62
|
+
const { chatId } = req.params;
|
|
63
|
+
const messages = await controller.getMessages(chatId);
|
|
64
|
+
res.json(messages);
|
|
65
|
+
});
|
|
66
|
+
app.use((req, res, next) => {
|
|
61
67
|
res.header(
|
|
62
68
|
"Access-Control-Allow-Headers",
|
|
63
69
|
"Access-Control-Allow-Origin: *",
|
|
@@ -65,11 +71,6 @@ function requireChats_routes() {
|
|
|
65
71
|
);
|
|
66
72
|
next();
|
|
67
73
|
});
|
|
68
|
-
app.get("/messages/:chatId", async (req, res) => {
|
|
69
|
-
const { chatId } = req.params;
|
|
70
|
-
const messages = await controller.getMessages(chatId);
|
|
71
|
-
res.json(messages);
|
|
72
|
-
});
|
|
73
74
|
};
|
|
74
75
|
return chats_routes;
|
|
75
76
|
}
|
package/dist/chats.server.mjs
CHANGED
|
@@ -46,17 +46,23 @@ function requireChats_routes() {
|
|
|
46
46
|
const { verifySignUp, verifyUser } = middlewareFactory(db);
|
|
47
47
|
wss.registerModule("chat", async (ws, msg) => {
|
|
48
48
|
if (msg.type === "joinChat") {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
if (!msg.chatId) return;
|
|
50
|
+
if (!ws.activeChats) ws.activeChats = /* @__PURE__ */ new Set();
|
|
51
|
+
ws.activeChats.add(msg.chatId);
|
|
52
|
+
}
|
|
53
|
+
if (msg.type === "message") {
|
|
51
54
|
const savedMessage = await controller.saveMessage(msg);
|
|
52
|
-
wss.broadcastToModuleWithFilter(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
savedMessage
|
|
56
|
-
);
|
|
55
|
+
wss.broadcastToModuleWithFilter("chat", (client) => {
|
|
56
|
+
return client.activeChats?.has(msg.chatId);
|
|
57
|
+
}, savedMessage);
|
|
57
58
|
}
|
|
58
59
|
});
|
|
59
|
-
app.
|
|
60
|
+
app.get("/messages/:chatId", async (req, res) => {
|
|
61
|
+
const { chatId } = req.params;
|
|
62
|
+
const messages = await controller.getMessages(chatId);
|
|
63
|
+
res.json(messages);
|
|
64
|
+
});
|
|
65
|
+
app.use((req, res, next) => {
|
|
60
66
|
res.header(
|
|
61
67
|
"Access-Control-Allow-Headers",
|
|
62
68
|
"Access-Control-Allow-Origin: *",
|
|
@@ -64,11 +70,6 @@ function requireChats_routes() {
|
|
|
64
70
|
);
|
|
65
71
|
next();
|
|
66
72
|
});
|
|
67
|
-
app.get("/messages/:chatId", async (req, res) => {
|
|
68
|
-
const { chatId } = req.params;
|
|
69
|
-
const messages = await controller.getMessages(chatId);
|
|
70
|
-
res.json(messages);
|
|
71
|
-
});
|
|
72
73
|
};
|
|
73
74
|
return chats_routes;
|
|
74
75
|
}
|
package/dist/globals.server.js
CHANGED
|
@@ -64,20 +64,20 @@ function requireGlobals_websocket() {
|
|
|
64
64
|
this.modules = /* @__PURE__ */ new Map();
|
|
65
65
|
this.userConnections = /* @__PURE__ */ new Map();
|
|
66
66
|
this.wss.on("connection", (ws, req) => {
|
|
67
|
-
ws.moduleName = null;
|
|
68
67
|
ws.userId = req.userId || null;
|
|
68
|
+
ws.subscriptions = /* @__PURE__ */ new Set();
|
|
69
69
|
if (ws.userId) {
|
|
70
70
|
this._trackUserConnection(ws.userId, ws);
|
|
71
71
|
}
|
|
72
72
|
ws.on("message", async (rawMessage) => {
|
|
73
73
|
try {
|
|
74
74
|
const msg = JSON.parse(rawMessage);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
if (msg.type === "subscribe" && msg.module && this.modules.has(msg.module)) {
|
|
76
|
+
ws.subscriptions.add(msg.module);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const moduleName = msg.module;
|
|
79
80
|
if (moduleName && this.modules.has(moduleName)) {
|
|
80
|
-
ws.moduleName = moduleName;
|
|
81
81
|
const handler = this.modules.get(moduleName);
|
|
82
82
|
await handler(ws, msg);
|
|
83
83
|
}
|
|
@@ -97,7 +97,7 @@ function requireGlobals_websocket() {
|
|
|
97
97
|
}
|
|
98
98
|
verifyClient(info, done) {
|
|
99
99
|
try {
|
|
100
|
-
const userCookie = info.req.headers.cookie?.split("; ").find((
|
|
100
|
+
const userCookie = info.req.headers.cookie?.split("; ").find((c) => c.startsWith("user="));
|
|
101
101
|
if (!userCookie) return done(true);
|
|
102
102
|
const token = JSON.parse(decodeURIComponent(userCookie.replace("user=", "")));
|
|
103
103
|
const decoded = jwt.verify(token.accessToken, process.env.SECRET_KEY);
|
|
@@ -117,25 +117,33 @@ function requireGlobals_websocket() {
|
|
|
117
117
|
this.modules.set(moduleName, handler);
|
|
118
118
|
}
|
|
119
119
|
sendToUserInModule(moduleName, userId, data) {
|
|
120
|
-
const
|
|
121
|
-
|
|
120
|
+
const userIdStr = userId.toString();
|
|
121
|
+
const sockets = this.userConnections.get(userIdStr);
|
|
122
|
+
if (!sockets) {
|
|
123
|
+
console.log(`No sockets found for user ${userIdStr}`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
let sent = false;
|
|
122
127
|
for (const ws of sockets) {
|
|
123
|
-
if (ws.readyState === 1 && ws.moduleName
|
|
128
|
+
if (ws.readyState === 1 && ws.subscriptions.has(moduleName)) {
|
|
124
129
|
ws.send(JSON.stringify(data));
|
|
130
|
+
sent = true;
|
|
125
131
|
}
|
|
126
132
|
}
|
|
133
|
+
return sent;
|
|
127
134
|
}
|
|
128
135
|
broadcastToModule(moduleName, data) {
|
|
129
136
|
for (const ws of this.wss.clients) {
|
|
130
|
-
if (ws.readyState === 1 && ws.moduleName
|
|
137
|
+
if (ws.readyState === 1 && ws.subscriptions.has(moduleName)) {
|
|
131
138
|
ws.send(JSON.stringify(data));
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
}
|
|
135
142
|
broadcastToModuleWithFilter(moduleName, filterFn, data) {
|
|
143
|
+
this.userConnections;
|
|
136
144
|
for (const ws of this.wss.clients) {
|
|
137
145
|
if (ws.readyState !== 1) continue;
|
|
138
|
-
if (ws.moduleName
|
|
146
|
+
if (!ws.subscriptions.has(moduleName)) continue;
|
|
139
147
|
if (!filterFn(ws)) continue;
|
|
140
148
|
ws.send(JSON.stringify(data));
|
|
141
149
|
}
|
package/dist/globals.server.mjs
CHANGED
|
@@ -63,20 +63,20 @@ function requireGlobals_websocket() {
|
|
|
63
63
|
this.modules = /* @__PURE__ */ new Map();
|
|
64
64
|
this.userConnections = /* @__PURE__ */ new Map();
|
|
65
65
|
this.wss.on("connection", (ws, req) => {
|
|
66
|
-
ws.moduleName = null;
|
|
67
66
|
ws.userId = req.userId || null;
|
|
67
|
+
ws.subscriptions = /* @__PURE__ */ new Set();
|
|
68
68
|
if (ws.userId) {
|
|
69
69
|
this._trackUserConnection(ws.userId, ws);
|
|
70
70
|
}
|
|
71
71
|
ws.on("message", async (rawMessage) => {
|
|
72
72
|
try {
|
|
73
73
|
const msg = JSON.parse(rawMessage);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
if (msg.type === "subscribe" && msg.module && this.modules.has(msg.module)) {
|
|
75
|
+
ws.subscriptions.add(msg.module);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const moduleName = msg.module;
|
|
78
79
|
if (moduleName && this.modules.has(moduleName)) {
|
|
79
|
-
ws.moduleName = moduleName;
|
|
80
80
|
const handler = this.modules.get(moduleName);
|
|
81
81
|
await handler(ws, msg);
|
|
82
82
|
}
|
|
@@ -96,7 +96,7 @@ function requireGlobals_websocket() {
|
|
|
96
96
|
}
|
|
97
97
|
verifyClient(info, done) {
|
|
98
98
|
try {
|
|
99
|
-
const userCookie = info.req.headers.cookie?.split("; ").find((
|
|
99
|
+
const userCookie = info.req.headers.cookie?.split("; ").find((c) => c.startsWith("user="));
|
|
100
100
|
if (!userCookie) return done(true);
|
|
101
101
|
const token = JSON.parse(decodeURIComponent(userCookie.replace("user=", "")));
|
|
102
102
|
const decoded = jwt.verify(token.accessToken, process.env.SECRET_KEY);
|
|
@@ -116,25 +116,33 @@ function requireGlobals_websocket() {
|
|
|
116
116
|
this.modules.set(moduleName, handler);
|
|
117
117
|
}
|
|
118
118
|
sendToUserInModule(moduleName, userId, data) {
|
|
119
|
-
const
|
|
120
|
-
|
|
119
|
+
const userIdStr = userId.toString();
|
|
120
|
+
const sockets = this.userConnections.get(userIdStr);
|
|
121
|
+
if (!sockets) {
|
|
122
|
+
console.log(`No sockets found for user ${userIdStr}`);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
let sent = false;
|
|
121
126
|
for (const ws of sockets) {
|
|
122
|
-
if (ws.readyState === 1 && ws.moduleName
|
|
127
|
+
if (ws.readyState === 1 && ws.subscriptions.has(moduleName)) {
|
|
123
128
|
ws.send(JSON.stringify(data));
|
|
129
|
+
sent = true;
|
|
124
130
|
}
|
|
125
131
|
}
|
|
132
|
+
return sent;
|
|
126
133
|
}
|
|
127
134
|
broadcastToModule(moduleName, data) {
|
|
128
135
|
for (const ws of this.wss.clients) {
|
|
129
|
-
if (ws.readyState === 1 && ws.moduleName
|
|
136
|
+
if (ws.readyState === 1 && ws.subscriptions.has(moduleName)) {
|
|
130
137
|
ws.send(JSON.stringify(data));
|
|
131
138
|
}
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
broadcastToModuleWithFilter(moduleName, filterFn, data) {
|
|
142
|
+
this.userConnections;
|
|
135
143
|
for (const ws of this.wss.clients) {
|
|
136
144
|
if (ws.readyState !== 1) continue;
|
|
137
|
-
if (ws.moduleName
|
|
145
|
+
if (!ws.subscriptions.has(moduleName)) continue;
|
|
138
146
|
if (!filterFn(ws)) continue;
|
|
139
147
|
ws.send(JSON.stringify(data));
|
|
140
148
|
}
|