kesha-antonov / react-native-action-cable

Use Rails 5+ ActionCable channels with React Native for realtime magic.
https://www.npmjs.com/package/@kesha-antonov/react-native-action-cable
MIT License
57 stars 24 forks source link

Not receiving data! #3

Closed dcalixto closed 4 years ago

dcalixto commented 4 years ago

Hello! @kesha-antonov thank you for the package, but is not receiving or something that i did wrong?

here is the configuration:

createSocket() {
    let actionCable = ActionCable.createConsumer("ws://localhost:3000/cable");

    this.chats = actionCable.subscriptions.create(
      {
        channel: "NotificationChannel"
      },
      {
        connected: () => {},
        received: data => {

          this.fetchNewNotification(); 
        }
      }
    );
  }
kesha-antonov commented 4 years ago

Hey @dcalixto

Can you post please app/channels/notifications_channel.rb?

dcalixto commented 4 years ago

Sure @kesha-antonov !

class NotificationChannel < ApplicationCable::Channel
  def subscribed
    stream_from "notification_channel"
  end

  def unsubscribed
    # Any cleanup needed when channel is unsubscribed
  end
end
kesha-antonov commented 4 years ago

Try this

createSocket() {
  const actionCable = ActionCable.createConsumer("ws://localhost:3000/cable");
  const cable = new Cable({})

  const channel = cable.setChannel(
    `notification_channel`
    actionCable.subscriptions.create({
      channel: 'NotificationChannel'
    })
  )

  channel
    .on( 'connected', () => { console.log('connected') } )
    .on( 'received', data => { 
      console.log('received', data) 
      this.fetchNewNotification()
    } )
   )
 }
dcalixto commented 4 years ago

@kesha-antonov sorry, but still not fetching or receiving data! Even in the logs shows nothing!

dcalixto commented 4 years ago

@kesha-antonov is anything that i can help or try?

kesha-antonov commented 4 years ago

Try

ActionCable.startDebugging()

to see the logs

kesha-antonov commented 4 years ago

And any output in rails server console?

dcalixto commented 4 years ago

@kesha-antonov just this! cable

kesha-antonov commented 4 years ago

@kesha-antonov just this! cable

Seems like all is ok - ws connected .on( 'connected', () => { console.log('connected') } ) should work

I can create example example with rails app and double check that everything is fine but only on weekend

dcalixto commented 4 years ago

@kesha-antonov , great! :)

kesha-antonov commented 4 years ago

Hey! @dcalixto Checkout example here https://github.com/kesha-antonov/react-native-action-cable/issues/5 Still didn't have time to implement my own

dcalixto commented 4 years ago

hey @kesha-antonov , my fault sorry for the delay! is working. i just forget to add the data.notifications on set state of this.fetchNewNotification() function!

thank you very much for your support and for the package :)

AftabUfaq commented 3 years ago

how to use this in a functional component