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

feat: add minimal support for streaming plugin #132

Merged

Conversation

fcx-mrogez
Copy link
Contributor

This PR add minimal support for the streaming plugin API.

We currently only support:

  • create an RTP mountpoint LIVE,ONDEMAND or RTSP are not yet supported
  • list available mountpoints
  • destroy mountpoint

I tried to follow what was done in other plugins but since I'm no expert in rust, and janus API may be sometime complicate to grasp, some things may need some tweaking especially regarding streaming events.
Anyway, I hope you'll find it useful. I'm not sure I'll have more time to allocate to add more features to this plugin (we only use this subset for now), but I'll try to take into account reviews feedback. Thanks for your work on this useful library :)

@Ghamza-Jd
Copy link
Owner

Thanks a lot for your contribution! ⭐

I'll review it this evening

@fcx-mrogez
Copy link
Contributor Author

fcx-mrogez commented Sep 27, 2024

Upon running some more tests I've encountered the following issue :

if I change the port to 5004 in the streaming example and run it, it will fail with a parsing error. This is unexpected. Given the default configuration of the streaming plugin (in the janus docker image) the port 5004 is already attributed to another mountpoint so it fails to create the mountpoint (as expected). But the returned json is :

    {
       "janus": "success",
       "session_id": 2158724686674557,
       "transaction": "nNbmsbj33zLY",
       "sender": 77797716144085,
       "plugindata": {
          "plugin": "janus.plugin.streaming",
          "data": {
             "streaming": "event",
             "error_code": 456,
             "error": "Can't add 'rtp' stream, error creating data source stream"
          }
       }
    }

The problem is the first line : "janus": "success", it should be "janus": "error" so that serde could properly deserialize the response... (see https://github.com/meetecho/janus-gateway/blob/master/src/plugins/janus_streaming.c#L5507)

To me, this looks like an upstream bug, but changing that upstream could be considered a breaking change and therefore not be accepted. What do you think ?

edit: Seems like videoroom is also affected https://github.com/meetecho/janus-gateway/blob/master/src/plugins/janus_videoroom.c#L8287

@Ghamza-Jd
Copy link
Owner

Ghamza-Jd commented Sep 27, 2024

@fcx-mrogez Thanks for finding these out!

I'm thinking of creating a plugin response enum that would parse the error variant.

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)]
#[serde(untagged)]
pub enum PluginResponse<T> {
    Err(ErrorRsp),
    Ok(T),
}

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)]
pub struct ErrorRsp {
    pub error_code: u16,
    pub error: String,
}

Then fallible can parse it

pub async fn create_mountpoint_with_config(
    &self,
    options: StreamingCreateOptions,
    timeout: Duration,
) -> JaResult<MountpointCreatedRsp> {
    tracing::info!(plugin = "streaming", "Sending create");
    let mut message: Value = options.try_into()?;
    message["request"] = "create".into();

    let rsp = self
        .handle
        .send_waiton_rsp::<PluginResponse<MountpointCreatedRsp>>(message, timeout)
        .await?;
    match rsp {
        PluginResponse::Err(err) => Err(JaError::JanusTransport(JaTransportError::JanusError {
            code: err.error_code,
            reason: err.error,
        })),
        PluginResponse::Ok(ok) => Ok(ok),
    }
}

That's the fast answer (although JanusError will be incorrect as we could have same error code for a janus connection and a janus plugin, e.g. JANUS_STREAMING_ERROR_CANT_CREATE 456 for the streaming plugin and JANUS_ERROR_MISSING_MANDATORY_ELEMENT 456 for janus connection)

The long answer is were should we have the error, we could make a JaStreamingError that wraps JaError and custom errors (in this case only the error struct) or a common JaPluginError with JaPluginResult, or changing the upstream (not entirely sure about this approach since this is a plugin specific error so I prefer scoping it in the plugin crate or at the handle level)

I don't mind having a breaking change, since this crate is still in active development.

@Ghamza-Jd
Copy link
Owner

You don't have to worry about the error issue in this PR, we could tackle it in a separate PR, I'm happy to review it regardless of this issue since it's an existing issue

Copy link
Owner

@Ghamza-Jd Ghamza-Jd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice PR ⭐️
It just requires tests on parsing.
It also triggered some design decisions for the lib to make it more robust and more developer friendly, Thanks!

jarust_plugins/src/streaming/events.rs Show resolved Hide resolved
jarust_plugins/src/streaming/msg_options.rs Show resolved Hide resolved
@Ghamza-Jd
Copy link
Owner

I've created a draft PR to tackle this issue, and it turns out changing the upstream solved 2 problems, propagating the error events and the error response.

#133

We can merge your PR first or mine, whichever you prefer!

We currently only support:
* create an RTP mountpoint
  LIVE,ONDEMAND or RTSP are not yet supported
* list available mountpoints
* destroy mountpoint
@fcx-mrogez
Copy link
Contributor Author

Thanks a lot for your review. I've forced pushed the updated branch with event parsing tests as requested.

Copy link
Owner

@Ghamza-Jd Ghamza-Jd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! ⭐️

@Ghamza-Jd Ghamza-Jd merged commit 466b70e into Ghamza-Jd:master Sep 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants