Esempio n. 1
0
    public void OnControlButtonClicked()
    {
        Debug.Log("clicked");
        if (mJoined)
        {
            //stop local preview
            mRtcEngine.StopPreview();
            GameObject          go      = GameObject.Find("LocalVideoCube");
            VideoDisplaySurface surface = go.GetComponent <VideoDisplaySurface>();
            surface.SetEnable(false);

            go = GameObject.Find("RemoteVideoCube");
            if (!ReferenceEquals(go, null))
            {
                surface = go.GetComponent <VideoDisplaySurface>();
                surface.SetEnable(false);
            }

            mRtcEngine.LeaveChannel();
        }
        else
        {
            //set local preview surface
            GameObject          go      = GameObject.Find("LocalVideoCube");
            VideoDisplaySurface surface = go.GetComponent <VideoDisplaySurface>();
            surface.SetUserId("");
            surface.SetVideoTrack(AliRTCVideoTrack.VIDEO_TRACK_CAMERA);
            surface.SetEnable(true);

#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
            mRtcEngine.SetLocalViewConfig(true);
            mRtcEngine.ConfigExternalVideoRendering(true);
#endif
            //start local preview
            mRtcEngine.StartPreview();
            // authInfo 从业务 appserver 获取
            // ckwxs2so
            // 24f2feb9cd976671d4271ba0db6597f6
            //join channel


            AliRTCAuthInfo ai = new AliRTCAuthInfo();
            ai.appId     = "ckwxs2so";
            ai.userId    = "myuserid";
            ai.channel   = "myfirstchannel";
            ai.nonce     = "AK-a04b4307-64d4-4c9e-be8f-13b42b3d4222";
            ai.timestamp = 1584946092;
            ai.token     = "70f16e8615b510c3bd0ccfda19e7da448ff5b9d18e6443321b648d592ce6ce98";
            ai.gslbArray = "['https://rgslb.rtc.aliyuncs.com']";

            mRtcEngine.JoinChannel(ai, "shawhu2000");
        }

        mJoined = !mJoined;
        mControlButton.GetComponentInChildren <Text>(true).text = mJoined == false ? "Join" : "Leave";
    }