コード例 #1
0
    void OnMessage(string s)
    {
        Debug.Log("onmessage " + s);
        var data = JsonUtility.FromJson <OnMessageS>(s);

        Debug.Log(data.type);
        if (data.type == "offer" || data.type == "answer" || data.type == "ice")
        {
            signaling.SetSdp(data.payload);
        }
    }
コード例 #2
0
    async void Join()
    {
        var request = new UnityWebRequest("http://" + baseAddress + ":8080/join", "POST");
        var join    = new JoinReq {
            room = "unity"
        };
        var json = JsonUtility.ToJson(join);

        byte[] postData = System.Text.Encoding.UTF8.GetBytes(json);
        request.uploadHandler   = (UploadHandler) new UploadHandlerRaw(postData);
        request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        await request.SendWebRequest();

        var joinres = JsonSerializer.Deserialize <JoinRes>(request.downloadHandler.text);

        id = joinres.uu;
        Debug.Log(joinres.sdp);

        signaling.SetSdp(joinres.sdp.type + "%" + joinres.sdp.sdp);
    }