Sha256: 51ddeb71d1238234347a5dd4f8b8c2dec132e26cb1424eae3260f51b66ee34a2

Contents?: true

Size: 803 Bytes

Versions: 51

Compression:

Stored size: 803 Bytes

Contents

import { createConsumer } from "@rails/actioncable";
import { debounce } from "throttle-debounce";
import { log } from "../plugins/logger";

export default function socket(endpoint) {
  const uid = (Date.now() + ((Math.random() * 100) | 0)).toString();
  const consumer = createConsumer(`${endpoint}?uid=${uid}`);
  return {
    addListener(channel, callback) {
      consumer.subscriptions.create(channel, {
        received: debounce(
          200,
          (data) => {
            log.debug("Lookbook files changed");
            callback(data);
          },
          { atBegin: true }
        ),
        connected() {
          log.info("Lookbook websocket connected");
        },
        disconnected() {
          log.info("Lookbook websocket disconnected");
        },
      });
    },
  };
}

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
lookbook-2.3.4 assets/js/lib/socket.js
lookbook-2.3.3 assets/js/lib/socket.js
lookbook-2.3.2 assets/js/lib/socket.js
lookbook-2.3.0 assets/js/lib/socket.js
lookbook-2.2.2 assets/js/lib/socket.js
lookbook-2.2.1 assets/js/lib/socket.js
lookbook-2.2.0 assets/js/lib/socket.js
lookbook-2.1.1 assets/js/lib/socket.js
lookbook-2.1.0 assets/js/lib/socket.js
lookbook-2.0.5 assets/js/lib/socket.js
lookbook-2.0.4 assets/js/lib/socket.js
lookbook-2.0.3 assets/js/lib/socket.js
lookbook-2.0.2 assets/js/lib/socket.js
lookbook-2.0.1 assets/js/lib/socket.js
lookbook-2.0.0 assets/js/lib/socket.js
lookbook-2.0.0.rc.3 assets/js/lib/socket.js
lookbook-1.5.5 app/assets/lookbook/js/lib/socket.js
lookbook-1.5.4 app/assets/lookbook/js/lib/socket.js
lookbook-2.0.0.rc.2 assets/js/lib/socket.js
lookbook-2.0.0.rc.1 assets/js/lib/socket.js