Commit 599da194 authored by Ashim Shrestha's avatar Ashim Shrestha
Browse files

remove listner and socket reconnect

parent 827f1b16
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
node_modules
dist
 No newline at end of file
# dist
 No newline at end of file

dist/mbroadcast.js

0 → 100644
+3 −0

File added.

Preview size limit exceeded, changes collapsed.

dist/mbroadcast.js.map

0 → 100644
+7 −0

File added.

Preview size limit exceeded, changes collapsed.

+3 −3
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/py-package/masonite-broadcast-client"
    "url": "https://git.kodiary.com/ashim/massonite-socket-client.git"
  },
  "keywords": [
    "masonite",
@@ -23,9 +23,9 @@
  ],
  "author": "Yubaraj Shrestha <companion.krish@gmail.com> (https://py-package.com)",
  "bugs": {
    "url": "https://github.com/py-package/masonite-broadcast-client/issues"
    "url": "https://git.kodiary.com/ashim/massonite-socket-client.git/issues"
  },
  "homepage": "https://github.com/py-package/masonite-broadcast-client",
  "homepage": "https://git.kodiary.com/ashim/massonite-socket-client.git",
  "module": "dist/mbroadcast.js",
  "devDependencies": {
    "eslint": "^8.21.0"
+117 −100
Original line number Diff line number Diff line
import { io } from "socket.io-client";
import SocketChannel from './channels/socket-channel';
import SocketChannel from "./channels/socket-channel";

class MasoniteBroadcastClient {
  config: any;
@@ -8,18 +8,29 @@ class MasoniteBroadcastClient {

  constructor(config: Config) {
    if (!config.url) {
            throw new Error('url is required');
      throw new Error("url is required");
    }
    this.config = config;
    this.#connect();
  }

  setExtra(value, callback) {
        this.socket.emit("setExtra", {
            extra: value
        }, (value) => {
    this.socket.emit(
      "setExtra",
      {
        extra: value,
      },
      (value) => {
        callback(value);
        });
      }
    );
  }

  reconnect() {
    this.socket = undefined;
    this.channels = {};
    this.#connect();
    // this.socket.emit("reconnect");
  }

  #connect() {
@@ -29,7 +40,7 @@ class MasoniteBroadcastClient {
      autoConnect: false,
    });

        const sessionID = localStorage.getItem('sessionID');
    const sessionID = localStorage.getItem("sessionID");
    if (sessionID) {
      this.socket.auth = { sessionID };
      this.socket.connect();
@@ -40,8 +51,8 @@ class MasoniteBroadcastClient {
    /** Handling Events */
    this.socket.on("session", ({ userID, sessionID }) => {
      this.socket.auth = { sessionID };
            localStorage.setItem('sessionID', sessionID);
            this.socket.userID = userID;
      localStorage.setItem("sessionID", sessionID);
      this.socket.userID = 3;
      this.socket.connect();
    });

@@ -60,7 +71,7 @@ class MasoniteBroadcastClient {
  #reconnect() {
    Object.values(this.channels).forEach((channel) => {
      channel.subscribe();
        })
    });
  }

  #disconnect() {
@@ -95,6 +106,12 @@ class MasoniteBroadcastClient {
    this.socket.on(event, callback);
  }

  stopListening(event: String = "") {
    if (event.length) this.socket.removeAllListeners(event);
    else this.socket.removeAllListeners();
    return this;
  }

  listenForWhisper(event, callback) {
    this.socket.on(`whisper:${event}`, callback);
  }
Loading