GetStream / stream-js

JS / Browser Client - Build Activity Feeds & Streams with GetStream.io
https://getstream.io
BSD 3-Clause "New" or "Revised" License
329 stars 110 forks source link

StreamFeed.subscribe() does not return a Faye Subscription. #607

Open skam22 opened 6 months ago

skam22 commented 6 months ago

export enum StreamFeedGroups {
  user = 'user',
  timeline = 'timeline',
  timeline_aggregated = 'timeline_aggregated',
  notification = 'notification',
}

const activityClient = connect(
  Config.STREAM_API_KEY,
  null,
  Config.STREAM_APP_ID,
);

const timelineFeed = activityClient.feed(
  StreamFeedGroups.timeline,
  userId,  // string
  userToken, // string
),

const Component = () => {

  useEffect(() => {
    let subscription: Subscription | null = null;

    timelineFeed.subscribe((data) => {
      console.log('New timeline data received':, data);
    }).then((fayeSubscription: Subscription) => {

      subscription = fayeSubscription;
      console.log('Timeline listener established', subscription);

        // expected object:
           type Subscription = {
             cancel: () => void;
           };
        // actual:
           undefined

    }).catch(error => {
      if (error instanceof Error) {
        console.error('Error setting up timeline listener', error)
      }
    });

    return () => {
      subscription?.cancel();
      subscription = null;
    }
  },[])

  return (
    ...
  )
}