{"id":19724237,"url":"https://github.com/kinsleykajiva/janus-server-java-sdk","last_synced_at":"2025-04-29T22:31:19.289Z","repository":{"id":218006337,"uuid":"745169306","full_name":"kinsleykajiva/janus-server-java-sdk","owner":"kinsleykajiva","description":"Janus WebRTC Server SDK for Java (Desktop \u0026 Web-Backend)","archived":false,"fork":false,"pushed_at":"2024-06-28T10:06:36.000Z","size":24632,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T20:04:21.740Z","etag":null,"topics":["devoid","java","webrtc"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kinsleykajiva.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-18T19:21:41.000Z","updated_at":"2024-06-28T10:06:39.000Z","dependencies_parsed_at":"2024-04-22T09:00:14.295Z","dependency_job_id":"c1119f19-fc48-41d9-bcb5-43f99cf7e347","html_url":"https://github.com/kinsleykajiva/janus-server-java-sdk","commit_stats":null,"previous_names":["kinsleykajiva/janus-server-java-sdk"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinsleykajiva%2Fjanus-server-java-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinsleykajiva%2Fjanus-server-java-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinsleykajiva%2Fjanus-server-java-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kinsleykajiva%2Fjanus-server-java-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kinsleykajiva","download_url":"https://codeload.github.com/kinsleykajiva/janus-server-java-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251593023,"owners_count":21614459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devoid","java","webrtc"],"created_at":"2024-11-11T23:24:58.781Z","updated_at":"2025-04-29T22:31:14.280Z","avatar_url":"https://github.com/kinsleykajiva.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Janus WebRTC Server SDK for Java (Desktop \u0026 Web-Backend)\n\n![version](https://img.shields.io/badge/version-0.8.0-blue)\n\nWelcome to the Java implementation of the Janus WebRTC server APIs. This SDK is designed to facilitate interaction with the Janus WebRTC server using both REST API and WebSockets. It is suitable for use in Java applications that require communication with the Janus WebRTC server.\n\nThe APIs methods are documented very much so it's easy to use you would understand how the code works as much no surprises there in behaviour also with respect to the Janus WebRTC server Documentation.\n\n\nThe SDK is divided into two parts:\n\n1. **API Part**: This can be integrated into the back-ends of web frameworks. It is ready for use with Spring Boot, Micronaut, Quakus, Helidon, and more.\n2. **Platform Dependent Part**: This is designed for desktop applications like JavaFX, Swing, AWT, etc. Please note that this part is still under development.\n\n### Disclaimer\n\nThis SDK is continually evolving, and while comprehensive, it may not cover all scenarios. I recognize room for improvement and encourage contributions from the community. \nIf you have suggestions, feel free to create a pull request.\n\n\n## How to use ?\nThere are two way to use this you can :\n- copy all the files from the sdk package and paste into your project folder structure.\n- import the `.jar` from` release/` folder,so the target files is `release/janus-server-sdk-{version}.jar`\n\n# Janus Streaming Plugin API\n\nThe Janus Streaming Plugin API is a Java class designed to interact with the Janus WebRTC server's streaming plugin. It provides methods for creating, deleting, checking the existence, and retrieving a list of streaming sessions.\n\n## Prerequisites\n\n- Java Development Kit (JDK) 11+ installed\n- Janus WebRTC server running and accessible\n\n### Initialization\n\n```java\nstatic final String JANUS_URL = \"https://some-address-to-janus-server/janus\";\nstatic String JANUS_ADMIN_SECRET= \"some-secret-if-janus-server-has-authentication\";\nJanus janus = new Janus(true,new JanusConfiguration(JANUS_URL,\"\",\"\",JANUS_ADMIN_SECRET));\n```\n\n## Create Mounting Point\n\n```java\nJSONObject result = janus.janusRestApiClient.janusStreamingPlugInAPI.createMountingPoint(\"rtp\", \"MountingPoint1\", \"Description\", \"metadata\", \"secret\", \"1234\", true, true, \"[{\\\"type\\\": \\\"audio\\\"}, {\\\"type\\\": \\\"video\\\"}]\");\n\n```\n\n## Edit Mounting Point\n\n\n```java\nJSONObject result = janus.janusRestApiClient.janusStreamingPlugInAPI.editMountingPoint(\"mountingPointId\", true, \"New Description\", \"new_metadata\", \"new_secret\", \"5678\", true, false);\n\n```\n\n\n## Delete Mounting Point\n\n\n```java\nJSONObject result = janus.janusRestApiClient.janusStreamingPlugInAPI.deleteMountingPoint(\"mountingPointId\", \"secret\", true);\n\n```\n\n\n## Enable Mounting Point\n\n\n```java\nJSONObject result = janus.janusRestApiClient.janusStreamingPlugInAPI.enableMountingPoint(\"mountingPointId\", \"secret\");\n\n```\n\n\n## Info Mounting Point\n\n\n```java\nJSONObject result = janus.janusRestApiClient.janusStreamingPlugInAPI.infoMountingPoint(\"mountingPointId\", \"secret\");\n\n```\n\n\n## Error Handling\n\nIn case of an error, the returned JSONObject may contain an \"error\" field with additional details.\n```java\nif (result.has(\"error\")) {\n    String errorMessage = result.getString(\"error\");\n    // Handle the error\n}\n\n```\n\n\n\n\n\n\n\n\n# Janus Video Room Plugin API\n\n\nThe Janus Video Room Plugin API is a Java class designed to interact with the Janus WebRTC server's video room plugin. It provides methods for creating, deleting, checking the existence, and retrieving a list of video rooms.\n\n\n\n\n## Installation\n\nClone the repository and include the JanusVideoRoomPlugInAPI class in your Java project.\n\n## Usage\nPlease do note that   `roomId` parameter can be a number or a string.\n\n### Initialization\n\n```java\nstatic final String JANUS_URL = \"https://some-address-to-janus-server/janus\";\nstatic String JANUS_ADMIN_SECRET= \"some-secret-if-janus-server-has-authentication\";\nJanus janus = new Janus(true,new JanusConfiguration(JANUS_URL,\"\",\"\",JANUS_ADMIN_SECRET));\n```\n\n## Creating a Video Room\n\n```java\nvar createJanusRoom = janus.janusRestApiClient.janusVideoRoomPlugInAPI.createJanusRoom(\"91\",\"room\",\"1234\",\"1234\",5,true,true,\"/tmp\");\n```\n## Deleting a Video Room\n\n```java\nvar deleteRoom = janus.janusRestApiClient.janusVideoRoomPlugInAPI.deleteRoom(\"91\",\"1234\");\n```\n\n## Checking Video Room Existence\n\n```java\nvar response = janus.janusRestApiClient.janusVideoRoomPlugInAPI.checkIfVideoRoomExistsBoolCheck(\"1234\");\n// or\nvar result = janus.janusRestApiClient.janusVideoRoomPlugInAPI.checkIfVideoRoomExists(\"1234\");\n```\n\n## Retrieving List of Video Rooms\n    \n```java\nvar response = janus.janusRestApiClient.janusVideoRoomPlugInAPI.getRooms();\n```\n\n## Video Room Events Handling\n\nThere is support to consume events from the video room plugin.This is done by implementing the `JanusEventsEmissions` interface.I would recommend to implement this  interface in the end point class that will be \nreceiving the events from Janus server.For Example:\n\n```java\n//Helidon SE Endpoint Class\npublic class JanusEventsService implements HttpService, JanusEventsEmissions {\n    //... other code\n\tprivate void janusEventsHandler(ServerRequest req, ServerResponse res) {\n\t\tString bodyText = req.content().as(String.class);\n\t\t//System.out.println(\"Event bodyText : \" + bodyText);\n\t\tconsumeEventAsync(bodyText);// this is the function to pass the json string for processing\n\t\tres.status(Status.OK_200).send(\"\");\n\t}\n\t//... other code\n}\n```\n```java\n//Spring boot  Endpoint Class\n@RestController\npublic class JanusEventsService implements JanusEventsEmissions {\n    //... other code\n    @PostMapping(\"/janus-events-handler\")\n    public ResponseEntity\u003cString\u003e janusEventsHandler(@RequestBody String bodyText) {\n        //System.out.println(\"Event bodyText : \" + bodyText);\n        consumeEventAsync(bodyText);// this is the function to pass the json string for processing\n        return ResponseEntity.ok().body(\"\");\n    }\n    //... other code\n}\n```\n```java\n// Micronaut Endpoint Class\n@Controller(\"/janus-events-handler\")\npublic class JanusEventsService implements JanusEventsEmissions {\n    //... other code\n    @Post\n    public HttpResponse\u003cString\u003e janusEventsHandler(@Body String bodyText) {\n        //System.out.println(\"Event bodyText : \" + bodyText);\n        consumeEventAsync(bodyText);// this is the function to pass the json string for processing\n        return HttpResponse.ok(\"\");\n    }\n    //... other code\n}\n```\n```java\n// Quarkus Endpoint Class\n@Path(\"/janus-events-handler\")\npublic class JanusEventsService implements JanusEventsEmissions {\n    //... other code\n    @POST\n    @Consumes(MediaType.TEXT_PLAIN)\n    public Response janusEventsHandler(String bodyText) {\n        //System.out.println(\"Event bodyText : \" + bodyText);\n        consumeEventAsync(bodyText);// this is the function to pass the json string for processing\n        return Response.ok().build();\n    }\n    //... other code\n}\n```\nHere are the methods that will be called when an event is received from Janus server.\n```java\n    @Override\n    public void onParticipantJoined( long participantId, String participantDisplay, String roomId ) {\n        System.out.println(\"onParticipantJoined event = \" + participantId + \" \" + participantDisplay + \" \" + roomId);\n    }\n    \n    @Override\n    public void onParticipantLeft( long participantId, String participantDisplay, String roomId ) {\n        System.out.println(\"onParticipantLeft event = \" + participantId + \" \" + participantDisplay + \" \" + roomId);\n    }\n    \n    @Override\n    public void onRoomSessionStarted( String roomId, long firstParticipantId, String firstParticipantDisplay ) {\n        System.out.println(\"onRoomSessionStarted event = \" + roomId + \" \" + firstParticipantId + \" \" + firstParticipantDisplay);\n    }\n    \n    @Override\n    public void onRoomSessionEnded( String roomId ) {\n        System.out.println(\"onRoomSessionEnded event = \" + roomId);\n    }\n```\n\n## Events Database Caching \n\nThis SDK provides a way to cache the events received from Janus server in a database.Currently, MySQL \u0026 Mongo are supported but other databases can be added easily(PRs are welcome).\nTo save the events to an existing database consider the following example :\n\nMake sure the user provided in all the databases or cases have enough privileges to create tables and insert data.\n```java\n\nDBAccess dbAccess = DBAccess.getInstance();\nDatabaseConfig mySqlConfig = new MySqlConfiguration(\"localhost\", 3306, \"mydatabase\", \"username\", \"password\");\ndbAccess.addDatabaseConnection(\"mysql\", mySqlConfig);\n\n````\n```java\nDBAccess dbAccess = DBAccess.getInstance();\nDatabaseConfig mySqlConfig = new MongoConfiguration(\"localhost\", 27017, \"janus_database\", \"root\", \"rootuser\");\ndbAccess.addDatabaseConnection(\"mongodb\", mySqlConfig);\n\n```\n\nThis SDK will start to cache the events in the database if `io.github.kinsleykajiva.cache.DBAccess` is not null.If the details to access the database are incorrect ,the app wil throw an exception and stop.\n\nSo far this SDK cache supports the [following Janus Events](https://janus.conf.meetecho.com/docs/eventhandlers.html) :\n* **Type 1** Session related event\n* **Type 2**\t-Handle related event\n* **Type 4**\tExternal event (injected via Admin API)\n* **Type 8**\tJSEP event (SDP offer/answer)\n* **Type 16**\tWebRTC state event (ICE/DTLS states, candidates, etc.)\n* **Type 32**\tMedia event (media state, reports, etc.)\n* **Type 64**\tPlugin-originated event (e.g., event coming from VideoRoom)\n* **Type 128**\tTransport-originated event (e.g., WebSocket connection state)\n* **Type 256**\tCore event (server startup/shutdown)\n\nPlease note that in fields like session id or handle id are stored as they are but if they are not found the value is set to 0 in the database .\nTimestamp are saved as `DateTime` in the database, this aims at making searching easy as well based on dates.\n\nIn the event you want to search, try to consider session , handle the timestamp  as well .\n\nAll events are saved on a background thread ,This is done to avoid blocking the parent thread.\n\n## Post Processing for Video Room with also video transcoding\n\n\nThis tool converts `mjr` files from video rooms into a single video file that includes all participants in the room. Currently, it supports a maximum of 6 participants' streamed media being combined.\n\nIt operates via the system bash or command line, utilizing Java to execute commands through the `java.lang.ProcessBuilder` class. Since the `java.lang.ProcessBuilder` class is not synchronized, it is the user's responsibility to manage multi-threaded scenarios. It is advisable to establish a pipeline that processes each room sequentially.\n\nThis solution heavily relies on Janus being installed on the same machine, as it necessitates access to the command line tools `janus-pp-rec` and FFmpeg for transcoding.\n\nThe process initially converts MJR files to Opus and WebM file formats for audio and video respectively, before proceeding with transcoding using FFmpeg.\n\nThe process can be initiated using the `MediaFactory.class` object. You can provide a callback interface `PostProcessing` to receive the results of the transcoding process.\n\n\nHere is an example of how this will the run\n\n```java\npublic static void main( String[] args ) {\n\t\t\n\t\tMediaFactory mediaFactory = new MediaFactory(\n\t\t\t\tMediaOutputTarget.VIDEO_ROOM_PLUGIN ,\n\t\t\t\t\"1234\",\n\t\t\t\t\"/var/www/janus/recording-folder\",\n\t\t\t\t\"/var/www/janus/recording-folder/processed\",\n\t\t\t\t\n\t\t\t\tnew PostProcessing(){\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void onProcessingStarted( String roomId, long millisecondsTimeStamp, List\u003cFileInfoMJR\u003e fileInfoMJRs, Thread thread ) {\n\t\t\t\t\t\tSystem.out.println(\"Processing started \" + roomId + \" \" + millisecondsTimeStamp + \" \" + fileInfoMJRs + \" \" + thread);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void onProcessingEnded( String roomId, long millisecondsTimeStamp, List\u003cFile\u003e outputs, Thread thread ) {\n\t\t\t\t\t\tSystem.out.println(\"Processing ended \" + roomId + \" \" + millisecondsTimeStamp + \" \" + outputs + \" \" + thread);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void onProcessingFailed( String roomId, long millisecondsTimeStamp, String error ) {\n\t\t\t\t\t\tSystem.out.println(\"Processing failed \" + roomId + \" \" + millisecondsTimeStamp + \" \" + error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void onCleanUpStarted( String roomId, long millisecondsTimeStamp, Set\u003cString\u003e filesToCleanup ) {\n\t\t\t\t\t\tSystem.out.println(\"Clean up started \" + roomId + \" \" + millisecondsTimeStamp + \" \" + filesToCleanup);\n\t\t\t\t\t\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void onCleanUpFailed( String roomId, long millisecondsTimeStamp, String error ) {\n\t\t\t\t\t\tSystem.out.println(\"Clean up failed \" + roomId + \" \" + millisecondsTimeStamp + \" \" + error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t@Override\n\t\t\t\t\tpublic void onCleanUpEnded( String roomId, long millisecondsTimeStamp ) {\n\t\t\t\t\t\tSystem.out.println(\"Clean up ended \" + roomId + \" \" + millisecondsTimeStamp);\n\t\t\t\t\t}\n\t\t\t\t});\n}\n\n\n```\n\nInternally there are checks on the call `SdkUtils.isJanusInstalled()` if this fails this wil throw an exception and stop the app.\n\n## Contributing\n\nI welcome contributions! If you find a bug, have a feature request, or want to improve the documentation, feel free to open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n```shell\n git push origin +refs/heads/master:refs/heads/master\n```\n\n## -------\n## -------\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinsleykajiva%2Fjanus-server-java-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkinsleykajiva%2Fjanus-server-java-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkinsleykajiva%2Fjanus-server-java-sdk/lists"}