示例#1
0
        // -------------------------------------------

        /*
         * StartVoiceStreaming
         */
        public void StartVoiceStreaming(bool _emitVoice)
        {
            object voiceFoun         = Resources.Load("Voice/Voice Connection and Recorder");
            bool   voiceHasBeenFound = false;

            if (voiceFoun != null)
            {
                GameObject voicePrefab = voiceFoun as GameObject;
                if (voicePrefab != null)
                {
                    voiceHasBeenFound = true;
                    m_voiceGO         = GameObject.Instantiate(voicePrefab);
                    ConnectAndJoin joinVoice = m_voiceGO.transform.GetComponentInChildren <ConnectAndJoin>();
                    m_voiceConnection = GameObject.FindObjectOfType <VoiceConnection>();
                    m_voiceConnection.SpeakerLinked += this.OnSpeakerCreated;
                    if ((joinVoice != null) && (m_voiceConnection != null))
                    {
                        joinVoice.RoomName = PhotonNetwork.CurrentRoom.Name;
                        m_voiceConnection.PrimaryRecorder.TransmitEnabled = _emitVoice;
                        joinVoice.ConnectNow();
                        NetworkEventController.Instance.DispatchLocalEvent(EVENT_PHOTONCONTROLLER_VOICE_CREATED, m_voiceConnection.gameObject.transform);
                    }
                }
            }

            if (!voiceHasBeenFound)
            {
                Debug.LogError("StartVoiceStreaming::PREFAB VOICE NOT FOUND!!!!!!!!!!!!!!!!");
            }
        }
 protected override void Awake()
 {
     base.Awake();
     this.voiceConnection = this.GetComponent <VoiceConnection>();
     this.voiceConnection.RemoteVoiceAdded += this.OnRemoteVoiceAdded;
     this.voiceConnection.SpeakerLinked    += this.OnSpeakerLinked;
 }
示例#3
0
        public static async void ConnectToVoiceChannel(VoiceServerUpdate data)
        {
            string name;

            if (data.GuildId == null)
            {
                data.GuildId = data.ChannelId;
                name         = $"DM - {LocalState.DMs[data.ChannelId].Name}";
            }
            else
            {
                name = $"{LocalState.Guilds[data.GuildId].Raw.Name} - {LocalState.Guilds[data.GuildId].channels[LocalState.VoiceState.ChannelId].raw.Name}";
            }
            App.UpdateLocalDeaf(false);
            App.UpdateVoiceStateHandler += App_UpdateVoiceStateHandler;
            //App.UpdateLocalMute(true); //LocalState.Muted);
            VoiceConnection = new VoiceConnection(data, LocalState.VoiceState);
            VoiceConnection.VoiceDataRecieved += VoiceConnection_VoiceDataRecieved;
            await VoiceConnection.ConnectAsync();

            ConnectoToVoiceHandler?.Invoke(typeof(App), new ConnectToVoiceArgs()
            {
                ChannelId = LocalState.VoiceState.ChannelId, GuildId = data.GuildId
            });
            AudioManager.InputRecieved += AudioManager_InputRecieved;
            if (Storage.Settings.BackgroundVoice)
            {
                VoipCallCoordinator vcc = VoipCallCoordinator.GetDefault();
                voipCall = vcc.RequestNewOutgoingCall("", name, "Quarrel", VoipPhoneCallMedia.Audio);
                voipCall.NotifyCallActive();
            }
        }
 private void Start()
 {
     vc                   = gameObject.GetComponent <VoiceConnection>();
     recorder             = GetComponent <Recorder>();
     recorder.IsRecording = false;
     recorder.Init(vc);
 }
示例#5
0
        private static void AudioManager_InputRecieved(object sender, float[] e)
        {
            double decibels = 0f;

            foreach (var sample in e)
            {
                decibels += Math.Abs(sample);
            }
            decibels = 20 * Math.Log10(decibels / e.Length);
            if (decibels < Storage.Settings.NoiseSensitivity)
            {
                if (hasSentSpeeking && !stopSpeaking)
                {
                    StopSpeaking();
                }
            }
            else
            {
                if (!noiseMuted)
                {
                    stopSpeaking = false;
                    if (!hasSentSpeeking)
                    {
                        VoiceConnection.SendSpeaking(true);
                        hasSentSpeeking = true;
                    }
                    VoiceConnection.SendVoiceData(e);
                }
            }
        }
 protected virtual void OnEnable()
 {
     this.connection            = this.target as VoiceConnection;
     this.updateIntervalSp      = this.serializedObject.FindProperty("updateInterval");
     this.enableSupportLoggerSp = this.serializedObject.FindProperty("enableSupportLogger");
     this.settingsSp            = this.serializedObject.FindProperty("Settings");
     #if !UNITY_ANDROID && !UNITY_IOS
     this.runInBackground = this.serializedObject.FindProperty("runInBackground");
     #endif
     #if !UNITY_IOS
     this.keepAliveInBackgroundSp = this.serializedObject.FindProperty("KeepAliveInBackground");
     #endif
     this.applyDontDestroyOnLoadSp = this.serializedObject.FindProperty("ApplyDontDestroyOnLoad");
     this.statsResetInterval       = this.serializedObject.FindProperty("statsResetInterval");
     this.primaryRecorderSp        = this.serializedObject.FindProperty("primaryRecorder");
     if (this.primaryRecorderSp == null) // [FormerlySerializedAs("PrimaryRecorder")]
     {
         this.primaryRecorderSp = this.serializedObject.FindProperty("PrimaryRecorder");
     }
     this.speakerPrefabSp = this.serializedObject.FindProperty("speakerPrefab");
     this.autoCreateSpeakerIfNotFoundSp = this.serializedObject.FindProperty("AutoCreateSpeakerIfNotFound");
     this.globalRecordersLogLevelSp     = this.serializedObject.FindProperty("globalRecordersLogLevel");
     this.globalSpeakersLogLevelSp      = this.serializedObject.FindProperty("globalSpeakersLogLevel");
     this.globalPlayDelaySettingsSp     = this.serializedObject.FindProperty("globalPlaybackDelaySettings");
 }
示例#7
0
    // Start is called before the first frame update
    void Start()
    {
        voice          = GameObject.FindGameObjectWithTag("Voice").GetComponent <VoiceConnection>();
        userNr         = transform.GetComponent <PhotonView>().ViewID;
        transform.name = "User: "******"GroupManager").GetComponent <GroupManager>();

        groupManager.SetUpGroups();
        SetUserName(transform.name);
        ActivateChat activateChat = GameObject.FindGameObjectWithTag("ChatManager").GetComponent <ActivateChat>();

        activateChat.Activate();
    }
示例#8
0
 private void Awake()
 {
     Screen.SetResolution(this.screenWidth, this.screenHeight, this.fullScreen);
     this.connectAndJoin            = this.GetComponent <ConnectAndJoin>();
     this.voiceConnection           = this.GetComponent <VoiceConnection>();
     this.voiceAudioPreprocessor    = this.voiceConnection.PrimaryRecorder.GetComponent <WebRtcAudioDsp>();
     this.compressionGainGameObject = this.agcCompressionGainSlider.transform.parent.gameObject;
     this.compressionGainText       = this.compressionGainGameObject.GetComponentInChildren <Text>();
     this.aecOptionsGameObject      = this.aecHighPassToggle.transform.parent.gameObject;
     this.SetDefaults();
     this.InitUiCallbacks();
     this.InitUiValues();
     this.GetSavedNickname();
 }
        private async void ConnectToVoiceChannel(VoiceServerUpdate data, VoiceState state)
        {
            voipCall?.NotifyCallEnded();
            VoipCallCoordinator vcc = VoipCallCoordinator.GetDefault();
            var status = await vcc.ReserveCallResourcesAsync("WebRTCBackgroundTask.VoipBackgroundTask");

            // TODO: More info for Mobile
            voipCall = vcc.RequestNewOutgoingCall(string.Empty, string.Empty, "Quarrel", VoipPhoneCallMedia.Audio);
            voipCall.NotifyCallActive();

            voiceConnection        = new VoiceConnection(data, state, webrtcManager);
            voiceConnection.Speak += Speak;
            await voiceConnection.ConnectAsync();
        }
        private void Start()
        {
            // Cache reference
            voiceConnection = GetComponent <VoiceConnection>();
            // Change the default Speaker Factory method for our custom one
            voiceConnection.SpeakerFactory = this.CustomBoltSpeakerFactory;

            // Cache reference
            voiceRecorder = GetComponent <Recorder>();
            // Cache the default Interest Group
            voiceRecorderDefaultGroup = voiceRecorder.InterestGroup;

            // Init the Speaker Registry
            speakerRegistry = new Dictionary <int, BoltVoiceSpeakerController>();
        }
 protected virtual void OnEnable()
 {
     connection            = target as VoiceConnection;
     updateIntervalSp      = serializedObject.FindProperty("updateInterval");
     enableSupportLoggerSp = serializedObject.FindProperty("enableSupportLogger");
     settingsSp            = serializedObject.FindProperty("Settings");
     #if !UNITY_ANDROID && !UNITY_IOS
     runInBackground = serializedObject.FindProperty("runInBackground");
     #endif
     #if !UNITY_IOS
     keepAliveInBackgroundSp = serializedObject.FindProperty("KeepAliveInBackground");
     #endif
     applyDontDestroyOnLoadSp = serializedObject.FindProperty("ApplyDontDestroyOnLoad");
     primaryRecorderSp        = serializedObject.FindProperty("PrimaryRecorder");
     statsResetInterval       = serializedObject.FindProperty("statsResetInterval");
 }
示例#12
0
        internal async Task ConnectToStream()
        {
            _voiceConnection = new VoiceConnection(
                unhandledMessageEncountered: e => _client.LogException(ClientLogEvent.VoiceExceptionHandled, e),
                knownOperationEncountered: e => _client.LogOperation(ClientLogEvent.KnownVoiceOperationEncountered, (int)e),
                unhandledOperationEncountered: e => _client.LogOperation(ClientLogEvent.UnhandledVoiceOperationEncountered, (int)e),
                unknownOperationEncountered: e => _client.LogOperation(ClientLogEvent.UnknownVoiceOperationEncountered, e),
                voiceConnectionStatusChanged: _ => { },
                ready: OnReady,
                sessionDescription: OnSessionDescription,
                speaking: OnSpeaking,
                video: OnVideo);

            await _voiceConnection.ConnectAsync(_connectionUrl);

            await _voiceConnection.IdentifySelfToVoiceConnection(_serverId, _sessionId, _token, _userId, true, new VoiceIdentity.VoiceIdentityStream[] { new() { Quality = 100, Rid = "100", Type = "video" } });
示例#13
0
 private static async void StopSpeaking()
 {
     stopSpeaking = true;
     if (!noiseMuted)
     {
         await Task.Delay(2000);
     }
     lock (syncLock)
     {
         if (stopSpeaking)
         {
             VoiceConnection.SendSpeaking(false);
             hasSentSpeeking = false;
             stopSpeaking    = false;
         }
     }
 }
 public void OnEnable()
 {
     VoiceConnection[] voiceConnections = this.GetComponents <VoiceConnection>();
     if (voiceConnections == null || voiceConnections.Length == 0)
     {
         Debug.LogError("No VoiceConnection component found, PhotonVoiceStatsGui disabled", this);
         this.enabled = false;
         return;
     }
     if (voiceConnections.Length > 1)
     {
         Debug.LogWarningFormat(this, "Multiple VoiceConnection components found, using first occurrence attached to GameObject {0}", voiceConnections[0].name);
     }
     this.voiceConnection  = voiceConnections[0];
     this.peer             = this.voiceConnection.Client.LoadBalancingPeer;
     this.debugLostPercent = this.voiceConnection.VoiceClient.DebugLostPercent;
 }
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            AppServiceDeferral deferral = args.GetDeferral();
            ValueSet           message  = args.Request.Message;

            switch (message["type"])
            {
            case "connect":
            {
                VoiceServerUpdate data  = JsonConvert.DeserializeObject <VoiceServerUpdate>(message["config"] as string);
                VoiceState        state = JsonConvert.DeserializeObject <VoiceState>(message["state"] as string);
                webrtcManager.SetRecordingDevice(message["inputId"] as string);
                webrtcManager.SetPlaybackDevice(message["outputId"] as string);
                ConnectToVoiceChannel(data, state);
            }
            break;

            case "disconnect":
                webrtcManager.Destroy();
                voipCall?.NotifyCallEnded();
                voipCall        = null;
                voiceConnection = null;
                break;

            case "voiceStateUpdate":
            {
                // Todo: handle here
                VoiceState state = JsonConvert.DeserializeObject <VoiceState>(message["state"] as string);
            }
            break;

            case "inputDevice":
                webrtcManager.SetRecordingDevice(message["id"] as string);
                break;

            case "outputDevice":
                webrtcManager.SetPlaybackDevice(message["id"] as string);
                break;
            }
            deferral.Complete();
        }
示例#16
0
        private static void OnProjectChanged()
        {
            if (speaker == null)
            {
                speaker = (GameObject)Resources.Load("Speaker");
            }

            if (speaker == null)
            {
                GameObject speaker = new GameObject();
                speaker.AddComponent <AudioSource>();
                speaker.AddComponent <Speaker>();
                PrefabUtility.SaveAsPrefabAsset(speaker, ResourcesFolderPath + "Speaker.prefab");
                Object.DestroyImmediate(speaker);
            }

            if (voiceController == null)
            {
                voiceController = (GameObject)Resources.Load("VoiceController");
            }

            if (voiceController == null)
            {
                GameObject             voiceController        = new GameObject();
                VoiceConnection        voiceConnection        = voiceController.AddComponent <VoiceConnection>();
                Recorder               recorder               = voiceController.AddComponent <Recorder>();
                PhotonVoiceChatManager photonVoiceChatManager = voiceController.AddComponent <PhotonVoiceChatManager>();
                recorder.TransmitEnabled = true;

                voiceConnection.PrimaryRecorder = recorder;
                voiceConnection.SpeakerPrefab   = speaker;

                string AppIdVoice = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice;
                PrefabUtility.SaveAsPrefabAsset(voiceController, ResourcesFolderPath + "VoiceController.prefab");
                Object.DestroyImmediate(voiceController);
            }
        }
示例#17
0
 private void Awake()
 {
     voiceConnection = GetComponent <VoiceConnection>();
 }
示例#18
0
 private void Awake()
 {
     this.voiceConnection = this.GetComponent <VoiceConnection>();
     this.InitToggles();
 }
 public void Start()
 {
     this.voiceConnection = this.GetComponent <VoiceConnection>();
     this.Peer            = voiceConnection.Client.LoadBalancingPeer;
 }
示例#20
0
 public virtual void Init(VoiceConnection vC)
 {
     this.voiceConnection = vC;
     this.voiceConnection.Client.AddCallbackTarget(this);
 }
示例#21
0
 private void Awake()
 {
     voiceConnection = this.GetComponent <VoiceConnection>();
     voiceConnection.SpeakerLinked += SpeakerLinkOn;
 }
示例#22
0
 void Awake()
 {
     voiceConnection = GetComponent <VoiceConnection>();
     GetComponent <ConnectAndJoin>().RoomName = NetworkManager.Instance.roomName;
 }
示例#23
0
 private void Awake()
 {
     voiceConnection = GetComponent <VoiceConnection>();
     voiceConnection.Settings.AppVersion = PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion;
     voiceConnection.Settings.AppIdVoice = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice;
 }