private void onJoinButtonClicked()
    {
        // get parameters (channel name, channel profile, etc.)
        GameObject go    = GameObject.Find("ChannelName");
        InputField field = go.GetComponent <InputField>();

        // create app if nonexistent
        if (ReferenceEquals(app, null))
        {
            app = new exampleApp();        // create app
            exampleApp.logD("zhangagora " + app);
            app.loadEngine();              // load engine
        }

        // join channel and jump to next scene
        app.join(field.text);
        SceneManager.sceneLoaded += OnLevelFinishedLoading;         // configure GameObject after scene is loaded
        SceneManager.LoadScene("Scene1", LoadSceneMode.Single);
    }
    private void onApiButtonClicked()
    {
        GameObject go  = GameObject.Find("ApiList");
        Dropdown   dd  = go.GetComponent <Dropdown> ();
        string     api = dd.captionText.text;

        Debug.Log("onApiButtonClicked: " + api);

        if (ReferenceEquals(app, null))
        {
            app = new exampleApp();
            app.loadEngine();
        }

        // these APIs do not require engine being created
        if (api.CompareTo("GetSdkVersion") == 0)
        {
            string ret = agora_gaming_rtc.IRtcEngine.GetSdkVersion();
            setApiReturn(ret);
            return;
        }

        if (api.CompareTo("SetChannelProfile") == 0)
        {
            int num = getApiParamInt(1);

            agora_gaming_rtc.CHANNEL_PROFILE chProfile;
            switch (num)
            {
            case 2:
                chProfile = agora_gaming_rtc.CHANNEL_PROFILE.GAME_FREE_MODE;
                break;

            case 3:
            default:
                chProfile = agora_gaming_rtc.CHANNEL_PROFILE.GAME_COMMAND_MODE;
                break;
            }

            int r = app.mRtcEngine.SetChannelProfile(chProfile);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetClientRole") == 0)
        {
            int num = getApiParamInt(1);

            agora_gaming_rtc.CLIENT_ROLE role;
            switch (num)
            {
            case 1:
                role = agora_gaming_rtc.CLIENT_ROLE.BROADCASTER;
                break;

            case 2:
            default:
                role = agora_gaming_rtc.CLIENT_ROLE.AUDIENCE;
                break;
            }

            int r = app.mRtcEngine.SetClientRole(role);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("Pause") == 0)
        {
            app.mRtcEngine.Pause();
        }
        else if (api.CompareTo("Resume") == 0)
        {
            app.mRtcEngine.Resume();
        }
        else if (api.CompareTo("GetCallId") == 0)
        {
            string ret = app.mRtcEngine.GetCallId();
            setApiReturn(ret);
        }
        else if (api.CompareTo("SwitchCamera") == 0)
        {
            int r = app.mRtcEngine.SwitchCamera();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetVideoProfile") == 0)
        {
            GameObject go1 = GameObject.Find("VIDEOPROFILE");
            Dropdown   dd1 = go1.GetComponent <Dropdown> ();
            string     s   = dd1.captionText.text;
            Debug.Log("VideoProfile: " + s);
            string[] sArray = s.Split(' ');

            int profile = int.Parse(sArray [0]);                    //getApiParamInt (1);
            int swap    = sArray[2].CompareTo("true") == 0 ? 1 : 0; //getApiParamInt (2);

            int r = app.mRtcEngine.SetVideoProfile(profile, (swap != 0));
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteLocalVideoStream") == 0)
        {
            int mute = getApiParamInt(1);

            int r = app.mRtcEngine.MuteLocalVideoStream(mute != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteAllRemoteVideoStreams") == 0)
        {
            int mute = getApiParamInt(1);

            int r = app.mRtcEngine.MuteAllRemoteVideoStreams(mute != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteRemoteVideoStream") == 0)
        {
            // auto fill in
            setApiParam(1, app.mRemotePeer.ToString());

            uint uid  = app.mRemotePeer;           // getApiParamInt (1);
            int  mute = getApiParamInt(2);

            int r = app.mRtcEngine.MuteRemoteVideoStream(uid, (mute != 0));
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableDualStreamMode") == 0)
        {
            int enabled = getApiParamInt(1);

            int r = app.mRtcEngine.EnableDualStreamMode(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetRemoteVideoStreamType") == 0)
        {
            int uid        = getApiParamInt(1);
            int streamType = getApiParamInt(2);

            int r = app.mRtcEngine.SetRemoteVideoStreamType((uint)uid, streamType);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableVideo") == 0)
        {
            int r = app.mRtcEngine.EnableVideo();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("DisableVideo") == 0)
        {
            int r = app.mRtcEngine.DisableVideo();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableLocalVideo") == 0)
        {
            int enabled = getApiParamInt(1);

            int r = app.mRtcEngine.EnableLocalVideo(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("StartPreview") == 0)
        {
            int r = app.mRtcEngine.StartPreview();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("StopPreview") == 0)
        {
            int r = app.mRtcEngine.StopPreview();
            setApiReturn(r.ToString());
        }
        else
        {
            Debug.Log("onApiButtonClicked: unsupported API!");
        }
    }
Exemple #3
0
    private void onApiButtonClicked()
    {
        GameObject go  = GameObject.Find("ApiList");
        Dropdown   dd  = go.GetComponent <Dropdown>();
        string     api = dd.captionText.text;

        Debug.Log("onApiButtonClicked: " + api);

        if (ReferenceEquals(app, null))
        {
            app = new exampleApp();
            app.loadEngine();
        }
        app.mRtcEngine.SetParameters("{\"rtc.log_filter\": 65535}");
        // these APIs do not require engine being created
        if (api.CompareTo("GetSdkVersion") == 0)
        {
            string ret = agora_gaming_rtc.IRtcEngine.GetSdkVersion();
            setApiReturn(ret);
            return;
        }

        if (api.CompareTo("SetChannelProfile") == 0)
        {
            int num = getApiParamInt(1);

            agora_gaming_rtc.CHANNEL_PROFILE chProfile;
            switch (num)
            {
            case 0:
                chProfile = agora_gaming_rtc.CHANNEL_PROFILE.GAME_FREE_MODE;
                break;

            case 1:
                chProfile = agora_gaming_rtc.CHANNEL_PROFILE.GAME_COMMAND_MODE;
                break;

            default:
                chProfile = agora_gaming_rtc.CHANNEL_PROFILE.GAME_FREE_MODE;
                break;
            }

            int r = app.mRtcEngine.SetChannelProfile(chProfile);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetClientRole") == 0)
        {
            int num = getApiParamInt(1);
            agora_gaming_rtc.CLIENT_ROLE role;
            switch (num)
            {
            case 1:
                role = agora_gaming_rtc.CLIENT_ROLE.BROADCASTER;
                break;

            case 2:
            default:
                role = agora_gaming_rtc.CLIENT_ROLE.AUDIENCE;
                break;
            }

            int r = app.mRtcEngine.SetClientRole(role);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("Pause") == 0)
        {
            app.mRtcEngine.Pause();
        }
        else if (api.CompareTo("Resume") == 0)
        {
            app.mRtcEngine.Resume();
        }
        else if (api.CompareTo("GetCallId") == 0)
        {
            string ret = app.mRtcEngine.GetCallId();
            setApiReturn(ret);
        }
        else if (api.CompareTo("SwitchCamera") == 0)
        {
            int r = app.mRtcEngine.SwitchCamera();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetVideoProfile") == 0)
        {
            GameObject go1 = GameObject.Find("VIDEOPROFILE");
            Dropdown   dd1 = go1.GetComponent <Dropdown>();
            string     s   = dd1.captionText.text;
            Debug.Log("VideoProfile: " + s);
            string[] sArray = s.Split(' ');

            int profile = int.Parse(sArray[0]);                     //getApiParamInt (1);
            int swap    = sArray[2].CompareTo("true") == 0 ? 1 : 0; //getApiParamInt (2);

            int r = app.mRtcEngine.SetVideoProfile(profile, (swap != 0));
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteLocalVideoStream") == 0)
        {
            int mute = getApiParamInt(1);

            int r = app.mRtcEngine.MuteLocalVideoStream(mute != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteAllRemoteVideoStreams") == 0)
        {
            int mute = getApiParamInt(1);

            int r = app.mRtcEngine.MuteAllRemoteVideoStreams(mute != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteRemoteVideoStream") == 0)
        {
            // auto fill in
            setApiParam(1, app.mRemotePeer.ToString());
            uint uid  = app.mRemotePeer;// getApiParamInt (1);
            int  mute = getApiParamInt(2);
            int  r    = app.mRtcEngine.MuteRemoteVideoStream(uid, (mute != 0));
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableDualStreamMode") == 0)
        {
            int enabled = getApiParamInt(1);
            int r       = app.mRtcEngine.EnableDualStreamMode(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetRemoteVideoStreamType") == 0)
        {
            setApiParam(1, app.mRemotePeer.ToString());
            uint uid = app.mRemotePeer; // getApiParamInt (1);
                                        //int uid = getApiParamInt (1);
            int streamType = getApiParamInt(2);
            int r          = app.mRtcEngine.SetRemoteVideoStreamType(uid, streamType);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableVideo") == 0)
        {
            int r = app.mRtcEngine.EnableVideo();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("DisableVideo") == 0)
        {
            int r = app.mRtcEngine.DisableVideo();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableLocalVideo") == 0)
        {
            int enabled = getApiParamInt(1);
            int r       = app.mRtcEngine.EnableLocalVideo(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("StartPreview") == 0)
        {
            int r = app.mRtcEngine.StartPreview();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("StopPreview") == 0)
        {
            int r = app.mRtcEngine.StopPreview();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetLocalVoicePitch") == 0)
        {
            string pitch = getApiParam(1);
            int    r     = app.mRtcEngine.SetLocalVoicePitch(double.Parse(pitch));
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetRemoteVoicePosition") == 0)
        {
            double pan  = double.Parse(getApiParam(2));
            double gain = double.Parse(getApiParam(3));
            int    r    = app.mRtcEngine.SetRemoteVoicePosition(app.mRemotePeer, pan, gain);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetVoiceOnlyMode") == 0)
        {
            int enabled = int.Parse(getApiParam(1));
            int r       = app.mRtcEngine.SetVoiceOnlyMode(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableLocalAudio") == 0)
        {
            int enabled = int.Parse(getApiParam(1));
            int r       = app.mRtcEngine.EnableLocalAudio(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetEnableSpeakerPhone") == 0)
        {
            int enabled = int.Parse(getApiParam(1));
            int r       = app.mRtcEngine.SetEnableSpeakerphone(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("IsSpeakerPhoneEnabled") == 0)
        {
            bool r = app.mRtcEngine.IsSpeakerphoneEnabled();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetDefaultAudioRouteToSpeakerphone") == 0)
        {
            int enabled = int.Parse(getApiParam(1));
            Debug.Log("SetDefaultAudioRouteToSpeakerphone  enabled = " + (enabled != 0));
            int r = app.mRtcEngine.SetDefaultAudioRouteToSpeakerphone(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableAudioVolumeIndication") == 0)
        {
            int interval = int.Parse(getApiParam(1));
            int smooth   = int.Parse(getApiParam(2));
            int r        = app.mRtcEngine.EnableAudioVolumeIndication(interval, smooth);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteLocalAudioStream") == 0)
        {
            int enabled = int.Parse(getApiParam(1));
            int r       = app.mRtcEngine.MuteLocalAudioStream(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteAllRemoteAudioStreams") == 0)
        {
            int enabled = int.Parse(getApiParam(1));
            int r       = app.mRtcEngine.MuteAllRemoteAudioStreams(enabled != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("MuteRemoteAudioStream") == 0)
        {
            int muted = int.Parse(getApiParam(2));
            int r     = app.mRtcEngine.MuteRemoteAudioStream(app.mRemotePeer, muted != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("AdjustRecordingSignalVolume") == 0)
        {
            int volume = int.Parse(getApiParam(1));
            int r      = app.mRtcEngine.AdjustRecordingSignalVolume(volume);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("AdjustPlaybackSignalVolume") == 0)
        {
            int volume = int.Parse(getApiParam(1));
            int r      = app.mRtcEngine.AdjustPlaybackSignalVolume(volume);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableVideoObserver") == 0)
        {
            int r = app.mRtcEngine.EnableVideoObserver();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("DisableVideoObserver") == 0)
        {
            int r = app.mRtcEngine.DisableVideoObserver();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetDefaultMuteAllRemoteAudioStreams") == 0)
        {
            int volume = int.Parse(getApiParam(1));
            int r      = app.mRtcEngine.SetDefaultMuteAllRemoteAudioStreams(volume != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("SetDefaultMuteAllRemoteVideoStreams") == 0)
        {
            int volume = int.Parse(getApiParam(1));
            int r      = app.mRtcEngine.SetDefaultMuteAllRemoteVideoStreams(volume != 0);
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("EnableAudio") == 0)
        {
            int r = app.mRtcEngine.EnableAudio();
            setApiReturn(r.ToString());
        }
        else if (api.CompareTo("DisableAudio") == 0)
        {
            int r = app.mRtcEngine.DisableAudio();
            setApiReturn(r.ToString());
        }
        else
        {
            Debug.Log("onApiButtonClicked: unsupported API!");
        }
    }