8个版本 (破坏性)

0.8.0 2021年1月25日
0.7.0 2020年4月1日
0.6.0 2018年3月28日
0.5.0 2017年12月7日
0.1.0 2017年10月25日

#176 in 视频

每月21次下载
用于 janus-plugin

MPL-2.0 许可证

24KB
439

janus-plugin-rs

Documentation janus-plugin

用于创建Janus插件和事件处理器的Rust库。仍然相对不稳定。

[dependencies]
janus-plugin = "0.13.0"

兼容性

目前与Janus版本 >= 0.10.9 兼容;Janus相对频繁地对插件API进行破坏性更改,因此预计此库需要更新和重新编译才能与新的Janus版本一起工作。

构建

需要Jansson本地库(Ubuntu: libjansson-dev)进行链接;已测试与 >= 2.5 版本兼容。

$ cargo build --all

测试

$ cargo test --all

基本用法

Janus期望将插件作为库动态链接,然后调用它们的create函数以返回一个janus_plugin结构,该结构具有多种函数指针,当核心发生与插件相关的事件时,Janus将调用这些函数指针。

这些绑定提供了一个接受插件元数据和一组(extern C)Rust函数作为参数的build_plugin!宏,生成janus_plugin结构的Rust版本,以及一个定义create函数以返回该结构的export_plugin!宏。因此,要实现插件,您应编写一些处理函数,然后像这样使用这些宏

use std::os::raw::c_char;

// helper macro for generating C-style strings from Rust string literals at compile time
macro_rules! c_str {
    ($lit:expr) => {
        unsafe {
            std::ffi::CStr::from_ptr(concat!($lit, "\0").as_ptr() as *const c_char)
        }
    }
}

extern "C" fn init(callbacks: *mut PluginCallbacks, config_path: *const c_char) -> c_int {
    janus_info!("Plugin loaded!");
    0
}

extern "C" fn destroy() {
    janus_info!("Plugin destroyed!");
}

// ...other handlers omitted: see
// https://janus.conf.meetecho.com/docs/plugin_8h.html#details

const PLUGIN: Plugin = build_plugin!(
    LibraryMetadata {
        // The Janus plugin API version. The version compiled into the plugin
        // must be identical to the version in the Janus which loads the plugin.
        api_version: 15,
        // Incrementing plugin version number for your own use.
        version: 1,
        // Human-readable metadata which Janus can query.
        name: c_str!("My plugin name"),
        package: c_str!("My plugin package name"),
        version_str: c_str!(env!("CARGO_PKG_VERSION")),
        description: c_str!(env!("CARGO_PKG_DESCRIPTION")),
        author: c_str!(env!("CARGO_PKG_AUTHORS")),
    },
    init,
    destroy,
    // ...other handlers omitted: see
    // https://janus.conf.meetecho.com/docs/plugin_8h.html#details
);

export_plugin!(&PLUGIN);

示例

以下是一些使用这些绑定的一些项目

依赖关系

~315–630KB
~14K SLoC