示例#1
0
        public void SwitchProfile(Tox tox, ToxAv toxAv)
        {
            _tox = tox;

            _tox.OnConnectionStatusChanged       += Tox_OnConnectionStatusChanged;
            _tox.OnFriendConnectionStatusChanged += Tox_OnFriendConnectionStatusChanged;
        }
示例#2
0
        public void InitManager(Tox tox, ToxAv toxAv)
        {
            if (tox == null)
            {
                throw new ArgumentNullException("tox");
            }

            if (toxAv == null)
            {
                throw new ArgumentNullException("toxAv");
            }

            this.cpuHasSsse3 = VideoUtils.CpuHasSsse3;

            this.tox = tox;
            this.tox.OnFriendConnectionStatusChanged += this.OnToxFriendConnectionStatusChanged;

            this.toxAv = toxAv;
            this.toxAv.OnBitrateSuggestion   += this.OnToxAvBitrateSuggestion;
            this.toxAv.OnCallRequestReceived += this.OnToxAvCallRequestReceived;
            this.toxAv.OnCallStateChanged    += this.OnToxAvCallStateChanged;
            this.toxAv.OnAudioFrameReceived  += this.OnToxAvAudioFrameReceived;
            this.toxAv.OnVideoFrameReceived  += this.OnToxAvVideoFrameReceived;
            this.toxAv.OnReceivedGroupAudio  += this.OnToxAvReceivedGroupAudio;
        }
示例#3
0
文件: ToxCall.cs 项目: Derrick-/Toxy
        public ToxCall(ToxAv toxav, int callindex, int friendnumber)
        {
            this.toxav        = toxav;
            this.FriendNumber = friendnumber;

            CallIndex = callindex;
        }
示例#4
0
 private void InitManagers(Tox tox, ToxAv toxAv)
 {
     TransferManager     = InitManager(TransferManager, tox, toxAv);
     AvatarManager       = InitManager(AvatarManager, tox, toxAv);
     CallManager         = InitManager(CallManager, tox, toxAv);
     ConnectionManager   = InitManager(ConnectionManager, tox, toxAv);
     NotificationManager = InitManager(NotificationManager, tox, toxAv);
 }
示例#5
0
        public void SetCurrent(ExtendedTox tox)
        {
            _toxAv?.Dispose();

            _toxAv = new ToxAv(tox);

            RegisterHandlers();
        }
示例#6
0
        public void SwitchProfile(Tox tox, ToxAv toxAv)
        {
            _tox   = tox;
            _toxAv = toxAv;

            _tox.OnFriendMessageReceived += Tox_OnFriendMessageReceived;
            _tox.OnGroupMessage          += Tox_OnGroupMessage;
            _tox.OnGroupAction           += Tox_OnGroupAction;
        }
示例#7
0
        public void TestToxAvCallAndAnswer()
        {
            var options = new ToxOptions(true, true);
            var tox1    = new Tox(options);
            var tox2    = new Tox(options);

            var toxAv1 = new ToxAv(tox1);
            var toxAv2 = new ToxAv(tox2);

            bool testFinished = false;

            Task.Run(async() =>
            {
                while (!testFinished)
                {
                    int time1 = tox1.Iterate();
                    int time2 = tox2.Iterate();

                    await Task.Delay(Math.Min(time1, time2));
                }
            });

            tox1.AddFriend(tox2.Id, "hey");
            tox2.AddFriend(tox1.Id, "hey");

            while (tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None)
            {
                Thread.Sleep(10);
            }

            bool answered = false;

            toxAv1.Call(0, 48, 30000);

            toxAv2.OnCallRequestReceived += (sender, e) =>
            {
                var  error2  = ToxAvErrorAnswer.Ok;
                bool result2 = toxAv2.Answer(e.FriendNumber, 48, 30000, out error2);
            };

            toxAv1.OnCallStateChanged += (sender, e) =>
            {
                answered = true;
            };

            while (!answered)
            {
                Thread.Sleep(10);
            }

            testFinished = true;
            toxAv1.Dispose();
            toxAv2.Dispose();
            tox1.Dispose();
            tox2.Dispose();
        }
示例#8
0
        private T InitManager <T>(T mgr, Tox tox, ToxAv toxAv) where T : IToxManager, new()
        {
            if (mgr == null)
            {
                mgr = new T();
            }

            mgr.InitManager(tox, toxAv);
            return(mgr);
        }
示例#9
0
        public void InitManager(Tox tox, ToxAv toxAv)
        {
            if (tox == null)
            {
                throw new ArgumentNullException("tox");
            }

            this.tox = tox;
            this.tox.OnConnectionStatusChanged += this.OnToxConnectionStatusChanged;
        }
示例#10
0
        public void SwitchProfile(Tox tox, ToxAv toxAv)
        {
            _tox   = tox;
            _toxAv = toxAv;

            _toxAv.OnAudioFrameReceived          += ToxAv_OnAudioFrameReceived;
            _toxAv.OnVideoFrameReceived          += ToxAv_OnVideoFrameReceived;
            _toxAv.OnCallStateChanged            += ToxAv_OnCallStateChanged;
            _toxAv.OnCallRequestReceived         += ToxAv_OnCallRequestReceived;
            _toxAv.OnBitrateSuggestion           += ToxAv_OnBitrateSuggestion;
            _tox.OnFriendConnectionStatusChanged += Tox_OnFriendConnectionStatusChanged;
        }
示例#11
0
        //should only be used when the application closes
        public void Dispose()
        {
            if (ToxAv != null)
            {
                ToxAv.Dispose();
            }

            if (Tox != null)
            {
                Tox.Dispose();
            }
        }
示例#12
0
        public void Logout()
        {
            if (Tox != null)
            {
                Tox.Dispose();
            }

            if (ToxAv != null)
            {
                ToxAv.Dispose();
            }

            Config.Instance.ProfilePath = null;
            Config.Instance.Save();
        }
示例#13
0
        private T InitManager <T>(T prop, Tox tox, ToxAv toxAv) where T : IToxManager, new()
        {
            if (prop == null)
            {
                var man = new T();
                man.SwitchProfile(tox, toxAv);
                prop = man;
            }
            else
            {
                prop.SwitchProfile(tox, toxAv);
            }

            return(prop);
        }
示例#14
0
        public void SwitchProfile(Tox tox, ToxAv toxAv)
        {
            //clear all transfers
            for (int i = _transfers.Count() - 1; i >= 0; i--)
            {
                var entry = _transfers.ElementAt(i);
                CancelTransfer(entry.Key);
            }

            _tox = tox;

            _tox.OnFileChunkReceived             += Tox_OnFileChunkReceived;
            _tox.OnFileChunkRequested            += Tox_OnFileChunkRequested;
            _tox.OnFileControlReceived           += Tox_OnFileControlReceived;
            _tox.OnFileSendRequestReceived       += Tox_OnFileSendRequestReceived;
            _tox.OnFriendConnectionStatusChanged += Tox_OnFriendConnectionStatusChanged;
        }
示例#15
0
        public void Init()
        {
            var options = new ToxOptions(true, true);

            _tox1 = new Tox(options);
            _tox2 = new Tox(options);

            _toxAv1 = new ToxAv(_tox1);
            _toxAv2 = new ToxAv(_tox2);

            _tox1.AddFriend(_tox2.Id, "hey");
            _tox2.AddFriend(_tox1.Id, "hey");

            while (_tox1.GetFriendConnectionStatus(0) == ToxConnectionStatus.None)
            {
                DoIterate();
            }

            bool answered = false;

            _toxAv1.Call(0, 48, 3000);

            _toxAv2.OnCallRequestReceived += (sender, e) =>
            {
                var  error2  = ToxAvErrorAnswer.Ok;
                bool result2 = _toxAv2.Answer(e.FriendNumber, 48, 3000, out error2);
            };

            _toxAv1.OnCallStateChanged += (sender, e) =>
            {
                answered = true;
            };

            while (!answered)
            {
                DoIterate();
            }
        }
示例#16
0
文件: ToxCall.cs 项目: TimBo93/Toxy
 public ToxGroupCall(ToxAv toxav, int groupNumber)
     : base(toxav)
 {
     GroupNumber = groupNumber;
 }
示例#17
0
        public void SwitchTo(ProfileInfo profile)
        {
            var options = ToxOptions.Default;

            options.Ipv6Enabled = Config.Instance.EnableIpv6;

            if (Config.Instance.ProxyType != ToxProxyType.None)
            {
                options.UdpEnabled = false;
                options.ProxyType  = Config.Instance.ProxyType;
                options.ProxyHost  = Config.Instance.ProxyAddress;
                options.ProxyPort  = Config.Instance.ProxyPort;
            }
            else
            {
                options.UdpEnabled = Config.Instance.EnableUdp;
            }

            Tox newTox;

            if (profile != null)
            {
                var data = ToxData.FromDisk(profile.Path);
                if (data == null)
                {
                    throw new Exception("Could not load profile.");
                }

                if (data.IsEncrypted)
                {
                    throw new Exception("Data is encrypted, Toxy does not support encrypted profiles yet.");
                }

                newTox = new Tox(options, data);
            }
            else
            {
                newTox = new Tox(options);
            }

            var newToxAv = new ToxAv(newTox);

            InitManagers(newTox, newToxAv);

            if (Tox != null)
            {
                Tox.Dispose();
            }

            if (ToxAv != null)
            {
                ToxAv.Dispose();
            }

            Tox   = newTox;
            ToxAv = newToxAv;

            AvatarManager.Rehash();
            ConnectionManager.DoBootstrap();

            //TODO: move this someplace else and make it configurable
            if (string.IsNullOrEmpty(Tox.Name))
            {
                Tox.Name = "Tox User";
            }
            if (string.IsNullOrEmpty(Tox.StatusMessage))
            {
                Tox.StatusMessage = "Toxing on Toxy";
            }

            Tox.Start();
            ToxAv.Start();

            CurrentProfile = profile;
            MainWindow.Instance.Reload();
        }
示例#18
0
文件: ToxCall.cs 项目: TimBo93/Toxy
 /// <summary>
 /// Dummy. Don't use this.
 /// </summary>
 /// <param name="toxav"></param>
 public ToxCall(ToxAv toxav)
 {
     this.toxav = toxav;
 }
示例#19
0
 private void InitManagers(Tox tox, ToxAv toxAv)
 {
     this.ConnectionManager = this.InitManager(this.ConnectionManager, tox, toxAv);
     this.CallManager       = this.InitManager(this.CallManager, tox, toxAv);
 }
示例#20
0
        public void SwitchTo(ProfileInfo profile)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile");
            }

            ToxOptions options = ToxOptions.Default;

            options.Ipv6Enabled = Config.Instance.EnableIpv6;
            options.UdpEnabled  = Config.Instance.EnableUdp;

            ToxData data = ToxData.FromDisk(profile.Path);

            if (data == null)
            {
                throw new Exception("Could not load profile.");
            }

            Tox   tox   = new Tox(options, data);
            ToxAv toxAv = new ToxAv(tox);

            try
            {
                this.InitManagers(tox, toxAv);
            }
            catch
            {
                toxAv.Dispose();
                tox.Dispose();
                throw;
            }

            if (this.Tox != null)
            {
                this.Tox.Dispose();
                this.Tox = null;
            }

            if (this.ToxAv != null)
            {
                this.ToxAv.Dispose();
                this.ToxAv = null;
            }

            this.Tox   = tox;
            this.ToxAv = toxAv;

            this.Tox.OnFriendRequestReceived         += this.OnToxFriendRequestReceived;
            this.Tox.OnFriendMessageReceived         += this.OnToxFriendMessageReceived;
            this.Tox.OnFriendNameChanged             += this.OnToxFriendNameChanged;
            this.Tox.OnFriendStatusMessageChanged    += this.OnToxFriendStatusMessageChanged;
            this.Tox.OnFriendStatusChanged           += this.OnToxFriendStatusChanged;
            this.Tox.OnFriendTypingChanged           += this.OnToxFriendTypingChanged;
            this.Tox.OnFriendConnectionStatusChanged += this.OnToxFriendConnectionStatusChanged;
            this.Tox.OnReadReceiptReceived           += this.OnToxReadReceiptReceived;

            this.Tox.OnFriendLossyPacketReceived    += this.OnToxFriendLossyPacketReceived;
            this.Tox.OnFriendLosslessPacketReceived += this.OnToxFriendLosslessPacketReceived;

            this.Tox.OnGroupInvite         += this.OnToxGroupInvite;
            this.Tox.OnGroupAction         += this.OnToxGroupAction;
            this.Tox.OnGroupMessage        += this.OnToxGroupMessage;
            this.Tox.OnGroupNamelistChange += this.OnToxGroupNamelistChange;
            this.Tox.OnGroupTitleChanged   += this.OnToxGroupTitleChanged;

            this.Tox.OnFileSendRequestReceived += this.OnToxFileSendRequestReceived;
            this.Tox.OnFileControlReceived     += this.OnToxFileControlReceived;
            this.Tox.OnFileChunkReceived       += this.OnToxFileChunkReceived;
            this.Tox.OnFileChunkRequested      += this.OnToxFileChunkRequested;

            this.CurrentProfile = profile;
        }