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-1.3.3 app/assets/lookbook/js/lib/socket.js
lookbook-1.3.1 app/assets/lookbook/js/lib/socket.js
lookbook-1.3.0 app/assets/lookbook/js/lib/socket.js
lookbook-1.2.1 app/assets/lookbook/js/lib/socket.js
lookbook-1.2.0 app/assets/lookbook/js/lib/socket.js
lookbook-1.1.1 app/assets/lookbook/js/lib/socket.js
lookbook-1.1.0 app/assets/lookbook/js/lib/socket.js
lookbook-1.0.8 app/assets/lookbook/js/lib/socket.js
lookbook-1.0.7 app/assets/lookbook/js/lib/socket.js
lookbook-1.0.6 app/assets/lookbook/js/lib/socket.js
lookbook-1.0.5 app/assets/lookbook/js/lib/socket.js