@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.
Files changed (135) hide show
  1. package/dist/{Media-DwVcRIAX.mjs → Media-C4Ges_Sd.mjs} +1 -1
  2. package/dist/{Media-DCGbUujy.js → Media-CR0V1zvB.js} +1 -1
  3. package/dist/chats.server.js +14 -13
  4. package/dist/chats.server.mjs +14 -13
  5. package/dist/globals.server.js +20 -12
  6. package/dist/globals.server.mjs +20 -12
  7. package/dist/{main-DEHjtgLs.mjs → main-CTcal9qN.mjs} +900 -884
  8. package/dist/{main-UVdexuMN.js → main-CsZAG5Wz.js} +5 -5
  9. package/dist/martyrs/src/components/Block/Block.vue.cjs +1 -1
  10. package/dist/martyrs/src/components/Block/Block.vue.js +1 -1
  11. package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.cjs → SelectMulti.vue.cjs} +2 -2
  12. package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.js.map → SelectMulti.vue.cjs.map} +1 -1
  13. package/dist/martyrs/src/components/SelectMulti/{SelectMulti.vue2.js → SelectMulti.vue.js} +2 -2
  14. package/dist/martyrs/src/components/SelectMulti/SelectMulti.vue.js.map +1 -0
  15. package/dist/martyrs/src/components/Tooltip/{Tooltip.vue.cjs → Tooltip.vue2.cjs} +2 -2
  16. package/dist/martyrs/src/components/Tooltip/Tooltip.vue2.cjs.map +1 -0
  17. package/dist/martyrs/src/components/Tooltip/{Tooltip.vue.js → Tooltip.vue2.js} +2 -2
  18. package/dist/martyrs/src/components/Tooltip/{Tooltip.vue.cjs.map → Tooltip.vue2.js.map} +1 -1
  19. package/dist/martyrs/src/modules/backoffice/components/partials/Sidebar.vue.cjs +1 -1
  20. package/dist/martyrs/src/modules/backoffice/components/partials/Sidebar.vue.js +1 -1
  21. package/dist/martyrs/src/modules/chats/store/chat.store.cjs +47 -16
  22. package/dist/martyrs/src/modules/chats/store/chat.store.cjs.map +1 -1
  23. package/dist/martyrs/src/modules/chats/store/chat.store.js +47 -16
  24. package/dist/martyrs/src/modules/chats/store/chat.store.js.map +1 -1
  25. package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.cjs +1 -1
  26. package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.cjs.map +1 -1
  27. package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.js +1 -1
  28. package/dist/martyrs/src/modules/community/components/blocks/CardBlogpost.vue.js.map +1 -1
  29. package/dist/martyrs/src/modules/community/components/pages/Blog.vue.cjs +1 -1
  30. package/dist/martyrs/src/modules/community/components/pages/Blog.vue.cjs.map +1 -1
  31. package/dist/martyrs/src/modules/community/components/pages/Blog.vue.js +1 -1
  32. package/dist/martyrs/src/modules/community/components/pages/Blog.vue.js.map +1 -1
  33. package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.cjs +4 -1
  34. package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.cjs.map +1 -1
  35. package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.js +4 -1
  36. package/dist/martyrs/src/modules/community/components/pages/BlogPost.vue.js.map +1 -1
  37. package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.cjs +3 -3
  38. package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.cjs.map +1 -1
  39. package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.js +3 -3
  40. package/dist/martyrs/src/modules/community/components/pages/CreateBlogPost.vue.js.map +1 -1
  41. package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.cjs +1 -1
  42. package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.cjs.map +1 -1
  43. package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.js +1 -1
  44. package/dist/martyrs/src/modules/constructor/components/elements/VideoPlayer.vue.js.map +1 -1
  45. package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.cjs +9 -9
  46. package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.cjs.map +1 -1
  47. package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.js +9 -9
  48. package/dist/martyrs/src/modules/constructor/components/sections/Constructor.vue.js.map +1 -1
  49. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.cjs +2 -2
  50. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.cjs.map +1 -1
  51. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.js +2 -2
  52. package/dist/martyrs/src/modules/events/components/pages/EditEvent.vue.js.map +1 -1
  53. package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.cjs +1 -1
  54. package/dist/martyrs/src/modules/gallery/components/sections/BackofficeGallery.vue.js +1 -1
  55. package/dist/martyrs/src/modules/globals/globals.client.cjs +0 -9
  56. package/dist/martyrs/src/modules/globals/globals.client.cjs.map +1 -1
  57. package/dist/martyrs/src/modules/globals/globals.client.js +0 -9
  58. package/dist/martyrs/src/modules/globals/globals.client.js.map +1 -1
  59. package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.cjs +40 -97
  60. package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.cjs.map +1 -1
  61. package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.js +40 -97
  62. package/dist/martyrs/src/modules/globals/views/classes/globals.websocket.js.map +1 -1
  63. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.cjs +1 -1
  64. package/dist/martyrs/src/modules/globals/views/components/blocks/CardHeader.vue.js +1 -1
  65. package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.cjs +1 -1
  66. package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.cjs.map +1 -1
  67. package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.js +1 -1
  68. package/dist/martyrs/src/modules/icons/skeletons/SkeletonBlogpost.vue.js.map +1 -1
  69. package/dist/martyrs/src/modules/notifications/notifications.client.cjs +35 -9
  70. package/dist/martyrs/src/modules/notifications/notifications.client.cjs.map +1 -1
  71. package/dist/martyrs/src/modules/notifications/notifications.client.js +35 -9
  72. package/dist/martyrs/src/modules/notifications/notifications.client.js.map +1 -1
  73. package/dist/martyrs/src/modules/orders/components/blocks/CardOrderUser.vue.cjs +1 -1
  74. package/dist/martyrs/src/modules/orders/components/blocks/CardOrderUser.vue.js +1 -1
  75. package/dist/martyrs/src/modules/orders/components/pages/OrderBackoffice.vue.cjs +1 -1
  76. package/dist/martyrs/src/modules/orders/components/pages/OrderBackoffice.vue.js +1 -1
  77. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs +7 -7
  78. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.cjs.map +1 -1
  79. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js +8 -8
  80. package/dist/martyrs/src/modules/orders/components/pages/OrderCreate.vue.js.map +1 -1
  81. package/dist/martyrs/src/modules/orders/components/pages/OrderCreateBackoffice.vue.cjs +1 -1
  82. package/dist/martyrs/src/modules/orders/components/pages/OrderCreateBackoffice.vue.js +1 -1
  83. package/dist/martyrs/src/modules/organizations/components/pages/Members.vue.cjs +1 -1
  84. package/dist/martyrs/src/modules/organizations/components/pages/Members.vue.js +1 -1
  85. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationBackoffice.vue.cjs +1 -1
  86. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationBackoffice.vue.js +1 -1
  87. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationEdit.vue.cjs +1 -1
  88. package/dist/martyrs/src/modules/organizations/components/pages/OrganizationEdit.vue.js +1 -1
  89. package/dist/martyrs/src/modules/pages/views/components/pages/PageEdit.vue.cjs +1 -1
  90. package/dist/martyrs/src/modules/pages/views/components/pages/PageEdit.vue.js +1 -1
  91. package/dist/martyrs/src/modules/products/components/blocks/CardPosition.vue.cjs +1 -1
  92. package/dist/martyrs/src/modules/products/components/blocks/CardPosition.vue.js +1 -1
  93. package/dist/martyrs/src/modules/products/components/pages/EditLeftover.vue.cjs +1 -1
  94. package/dist/martyrs/src/modules/products/components/pages/EditLeftover.vue.js +1 -1
  95. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs +6 -5
  96. package/dist/martyrs/src/modules/products/components/pages/Product.vue.cjs.map +1 -1
  97. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js +6 -5
  98. package/dist/martyrs/src/modules/products/components/pages/Product.vue.js.map +1 -1
  99. package/dist/martyrs/src/modules/rents/views/components/pages/RentsEdit.vue.cjs +1 -1
  100. package/dist/martyrs/src/modules/rents/views/components/pages/RentsEdit.vue.js +1 -1
  101. package/dist/martyrs.cjs.js +1 -1
  102. package/dist/martyrs.css +1 -1
  103. package/dist/martyrs.es.js +1 -1
  104. package/dist/notifications.server.js +69 -13
  105. package/dist/notifications.server.mjs +69 -13
  106. package/dist/orders.server.js +1 -0
  107. package/dist/orders.server.mjs +1 -0
  108. package/package.json +1 -1
  109. package/src/components/Shader/Shader.vue +44 -25
  110. package/src/modules/chats/routes/chats.routes.js +21 -17
  111. package/src/modules/chats/store/chat.store.js +55 -28
  112. package/src/modules/community/components/blocks/CardBlogpost.vue +1 -1
  113. package/src/modules/community/components/pages/Blog.vue +1 -1
  114. package/src/modules/community/components/pages/BlogPost.vue +1 -0
  115. package/src/modules/community/components/pages/CreateBlogPost.vue +3 -3
  116. package/src/modules/constructor/components/elements/VideoPlayer.vue +1 -1
  117. package/src/modules/constructor/components/sections/Constructor.vue +9 -9
  118. package/src/modules/events/components/pages/EditEvent.vue +1 -1
  119. package/src/modules/globals/controllers/classes/globals.websocket.js +29 -21
  120. package/src/modules/globals/globals.client.js +0 -12
  121. package/src/modules/globals/views/classes/globals.websocket.js +46 -146
  122. package/src/modules/icons/skeletons/SkeletonBlogpost.vue +2 -2
  123. package/src/modules/notifications/controllers/notifications.controller.js +2 -2
  124. package/src/modules/notifications/notifications.client.js +57 -19
  125. package/src/modules/notifications/notifications.server.js +3 -1
  126. package/src/modules/notifications/routes/notifications.routes.js +2 -2
  127. package/src/modules/notifications/services/notification.service.js +34 -15
  128. package/src/modules/notifications/services/web-push.service.js +7 -6
  129. package/src/modules/orders/components/pages/OrderCreate.vue +3 -4
  130. package/src/modules/orders/controllers/orders.controller.js +2 -0
  131. package/src/modules/products/components/pages/Product.vue +7 -6
  132. package/dist/martyrs/src/components/SelectMulti/SelectMulti.vue2.cjs.map +0 -1
  133. package/dist/martyrs/src/components/Tooltip/Tooltip.vue.js.map +0 -1
  134. package/src/modules/notifications/notifications2.client.js +0 -256
  135. 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-DEHjtgLs.mjs";
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-UVdexuMN.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;
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;
@@ -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
- ws.chatId = msg.chatId;
51
- } else {
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
- "chat",
55
- (client) => client.chatId === msg.chatId,
56
- savedMessage
57
- );
56
+ wss.broadcastToModuleWithFilter("chat", (client) => {
57
+ return client.activeChats?.has(msg.chatId);
58
+ }, savedMessage);
58
59
  }
