# OpenVidu on Unity

**URL:** <https://openvidu.discourse.group/t/openvidu-on-unity/4454>\
**Category:** How to implement?\
**Tags:** v2\
**Created:** [February 27, 2023, 10:49am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454 "2023-02-27T10:49:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Belo](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/joel_belo/32/2159_2.png) [@Joel\_Belo](https://openvidu.discourse.group/u/Joel_Belo)\
**Post date:** [February 27, 2023, 10:49am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/1 "2023-02-27T10:49:37Z")

</div>

Hello,  
I’m trying to implement OpenVidu with Unity, is there any way to do this?  
Does OpenVidu have any SDK for unity?

Thanks

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [February 28, 2023, 9:53am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/2 "2023-02-28T09:53:04Z")

</div>

There is no official OpenVidu SDK for Unity.  
But any client platform that has a modern WebRTC package should work fine with OpenVidu, if the RPC protocol is properly implemented.

- Unity WebRTC package: [WebRTC | WebRTC | 2.4.0-exp.11](https://docs.unity3d.com/Packages/com.unity.webrtc@2.4/manual/index.html)
- OpenVidu RPC protocol: [OpenVidu Server RPC protocol - OpenVidu Docs](https://docs.openvidu.io/en/2.25.0/developing/rpc/)

Cheers.

---

<div class="post-metadata">

**Author:** ![Joel\_Belo](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/joel_belo/32/2159_2.png) [@Joel\_Belo](https://openvidu.discourse.group/u/Joel_Belo)\
**Post date:** [March 6, 2023, 11:35am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/3 "2023-03-06T11:35:20Z")

</div>

I’m currently connecting to the API and then websocket connection, but when I do the first connection and send the first publishVideo call I get this error:

{“id”:5,“error”:{“code”:-1,“message”:“java.lang.NullPointerException:null”,“data”:“java.lang.NullPointerException\n\tat io.openvidu.server.kurento.core.KurentoParticipant.createPublishingEndpoint(KurentoParticipant.java:102)\n\tat io.openvidu.server.kurento.core.KurentoSessionManager.publishVideo(KurentoSessionManager.java:405)\n\tat io.openvidu.server.rpc.RpcHandler.publishVideo(RpcHandler.java:383)\n\tat io.openvidu.server.rpc.RpcHandler.handleRequest(RpcHandler.java:135)\n\tat org.kurento.jsonrpc.internal.JsonRpcHandlerManager.handleRequest(JsonRpcHandlerManager.java:142)\n\tat org.kurento.jsonrpc.internal.server.ProtocolManager$3.run(ProtocolManager.java:218)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)\n\tat java.base/java.lang.Thread.run(Thread.java:829)\n”},“jsonrpc”:“2.0”}

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [March 6, 2023, 11:56am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/4 "2023-03-06T11:56:27Z")

</div>

Make sure your participant has role PUBLISHER and not SUBSCRIBER.  
Also make sure you are implementing the RPC protocol for the exact version of the OpenVidu deployment you are using.

---

<div class="post-metadata">

**Author:** ![Joel\_Belo](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/joel_belo/32/2159_2.png) [@Joel\_Belo](https://openvidu.discourse.group/u/Joel_Belo)\
**Post date:** [March 7, 2023, 12:18pm UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/5 "2023-03-07T12:18:46Z")

</div>

I’m recieving this response after joinRoom:

Received: {  
“id”: 3,  
“result”: {  
“id”: “con\_TqjLN7oDLi”,  
“finalUserId”: “42BC0A2CC7B6BA3D”,  
“createdAt”: 1678190750655,  
“metadata”: “{clientData: TestClient}”,  
“value”: ,  
“session”: “mareah-singapore-black-giraffe”,  
“version”: “2.25.0”,  
“mediaServer”: “kurento”,  
“videoSimulcast”: false,  
“role”: “SUBSCRIBER”,  
“coturnIp”: “35.156.123.243”,  
“coturnPort”: 3478,  
“turnUsername”: “1678277150:sh97YR2k”,  
“turnCredential”: “Oqn23RtnR4xDvCdz4FpmdwVSW7w=”,  
“customIceServers”: [  
{  
“url”: “turn:35.156.123.243:3478”,  
“username”: “1678277150:sh97YR2k”,  
“credential”: “Oqn23RtnR4xDvCdz4FpmdwVSW7w=”  
}  
],  
“sessionId”: “o60d9ulfs973a1qo0n2lrjqb37”  
},  
“jsonrpc”: “2.0”  
}

How can I make the user PUBLISHER instead of SUBSCRIBER?

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [March 7, 2023, 4:04pm UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/6 "2023-03-07T16:04:34Z")

</div>

When creating a Connection from your application server, set the role to PUBLISHER: [Application server - OpenVidu Docs](https://docs.openvidu.io/en/2.25.0/application-server/#2-create-a-connection)

Use that Connection’s token to connect your user with RPC method `joinRoom`.

---

<div class="post-metadata">

**Author:** ![Joel\_Belo](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/joel_belo/32/2159_2.png) [@Joel\_Belo](https://openvidu.discourse.group/u/Joel_Belo)\
**Post date:** [March 9, 2023, 10:59am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/7 "2023-03-09T10:59:26Z")

</div>

Just to clarify, when you say “When creating a Connection from your application server” that is coming from the api call that the client does or the server itself? Because on the client I am sending to the token api the session name and putting role PUBLISHER and I recieve this back:

1. {“id”:“wss://aws.openvidu.assistance.immera.io?sessionId=mareah-singapore-black-giraffe&token=tok\_LfdleuW5tJ4saj1C”,“token”:“wss://aws.openvidu.assistance.immera.io?sessionId=mareah-singapore-black-giraffe&token=tok\_LfdleuW5tJ4saj1C”,“createdAt”:1678285979465,“connectionId”:“con\_OJ0VR5MzT6”,“session”:“mareah-singapore-black-giraffe”,“data”:“”,“role”:“PUBLISHER”}

But when I connect with sockets using joinRoom sending this:

Sent: {“jsonrpc”: “2.0”,“method”: “joinRoom”,“params”: {“token”: “wss://aws.openvidu.assistance.immera.io?sessionId=mareah-singapore-black-giraffe&token=tok\_LfdleuW5tJ4saj1C”,“session”: “mareah-singapore-black-giraffe”,“platform”: “Chrome 76.0.3809.132 on Linux 64-bit”,“metadata”: “{clientData: TestClient}”,“secret”: “xxxxxxxxxx”, “recorder”: false },“id”: 2 }

I recieve this:

Received: {“id”:2,“result”:{“id”:“con\_KrFBIbXh1Y”,“finalUserId”:“59117852E0A2DB97”,“createdAt”:1678285980807,“metadata”:“{clientData: TestClient}”,“value”:[{“id”:“con\_OLzhXJ2rZG”,“createdAt”:1678285898322,“metadata”:“{clientData: TestClient}”}],“session”:“mareah-singapore-black-giraffe”,“version”:“2.25.0”,“mediaServer”:“kurento”,“videoSimulcast”:false,“role”:“SUBSCRIBER”,“coturnIp”:“35.156.123.243”,“coturnPort”:3478,“turnUsername”:“1678372380:4OO3bC0u”,“turnCredential”:“hL+i1h5SwBoRC+Zhh6hyf2MjTSQ=”,“customIceServers”:[{“url”:“turn:35.156.123.243:3478”,“username”:“1678372380:4OO3bC0u”,“credential”:“hL+i1h5SwBoRC+Zhh6hyf2MjTSQ=”}],“sessionId”:“vrjo3s86a8u1djt90fpa3j5hg8”},“jsonrpc”:“2.0”}

SUBSCRIBER again. What is wrong here?

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [March 9, 2023, 11:36am UTC](https://openvidu.discourse.group/t/openvidu-on-unity/4454/8 "2023-03-09T11:36:30Z")

</div>

I sense some confusion in the basic concepts of how you are using the OpenVidu API. Please, carefully read this documentation page: [Developing your video app - OpenVidu Docs](https://docs.openvidu.io/en/stable/developing-your-video-app/).  
Especially this section explaining the [**Workflow of an OpenVidu Session**](https://docs.openvidu.io/en/stable/developing-your-video-app/#workflow-of-an-openvidu-session)

The phrase “that is coming from the api call that the client does or the server itself?” makes me think that you are mixing the client-side and the server-side of your application. You must first create a Session and a Connection (with role PUBLISHER) from your **application server** , and then pass the token of the Connection to your **application client**. Only then you can use it to call the RPC `joinRoom`.
