0

My controller:

import { Controller } from "@hotwired/stimulus";
import consumer from "channels/consumer";

export default class extends Controller {
  static targets = ["users", "roomId"];

  connect() {
    console.log("");
    this.subscription = consumer.subscriptions.find("RoomChannel");
  }

};

My room_channel.js:

import consumer from "channels/consumer"

consumer.subscriptions.create("RoomChannel", {



  connected() {
    // Called when the subscription is ready for use on the server
    console.log("Connected to rooms channel");

  }

},

My HTML:

<div data-controller="room">
   <!-- get data -->
</div>

Result in console.log():

Error connecting controller

TypeError: consumer.subscriptions.find is not a function

What am I doing wrong here?

Wordica
  • 2,427
  • 3
  • 31
  • 51

1 Answers1

1

Actually, consumer.subscriptions doesn't have the 'find' method, but it has several different methods: ['create', 'add', 'remove', 'reject', 'forget', 'findAll', 'reload', 'notifyAll', 'notify', 'subscribe', 'confirmSubscription', 'sendCommand']

You probably wanted to use the method findAll, but don't forget that this method accepts full channel identifier

this.subscription = consumer.subscriptions.findAll(
      '{"channel":"RoomChannel","room":"Best Room"}')
sapiv71097
  • 108
  • 3