59
60
  });
60
- app.use(function(req, res, next) {
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
  }
@@ -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
- ws.chatId = msg.chatId;
50
- } else {
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
- "chat",
54
- (client) => client.chatId === msg.chatId,
55
- savedMessage
56
- );
55
+ wss.broadcastToModuleWithFilter("chat", (client) => {
56
+ return client.activeChats?.has(msg.chatId);
57
+ }, savedMessage);
57
58
  }
58
59
  });
59
- app.use(function(req, res, next) {
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
  }
@@ -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
- console.log(msg);
76
- const moduleName = ws.moduleName || msg.module;
77
- console.log("module name is,", moduleName);
78
- console.log("modules is,", this.modules);
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((cookie) => cookie.startsWith("user="));
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 sockets = this.userConnections.get(userId);
121
- if (!sockets) return;
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 === 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 === 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 !== moduleName) continue;
146
+ if (!ws.subscriptions.has(moduleName)) continue;
139
147
  if (!filterFn(ws)) continue;
140
148
  ws.send(JSON.stringify(data));
141
149
  }
@@ -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
- console.log(msg);
75
- const moduleName = ws.moduleName || msg.module;
76
- console.log("module name is,", moduleName);
77
- console.log("modules is,", this.modules);
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((cookie) => cookie.startsWith("user="));
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 sockets = this.userConnections.get(userId);
120
- if (!sockets) return;
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 === 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 === 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 !== moduleName) continue;
145
+ if (!ws.subscriptions.has(moduleName)) continue;
138
146
  if (!filterFn(ws)) continue;
139
147
  ws.send(JSON.stringify(data));
140
148
  }