/// <inheritdoc/> public override Task SendMessageAsync(SdpMessage message) { Debug.Log("<color=cyan>SdpMessage</color>: " + message.Content); if (message.Type == SdpMessageType.Offer) { lastOffer = message; } long i = idMessage++; var rpcMessage = "{\"jsonrpc\": \"2.0\"," + "\"method\": \"publishVideo\", " + "\"params\": { " + "\"sdpOffer\": \"" + message.Content + "\"," + "\"doLoopback\": false," + "\"hasAudio\": false," + "\"hasVideo\": true," + "\"audioActive\": false," + "\"videoActive\": true," + "\"typeOfVideo\": \"CAMERA\"," + "\"frameRate\": 30," + "\"videoDimensions\": \"{\\\"width\\\":640,\\\"height\\\":480}\"" + //TODO setup video dimensions according to capabilites "}, \"id\": " + i + " }"; Debug.Log("SdpMessage: " + rpcMessage); webSocket.SendText(rpcMessage); messages.Add(i, OpenViduType.PublishVideo); var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(true); return(tcs.Task); //return SendMessageImplAsync(new OpenViduMessage(message)); }
private IEnumerator Connect() { var www = UnityWebRequest.Get($"https://{Server}/api/sessions/" + Room); www.SetRequestHeader("Authorization", "Basic " + EncodedSecret); yield return(www.SendWebRequest()); bool sessionOk = false; string token = ""; if (www.isNetworkError) { Debug.Log("Error While Sending: " + www.error); } else { Debug.Log($"Received{www.responseCode}: {www.downloadHandler.text}"); session = JsonConvert.DeserializeObject <OpenViduSessionInfo>(www.downloadHandler.text); sessionOk = true; } if (www.responseCode == 404) { Debug.Log("Creating Session"); www = new UnityWebRequest($"https://{Server}/api/sessions", "POST"); byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"customSessionId\": \"" + Room + "\"}"); www.uploadHandler = (UploadHandler) new UploadHandlerRaw(jsonToSend); www.SetRequestHeader("Authorization", "Basic " + EncodedSecret); www.SetRequestHeader("Content-Type", "application/json"); www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log("Error While Sending: " + www.error); } else { Debug.Log($"Received{www.responseCode}: {www.downloadHandler.text}"); sessionOk = true; } } if (sessionOk) { Debug.Log("Asking for a token"); www = new UnityWebRequest($"https://{Server}/api/tokens", "POST"); byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"session\": \"" + Room + "\"}");// default to publisher //byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes("{\"session\": \"Aresibo\", \"role\": \"SUBSCRIBER\"}"); www.uploadHandler = (UploadHandler) new UploadHandlerRaw(jsonToSend); www.SetRequestHeader("Authorization", "Basic " + EncodedSecret); www.SetRequestHeader("Content-Type", "application/json"); www.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); if (www.isNetworkError) { Debug.Log("Error While Sending: " + www.error); } else { Debug.Log($"Received{www.responseCode}: {www.downloadHandler.text}"); var t = JsonConvert.DeserializeObject <OpenViduToken>(www.downloadHandler.text); token = t.token; Debug.Log($"Token :{token}"); } } //connect Websocket webSocket = gameObject.GetComponent <UnityWebSocket>(); webSocket.Connect(); //wait for the socket to be ready yield return(new WaitForSeconds(1f)); long i = idMessage++; webSocket.SendText("{\"jsonrpc\": \"2.0\"," + "\"method\": \"joinRoom\"," + "\"params\": {" + "\"token\": \"" + token + "\"," + "\"session\": \"" + Room + "\"," + "\"platform\": \"Chrome 76.0.3809.132 on Linux 64-bit\"," + //"\"platform\": \"Unity\"," + "\"metadata\": \"{clientData: TestClient}\"," + "\"secret\": \"" + Secret + "\", " + "\"recorder\": false }," + "\"id\": " + i + " }"); messages.Add(i, OpenViduType.JoinRoom); }