davidstump / SwiftPhoenixClient

Connect your Phoenix and iOS applications through WebSockets!
MIT License
507 stars 147 forks source link

2.2.0 doesn't call receive callbacks #205

Closed ruslandoga closed 2 years ago

ruslandoga commented 2 years ago
import UIKit
import SwiftPhoenixClient

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
  }

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    let socket = Socket("http://localhost:4000/socket", params: ["token": "123"])
    socket.connect()

    let channel = socket.channel("chat:123")
    channel.join().receive("ok") { message in
      print("received ok \(message)")
    }.receive("error") { message in
      print("received error \(message)")
    }.receive("timeout") { message in
      print("received timeout \(message)")
    }
  }
}

receive callbacks are not executed, nothing is printed in the console

Logs from server:

iex(5)> connect_info: %{
  peer_data: %{address: {127, 0, 0, 1}, port: 49471, ssl_cert: nil},
  x_headers: []
}
[info] CONNECTED TO SWeb.UserSocket in 2ms
  Transport: :websocket
  Serializer: Phoenix.Socket.V1.JSONSerializer
  Parameters: %{"token" => "123"}
[info] JOINED chat:123 in 18µs
  Parameters: %{}
ruslandoga commented 2 years ago

Repro client: https://github.com/ruslandoga/phx-socket (commit)

Repro server: https://github.com/ruslandoga/phx-socket-server (commit)

ruslandoga commented 2 years ago

version 2.1.0 works,

received ok SwiftPhoenixClient.Message

is printed in the console