Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { io } from "socket.io-client";
- // Connect to the shelf socket namespace
- const socket = io("https://your-server-url", {
- // Add auth headers or namespace config if needed
- });
- // Connection established
- socket.on("connect", () => {
- console.log("🔗 Connected to shelf socket:", socket.id);
- });
- // Shelf state update event (specific product)
- socket.on("shelf-state-update", (response) => {
- if (response.success) {
- const { _id, shelfState, weight } = response.product;
- console.log("Shelf product updated:", {
- productId: _id,
- state: shelfState,
- weight: weight,
- });
- // Update UI with the new shelf product state
- } else {
- console.error("Shelf update failed:", response);
- }
- });
- // All products state counts update (new event)
- socket.on("product-states-update", (response) => {
- if (response.success) {
- console.log("Updated product state counts:", response.stateCounts);
- // response.stateCounts example:
- // { available: 4, outOfStock: 2, lowStock: 3 }
- // Update your dashboard/statistics panel accordingly
- } else {
- console.error("Failed to receive product state counts:", response);
- }
- });
- // Handle socket errors
- socket.on("error", (error) => {
- console.error("Socket error:", error.message || error);
- });
- // Handle disconnect
- socket.on("disconnect", () => {
- console.log("Disconnected from shelf socket");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement