void InitEngine() { mRtcEngine = IRtcEngine.GetEngine(APP_ID); mRtcEngine.SetLogFile("log.txt"); mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_LIVE_BROADCASTING); mRtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER); mRtcEngine.SetVideoEncoderConfiguration(new VideoEncoderConfiguration { dimensions = new VideoDimensions { width = 720, height = 640 }, frameRate = FRAME_RATE.FRAME_RATE_FPS_24 }); mRtcEngine.EnableAudio(); mRtcEngine.EnableVideo(); mRtcEngine.EnableVideoObserver(); mRtcEngine.OnJoinChannelSuccess += OnJoinChannelSuccessHandler; mRtcEngine.OnLeaveChannel += OnLeaveChannelHandler; mRtcEngine.OnWarning += OnSDKWarningHandler; mRtcEngine.OnError += OnSDKErrorHandler; mRtcEngine.OnConnectionLost += OnConnectionLostHandler; mRtcEngine.OnUserJoined += OnUserJoinedHandler; mRtcEngine.OnUserOffline += OnUserOfflineHandler; mRtcEngine.OnStreamPublished += OnStreamPublishedHandler; mRtcEngine.OnRtmpStreamingStateChanged += OnRtmpStreamingStateChangedHandler; mRtcEngine.OnRtmpStreamingEvent += OnRtmpStreamingEventHandler; }
void ToggleValueChanged(Toggle change) { if (mToggleBtn.isOn) { mRtcEngine.EnableAudio(); } else { mRtcEngine.DisableAudio(); } }
void OnApplicationFocus(bool isFocus) { if (isFocus) { if (mRtcEngine != null) { mRtcEngine.EnableAudio(); } Debug.Log("agora isFocus"); } else { Debug.Log("agora unfocus"); } }
private void InitEngine() { mRtcEngine = IRtcEngine.GetEngine(APP_ID); mRtcEngine.SetLogFile("log.txt"); mRtcEngine.EnableAudio(); mRtcEngine.EnableVideo(); mRtcEngine.EnableVideoObserver(); mRtcEngine.OnJoinChannelSuccess += OnJoinChannelSuccessHandler; mRtcEngine.OnLeaveChannel += OnLeaveChannelHandler; mRtcEngine.OnWarning += OnSDKWarningHandler; mRtcEngine.OnError += OnSDKErrorHandler; mRtcEngine.OnConnectionLost += OnConnectionLostHandler; mRtcEngine.OnUserJoined += OnUserJoinedHandler; mRtcEngine.OnUserOffline += OnUserOfflineHandler; }
void InitEngine() { mRtcEngine = IRtcEngine.GetEngine(APP_ID); mRtcEngine.SetLogFile("log.txt"); mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_LIVE_BROADCASTING); mRtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER); mRtcEngine.EnableAudio(); mRtcEngine.EnableVideo(); mRtcEngine.EnableVideoObserver(); mRtcEngine.OnJoinChannelSuccess += OnJoinChannelSuccessHandler; mRtcEngine.OnLeaveChannel += OnLeaveChannelHandler; mRtcEngine.OnWarning += OnSDKWarningHandler; mRtcEngine.OnError += OnSDKErrorHandler; mRtcEngine.OnConnectionLost += OnConnectionLostHandler; mRtcEngine.OnUserJoined += OnUserJoinedHandler; mRtcEngine.OnUserOffline += OnUserOfflineHandler; }
void InitEngine() { mRtcEngine = IRtcEngine.GetEngine(APP_ID); mRtcEngine.SetLogFile("log.txt"); mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_LIVE_BROADCASTING); mRtcEngine.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER); videoRawDataManager = VideoRawDataManager.GetInstance(mRtcEngine); videoRawDataManager.SetOnCaptureVideoFrameCallback(OnCaptureVideoFrameHandler); videoRawDataManager.SetOnRenderVideoFrameCallback(OnRenderVideoFrameHandler); mRtcEngine.EnableAudio(); mRtcEngine.EnableVideo(); mRtcEngine.EnableVideoObserver(); mRtcEngine.OnJoinChannelSuccess += OnJoinChannelSuccessHandler; mRtcEngine.OnLeaveChannel += OnLeaveChannelHandler; mRtcEngine.OnWarning += OnSDKWarningHandler; mRtcEngine.OnError += OnSDKErrorHandler; mRtcEngine.OnConnectionLost += OnConnectionLostHandler; mRtcEngine.OnUserJoined += OnUserJoinedHandler; mRtcEngine.OnUserOffline += OnUserOfflineHandler; }
void InitEngine() { mRtcEngine = IRtcEngine.GetEngine(APP_ID); mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.CHANNEL_PROFILE_LIVE_BROADCASTING); // If you want to user Multi Channel Video, please call "SetMultiChannleWant to true" mRtcEngine.SetMultiChannelWant(true); mRtcEngine.EnableAudio(); mRtcEngine.EnableVideo(); mRtcEngine.EnableVideoObserver(); channel1 = mRtcEngine.CreateChannel(channel1Name); channel2 = mRtcEngine.CreateChannel(channel2Name); channel1.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER); channel2.SetClientRole(CLIENT_ROLE_TYPE.CLIENT_ROLE_BROADCASTER); channel1.ChannelOnJoinChannelSuccess = Channel1OnJoinChannelSuccessHandler; channel1.ChannelOnLeaveChannel = Channel1OnLeaveChannelHandler; channel1.ChannelOnUserJoined = Channel1OnUserJoinedHandler; channel1.ChannelOnError = Channel1OnErrorHandler; channel2.ChannelOnJoinChannelSuccess = Channel2OnJoinChannelSuccessHandler; channel2.ChannelOnLeaveChannel = Channel2OnLeaveChannelHandler; channel2.ChannelOnUserJoined = Channel2OnUserJoinedHandler; channel2.ChannelOnError = Channel2OnErrorHandler; }
// Use this for initialization void Start() { if (!mInitialized) { mInitialized = true; isRecord = false; mRtcEngine = IRtcEngine.GetEngine(appId); mRtcEngine.OnJoinChannelSuccess += (string channelName, uint uid, int elapsed) => { string joinSuccessMessage = string.Format("joinChannel callback uid: {0}, channel: {1}, version: {2}", uid, channelName, IRtcEngine.GetSdkVersion()); Debug.Log(joinSuccessMessage); mShownMessage.GetComponent <Text> ().text = (joinSuccessMessage); }; mRtcEngine.OnLeaveChannel += (RtcStats stats) => { string leaveChannelMessage = string.Format("onLeaveChannel callback duration {0}, tx: {1}, rx: {2}, tx kbps: {3}, rx kbps: {4}", stats.duration, stats.txBytes, stats.rxBytes, stats.txKBitRate, stats.rxKBitRate); Debug.Log(leaveChannelMessage); mShownMessage.GetComponent <Text> ().text = (leaveChannelMessage); }; mRtcEngine.OnUserJoined += (uint uid, int elapsed) => { string userJoinedMessage = string.Format("onUserJoined callback uid {0} {1}", uid, elapsed); //int a = mRtcEngine.SetRemoteVoicePosition (uid, -1 ,50.0); //Debug.Log ("OnUserJoined setRemoteVoicePosition a = "+ a); AudioEffectManagerImpl audio = new AudioEffectManagerImpl(mRtcEngine); int a = audio.SetRemoteVoicePosition(uid, -1, 0); Debug.Log("OnUserJoined setRemoteVoicePosition = " + a); Debug.Log(userJoinedMessage); }; mRtcEngine.OnUserOffline += (uint uid, USER_OFFLINE_REASON reason) => { string userOfflineMessage = string.Format("onUserOffline callback uid {0} {1}", uid, reason); Debug.Log(userOfflineMessage); }; mRtcEngine.OnVolumeIndication += (AudioVolumeInfo[] speakers, int speakerNumber, int totalVolume) => { if (speakerNumber == 0 || speakers == null) { Debug.Log(string.Format("onVolumeIndication only local {0}", totalVolume)); } for (int idx = 0; idx < speakerNumber; idx++) { string volumeIndicationMessage = string.Format("{0} onVolumeIndication {1} {2}", speakerNumber, speakers [idx].uid, speakers [idx].volume); Debug.Log(volumeIndicationMessage); } }; mRtcEngine.OnUserMuted += (uint uid, bool muted) => { string userMutedMessage = string.Format("onUserMuted callback uid {0} {1}", uid, muted); Debug.Log(userMutedMessage); }; mRtcEngine.OnWarning += (int warn, string msg) => { string description = IRtcEngine.GetErrorDescription(warn); string warningMessage = string.Format("onWarning callback {0} {1} {2}", warn, msg, description); Debug.Log(warningMessage); }; mRtcEngine.OnError += (int error, string msg) => { string description = IRtcEngine.GetErrorDescription(error); string errorMessage = string.Format("onError callback {0} {1} {2}", error, msg, description); Debug.Log(errorMessage); }; mRtcEngine.OnRtcStats += (RtcStats stats) => { string rtcStatsMessage = string.Format("onRtcStats callback duration {0}, tx: {1}, rx: {2}, tx kbps: {3}, rx kbps: {4}, tx(a) kbps: {5}, rx(a) kbps: {6} users {7}", stats.duration, stats.txBytes, stats.rxBytes, stats.txKBitRate, stats.rxKBitRate, stats.txAudioKBitRate, stats.rxAudioKBitRate, stats.users); Debug.Log(rtcStatsMessage); int lengthOfMixingFile = mRtcEngine.GetAudioMixingDuration(); int currentTs = mRtcEngine.GetAudioMixingCurrentPosition(); string mixingMessage = string.Format("Mixing File Meta {0}, {1}", lengthOfMixingFile, currentTs); Debug.Log(mixingMessage); }; mRtcEngine.OnAudioRouteChanged += (AUDIO_ROUTE route) => { string routeMessage = string.Format("onAudioRouteChanged {0}", route); Debug.Log(routeMessage); }; mRtcEngine.OnRequestChannelKey += () => { string requestKeyMessage = string.Format("OnRequestChannelKey"); Debug.Log(requestKeyMessage); }; mRtcEngine.OnConnectionInterrupted += () => { string interruptedMessage = string.Format("OnConnectionInterrupted"); Debug.Log(interruptedMessage); }; mRtcEngine.OnConnectionLost += () => { string lostMessage = string.Format("OnConnectionLost"); Debug.Log(lostMessage); }; mRtcEngine.SetLogFilter(LOG_FILTER.INFO); // mRtcEngine.setLogFile("path_to_file_unity.log"); mRtcEngine.SetChannelProfile(CHANNEL_PROFILE.GAME_FREE_MODE); mRtcEngine.EnableAudio(); // mRtcEngine.SetChannelProfile (CHANNEL_PROFILE.GAME_COMMAND_MODE); // mRtcEngine.SetClientRole (CLIENT_ROLE.BROADCASTER); } }
//Called to join or leave a session. Engine must be loaded first! public void join(string channel) { if (String.IsNullOrEmpty(channel)) { Debug.LogWarning("Empty channel name. Ignoring join request."); return; } loadEngine(AppID); // load engine if (mRtcEngine == null) { return; } Debug.Log("calling join (channel = " + channel + ")"); // set callbacks (optional) mRtcEngine.OnJoinChannelSuccess = onJoinChannelSuccess; mRtcEngine.OnLeaveChannel = onLeaveChannel; mRtcEngine.OnUserJoined = onUserJoined; mRtcEngine.OnUserOffline = onUserOffline; mRtcEngine.OnStreamMessage = onStreamMessage; mRtcEngine.OnRtcStats = onRtcStats; //set timeout timer (optional) if (timeout > 0) { timeoutTimer = timeout; hideWarningLabel(); } //Audio settings if (useAudio) { mRtcEngine.EnableAudio(); // enable audio in general mRtcEngine.EnableLocalAudio(!muteLocalAudio); //controls sending local out HARD STOP mRtcEngine.MuteLocalAudioStream(muteLocalAudio); //still sending, but not audible mRtcEngine.MuteAllRemoteAudioStreams(muteRemoteAudio); //still sending, but not audible mRtcEngine.AdjustRecordingSignalVolume(localVolume); mRtcEngine.AdjustPlaybackSignalVolume(remoteVolume); } else { mRtcEngine.DisableAudio(); } // disable video in general //Begin video feed if (useVideo) { mRtcEngine.EnableVideo(); // enable video in general mRtcEngine.EnableVideoObserver(); mRtcEngine.EnableLocalVideo(!muteLocalVideo); //controls sending local out HARD STOP mRtcEngine.MuteLocalVideoStream(muteLocalVideo); //Send local video to remote? mRtcEngine.MuteAllRemoteVideoStreams(muteRemoteVideo); //still receiving, but not visible //if(muteRemoteVideo) { mRtcEngine.DisableVideoObserver(); } //controls receiving video HARD STOP //else { mRtcEngine.EnableVideoObserver(); } //Change Video feed settings VideoEncoderConfiguration videoConfig = new VideoEncoderConfiguration(); videoConfig.dimensions.width = 1280; videoConfig.dimensions.height = 720; videoConfig.frameRate = FRAME_RATE.FRAME_RATE_FPS_15; mRtcEngine.SetVideoEncoderConfiguration(videoConfig); //WEBCAMS: Show list of all webcam devices mRtcEngine.GetVideoDeviceManager().CreateAVideoDeviceManager(); int deviceCount = mRtcEngine.GetVideoDeviceManager().GetVideoDeviceCount(); Debug.Log("Video device count: " + deviceCount); string deviceName = ""; string deviceId = ""; for (int i = 0; i < deviceCount; i++) //Show list of webcams { mRtcEngine.GetVideoDeviceManager().GetVideoDevice(i, ref deviceName, ref deviceId); Debug.Log("Device[i] deviceName = \"" + deviceName + "\" | deviceId = \"" + deviceId + "\""); } //---Show current video device--- mRtcEngine.GetVideoDeviceManager().GetCurrentVideoDevice(ref deviceId); Debug.Log("CurrentVideoDevice deviceId = \"" + deviceId + "\""); //---Pick the first one?--- mRtcEngine.GetVideoDeviceManager().GetVideoDevice(0, ref deviceName, ref deviceId); mRtcEngine.GetVideoDeviceManager().SetVideoDevice(deviceId); } else { mRtcEngine.DisableVideo(); } // disable video in general //Join Channel UID = mRtcEngine.JoinChannel(channel, null, 0); // join channel // Optional: if a data stream is required, here is a good place to create it. streamID = mRtcEngine.CreateDataStream(true, true); Debug.Log("initializeEngine done, data stream id = " + streamID); //Show local video showLocalVideo(); //Hide Join Button and Show Leave button if assigned joinButton.SetActive(false); leaveButton.SetActive(true); //Hide warning label if still there hideWarningLabel(); }