nuxt-visitors 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Nuxt Active Users
1
+ # Nuxt Visitors 👀
2
2
 
3
3
  <!-- automd:badges color=black license provider=shields name=nuxt-visitors -->
4
4
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-visitors",
3
3
  "configKey": "visitors",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -10,7 +10,7 @@ const module = defineNuxtModule({
10
10
  addImportsDir(resolver.resolve("./runtime/app/composables"));
11
11
  addServerHandler({
12
12
  route: "/.nuxt-visitors/ws",
13
- handler: resolver.resolve("./runtime/server/routes/visitors.ts")
13
+ handler: resolver.resolve("./runtime/server/routes/visitors")
14
14
  });
15
15
  }
16
16
  });
@@ -16,9 +16,9 @@
16
16
  * - reconnect: () => void - Function to manually reconnect
17
17
  */
18
18
  export declare function useVisitors(): {
19
- visitors: any;
20
- isLoading: any;
21
- error: any;
22
- isConnected: any;
19
+ visitors: import("vue").Ref<number, number>;
20
+ isLoading: import("vue").Ref<boolean, boolean>;
21
+ error: import("vue").Ref<string | null, string | null>;
22
+ isConnected: import("vue").Ref<boolean, boolean>;
23
23
  reconnect: () => void;
24
24
  };
@@ -1,3 +1,5 @@
1
+ import { ref, onMounted, onBeforeUnmount } from "vue";
2
+ import { useState } from "#imports";
1
3
  export function useVisitors() {
2
4
  const visitors = useState("visitors", () => 0);
3
5
  const isLoading = ref(true);
@@ -20,10 +22,11 @@ export function useVisitors() {
20
22
  isConnected.value = false;
21
23
  isLoading.value = false;
22
24
  };
23
- const handleMessage = (event) => {
25
+ const handleMessage = async (event) => {
24
26
  if (!isMounted.value) return;
25
27
  try {
26
- const visitorCount = parseInt(event.data, 10);
28
+ const data = typeof event.data === "string" ? event.data : await event.data.text();
29
+ const visitorCount = parseInt(data, 10);
27
30
  if (!isNaN(visitorCount) && visitorCount >= 0) {
28
31
  visitors.value = visitorCount;
29
32
  } else {
@@ -1,2 +1,2 @@
1
- declare const _default: any;
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, never>;
2
2
  export default _default;
@@ -1,3 +1,4 @@
1
+ import { defineWebSocketHandler } from "h3";
1
2
  export default defineWebSocketHandler({
2
3
  open(peer) {
3
4
  peer.subscribe("nuxt-visitors");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-visitors",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Add real-time visitor tracking to your Nuxt app with one line of code. WebSocket made easy",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -31,6 +31,7 @@
31
31
  "dev:build": "nuxi build playground",
32
32
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
33
33
  "release": "npm run lint && npm run test && npm run prepack",
34
+ "typecheck": "tsc --noEmit",
34
35
  "lint": "eslint .",
35
36
  "lint:fix": "eslint --fix .",
36
37
  "test": "vitest run",
@@ -38,23 +39,22 @@
38
39
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
39
40
  },
40
41
  "dependencies": {
41
- "@nuxt/kit": "^3.15.3"
42
+ "@nuxt/kit": "3.15.2"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@hrcd/eslint-config": "^2.1.1",
45
46
  "@nuxt/devtools": "^1.7.0",
46
47
  "@nuxt/eslint-config": "^0.7.5",
47
48
  "@nuxt/module-builder": "^0.8.4",
48
- "@nuxt/schema": "^3.15.3",
49
+ "@nuxt/schema": "3.15.2",
49
50
  "@nuxt/test-utils": "^3.15.4",
50
51
  "@types/node": "latest",
51
- "changelogen": "^0.5.7",
52
+ "automd": "^0.3.12",
52
53
  "eslint": "^9.19.0",
53
- "nuxt": "3.15.3",
54
- "typescript": "5.7.2",
54
+ "nuxt": "3.15.2",
55
+ "typescript": "5.6.3",
55
56
  "vitest": "^3.0.4",
56
- "vue-tsc": "^2.2.0",
57
- "automd": "^0.3.12"
57
+ "vue-tsc": "^2.2.0"
58
58
  },
59
- "packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0"
59
+ "packageManager": "pnpm@9.15.4"
60
60
  }