Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phoenix.Channels: Failing to build #17

Open
cplotter opened this issue May 1, 2023 · 5 comments
Open

Phoenix.Channels: Failing to build #17

cplotter opened this issue May 1, 2023 · 5 comments
Assignees

Comments

@cplotter
Copy link

cplotter commented May 1, 2023

I am new to rust and want to play with this library to build a small cli client but I am running into issues building this crate.

cargo run -- "ws://localhost:4000/socket" secret earth
warning: unused manifest key: build
   Compiling phoenix_channels_client v0.1.2
error[E0425]: cannot find function `consume_budget` in module `task`
   --> /home/tru1ock/.cargo/registry/src/index.crates.io-6f17d22bba15001f/phoenix_channels_client-0.1.2/src/channel.rs:519:23
    |
519 |                 task::consume_budget().await
    |                       ^^^^^^^^^^^^^^ not found in `task`
    
    rustc 1.71.0-nightly (9ecda8de8 2023-04-30
    
    [package]
name = "client"
version = "0.1.0"
edition = "2021"


[dependencies]
phoenix_channels_client = { version = "0.1.2", features = ["nightly"] }
clap = { version = "4.2.5", features = ["derive"] }

[build]
rustflags = ["--cfg", "tokio_unstable"]

Any help would be much appreciated!

@KronicDeth
Copy link
Contributor

This library is not production ready yet. I would not recommend using it until we finish the reconnect logic I am currently working on as it won't match the robustness of the JS library that can handle network instability correctly.

@cplotter
Copy link
Author

cplotter commented May 1, 2023

Not building something for production :) I am investigating low level languages like Rust and Zig to build some of my server game logic in. Some actors will be rust or zig processes that is managed by https://github.com/fhunleth/muontrap. This is for a hobby project so I am not concerned with risk and just want to learn.

I have fixed the issue by adding a .cargo folder and adding the build flags there:

[build]
rustflags = ["--cfg", "tokio_unstable"]

Also I got the connection to work by modifying the example script:

#![allow(unused)]

use clap::Parser;
use phoenix_channels_client::Payload;
use phoenix_channels_client::{Client, Config};
use serde_json::json;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::time::Duration;
use url::Url;

#[derive(Parser)]
struct Cli {
    url: String,
    secret: String,
    topic: String,
}

#[tokio::main]
async fn main() {
    let args = Cli::parse();
    let url = Url::parse(&args.url).unwrap();
    // Prepare configuration for the client
    let mut config = Config::new(url).unwrap();
    config.set("shared_secret", args.secret);
    config.set("user_id", "1234");

    // Create a client
    let mut client = Client::new(config).unwrap();

    // Connect the client
    client.connect().await.unwrap();

    // Join a channel with no params and a timeout
    let channel = client
        .join("location:${args.topic}", Some(Duration::from_secs(15)))
        .await
        .unwrap();

    channel
        .on(
            "solar_bodies",
            Box::new(
                move |channel: Arc<phoenix_channels_client::Channel>, payload: &Payload| {
                    println!(
                        "channel received {} from topic '{}'",
                        payload,
                        channel.topic()
                    );
                },
            ),
        )
        .await
        .unwrap();

    // Send a message, waiting for a reply indefinitely
    let result = channel
        .send("marco", json!({ "name": "foo", "message": "hi"}))
        .await
        .unwrap();

    // Send a message, waiting for a reply with an optional timeout
    let result = channel
        .send_with_timeout(
            "marco",
            json!({ "name": "foo", "message": "hello"}),
            Some(Duration::from_secs(5)),
        )
        .await
        .unwrap();

    // Send a message, not waiting for a reply
    let result = channel
        .send_noreply(
            "input_changed",
            json!({
              "throttle": 5,
              "stopping": false,
              "turning": 0.1
            }),
        )
        .await
        .unwrap();

    // Leave the channel
    channel.leave().await;
}

@cplotter
Copy link
Author

cplotter commented May 1, 2023

Final question before I leave you be :) I did not see any reference to presence in the source, is that on the roadmap?

@KronicDeth
Copy link
Contributor

We'll add features as they are needed to support the LiveView Native clients for Swift and Kotlin. As of right now presence is not prioritized unless it is needed for specific demo apps.

@AZholtkevych AZholtkevych changed the title Failing to build Phoenix.Channels: Failing to build Apr 21, 2024
@AZholtkevych
Copy link

@simlay could you please review that, if it is still valid or not

@AZholtkevych AZholtkevych moved this from Todo to On Hold in LiveViewNative Core Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: On Hold
Development

No branches or pull requests

4 participants