GetStream / stream-swift

Swift client for Stream API
https://getstream.io
BSD 3-Clause "New" or "Revised" License
35 stars 26 forks source link

Usage example for subscribing to feed for realtime updates? Any low level socket reference docs? #6

Closed rromanchuk closed 5 years ago

rromanchuk commented 5 years ago

Looks like there may have been some drift, as signatures and return types have changed and the following snippet won't compile.

https://github.com/GetStream/stream-swift/wiki/Realtime-updates

Do you have any recent usage snippets? I've poked around the source but I might be missing something. Is it possible to just get these message payloads without needing to conform to an activity type? Also, are there any low level connection reference documentation (so I can avoid digging through the sdks) for real time? Since my scope is very narrow i'd prefer to establish these sockets myself in exchange for the users jwt token.

I'll dig into the sdks, but if you have any hints would be great. It might even make more sense for me to create a new channel between my own client/server socket and just push out those messages myself when I get them upstream from my firehose.

buh commented 5 years ago

Thanks for your questions!

  1. I updated the snippet and it should compile now.
  2. The activity type needed for decode the data. If you want to decode the web socket response data by yourself you can do that, but for now the Faye client is internal, so you need to configure it before to use:
    
    Faye.Client.config = .init(url: URL(string: "wss://faye.getstream.io/faye")!)
    let notificationChannelName = "site-\(client.appId)-feed-\(feedId.together)"
    let channel = Channel(notificationChannelName, client: Client.fayeClient) { [weak self] data  in
    // Parse data here.
    }

channel.ext = ["api_key": client.apiKey, "signature": client.token, "user_id": notificationChannelName]

do { try Client.fayeClient.subscribe(to: channel) } catch { // Handle errors here. }

// Keep the subscription object, until you need it and then set it to nil. var subscription: SubscribedChannel? = SubscribedChannel(channel)


It's from the current implementation: https://github.com/GetStream/stream-swift/blob/master/Sources/Faye/Feed%2BFaye.swift

If you'll have other questions, let me know.
rromanchuk commented 5 years ago

@buh thanks! this is perfect