2017-10-03 23:46:22 +03:00
# janus-plugin-rs
2017-10-26 00:35:21 +03:00
[![Documentation ](https://docs.rs/janus-plugin/badge.svg )](https://docs.rs/janus-plugin/)
[![janus-plugin ](https://img.shields.io/crates/v/janus-plugin.svg )](https://crates.io/crates/janus-plugin)
2017-10-05 02:22:04 +03:00
2018-03-29 00:20:42 +03:00
Library for creating Rust plugins and event handlers for [Janus ](https://janus.conf.meetecho.com/ ). Still moderately unstable.
2017-10-03 23:46:22 +03:00
``` toml
[dependencies]
2021-01-25 11:53:35 +03:00
janus-plugin = "0.13.0"
2017-10-03 23:46:22 +03:00
```
2019-12-10 01:43:45 +03:00
## Compatibility
2021-01-25 11:53:35 +03:00
Currently compatible with Janus versions >= 0.10.9; Janus makes breaking changes relatively frequently to
2019-12-10 01:43:45 +03:00
the plugin API, so expect this library to require updating and recompilation for plugins to continue to work with new
Janus versions.
2017-10-03 23:46:22 +03:00
## Building
2017-10-09 11:28:15 +03:00
Requires the [Jansson ](http://www.digip.org/jansson/ ) native library (Ubuntu: `libjansson-dev` ) to link against; tested as compatible with versions >= 2.5.
2017-10-05 02:42:55 +03:00
2017-10-03 23:46:22 +03:00
```
2017-10-05 02:43:35 +03:00
$ cargo build --all
2017-10-03 23:46:22 +03:00
```
## Testing
```
2017-10-05 02:43:35 +03:00
$ cargo test --all
2017-10-03 23:46:22 +03:00
```
2017-11-11 01:44:55 +03:00
2019-12-10 01:58:24 +03:00
## Basic usage
Janus expects to dynamically link plugins as libraries and then call a `create` function on them to return a
`janus_plugin` struct, which has a variety of function pointers that Janus will call when plugin-related events in the
core happen.
These bindings provide a `build_plugin!` macro that accepts as arguments plugin metadata and a set of (`extern C`) Rust
functions, producing a Rust version of the `janus_plugin` struct, and an `export_plugin!` macro that defines the
`create` function to return that struct. So to implement a plugin, you should write some handler functions, and then use
those macros like so:
``` Rust
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.
2021-01-25 11:53:35 +03:00
api_version: 15,
2019-12-10 01:58:24 +03:00
// 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);
```
2017-11-11 01:44:55 +03:00
## Examples
Here are some projects which are using these bindings:
2017-12-07 04:11:17 +03:00
* https://github.com/mozilla/janus-plugin-sfu
2017-11-11 01:44:55 +03:00
* https://github.com/ivanovaleksey/janus-echotest-rs
2021-01-25 11:53:35 +03:00
* https://github.com/netology-group/janus-conference/