Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        public Basic()
        {
            ToxOptions options = new ToxOptions(true, false);

            tox = new Tox(options);
            tox.OnFriendRequest += tox_OnFriendRequest;
            tox.OnFriendMessage += tox_OnFriendMessage;

            foreach (ToxNode node in Nodes)
            {
                tox.BootstrapFromNode(node);
            }

            tox.Name          = "SharpTox";
            tox.StatusMessage = "Testing SharpTox";

            tox.Start();

            string id = tox.Id.ToString();

            Console.WriteLine("ID: {0}", id);

            Console.ReadKey();
            tox.Dispose();
        }
Exemplo n.º 3
0
        public void Init()
        {
            if (!File.Exists(DataPath))
            {
                Tox = new Tox(ToxOptions.Default);

                Tox.GetData().Save(DataPath);
            }
            else
            {
                Tox = new Tox(ToxOptions.Default, ToxData.FromDisk(DataPath));
            }

            foreach (var node in Nodes)
            {
                Tox.Bootstrap(node);
            }

            BindEvents();
            PopulateList();

            Tox.Start();

            Tox.StatusMessage = "Toxing on Detox";
        }
Exemplo n.º 4
0
        public FriendListEntryViewModel(Tox tox, uint friendNumber)
        {
            //var publicKey = tox.GetFriendPublicKey(friendNumber);
            var status = tox.Events().Friends.StatusChanged
                         .Where(x => x.FriendNumber == friendNumber)
                         .Select(x => x.Status);

            status.Select(x => x == ToxUserStatus.Away)
            .ToPropertyEx(this, x => x.IsAway);

            status.Select(x => x == ToxUserStatus.Busy)
            .ToPropertyEx(this, x => x.IsBusy);

            tox.Events().Friends.NameChanged
            .Where(x => x.FriendNumber == friendNumber)
            .Select(x => x.Name)
            .StartWith(tox.GetFriendName(friendNumber, out _))
            .ToPropertyEx(this, x => x.Name);

            tox.Events().Friends.StatusMessageChanged
            .Where(x => x.FriendNumber == friendNumber)
            .Select(x => x.StatusMessage)
            .StartWith(tox.GetFriendStatusMessage(friendNumber, out _))
            .ToPropertyEx(this, x => x.StatusMessage);

            this.Remove       = ReactiveCommand.Create(() => friendNumber);
            this.Conversation = new FriendConversationViewModel(tox, friendNumber);
        }
Exemplo n.º 5
0
        public override void Kill(bool finished)
        {
            if (_stream != null)
            {
                _stream.Dispose();
            }

            if (finished)
            {
                Finished = true;
                if (Tag != null)
                {
                    Tag.HideAllButtons();
                }
            }
            else
            {
                Tox.FileControl(FriendNumber, FileNumber, ToxFileControl.Cancel);

                if (Tag != null)
                {
                    Tag.HideAllButtons();
                    Tag.SetStatus(FileName + " - Transfer killed");
                }
            }
        }
Exemplo n.º 6
0
        public override void Kill(bool finished)
        {
            if (_stream != null)
            {
                _stream.Dispose();
            }

            if (finished)
            {
                //Tox.FileSendControl(FriendNumber, FileNumber, ToxFileControl., new byte[0]);
                Finished = true;

                if (Tag != null)
                {
                    Tag.Dispatcher.BeginInvoke(((Action)(() =>
                    {
                        Tag.AcceptButton.Visibility = Visibility.Collapsed;
                        Tag.DeclineButton.Visibility = Visibility.Collapsed;
                        Tag.PauseButton.Visibility = Visibility.Collapsed;
                        Tag.FileOpenButton.Visibility = Visibility.Visible;
                        Tag.FolderOpenButton.Visibility = Visibility.Visible;
                    })));
                }
            }
            else
            {
                Tox.FileControl(FriendNumber, FileNumber, ToxFileControl.Cancel);

                if (Tag != null)
                {
                    Tag.HideAllButtons();
                    Tag.SetStatus(FileName + " - Transfer killed");
                }
            }
        }
Exemplo n.º 7
0
        public FriendListViewModel(Tox tox)
        {
            var friends = new SourceList <uint>();

            foreach (var friend in tox.Friends)
            {
                friends.Add(friend);
                tox.AddFriendNoRequest(tox.GetFriendPublicKey(friend, out _), out _);
            }

            this.Add = ReactiveCommand.Create <uint>(friendNumber =>
            {
                friends.Add(friendNumber);
            });

            ReadOnlyObservableCollection <FriendListEntryViewModel> entries;

            friends.Connect()
            .Transform(number => new FriendListEntryViewModel(tox, number))
            .Bind(out entries)
            .Subscribe();

            this.Friends = entries;

            this.Friends.ToObservableChangeSet()
            .MergeMany(x => x.Remove)
            .Subscribe(number =>
            {
                if (tox.DeleteFriend(number, out _))
                {
                    friends.Remove(number);
                }
            });
        }
Exemplo n.º 8
0
        public ProfileInfo CreateNew(string profileName)
        {
            string path = Path.Combine(ProfileDataPath, profileName + ".tox");

            if (File.Exists(path))
            {
                return(null);
            }

            var tox = new Tox(ToxOptions.Default);

            tox.Name          = profileName;
            tox.StatusMessage = "Toxing on Toxy";

            try
            {
                if (!Directory.Exists(ProfileDataPath))
                {
                    Directory.CreateDirectory(ProfileDataPath);
                }
            }
            catch { return(null); }

            if (!tox.GetData().Save(path))
            {
                return(null);
            }

            tox.Dispose();
            return(new ProfileInfo(path));
        }
Exemplo n.º 9
0
        public void TestToxEncryptionLoad()
        {
            var tox1 = new Tox(ToxOptions.Default);

            tox1.Name          = "Test";
            tox1.StatusMessage = "Hey";

            string password = "******";
            var    data     = tox1.GetData(password);

            Assert.IsNotNull(data, "Failed to encrypt the Tox data");
            Assert.IsTrue(data.IsEncrypted, "We encrypted the data, but toxencryptsave thinks we didn't");

            var tox2 = new Tox(ToxOptions.Default, ToxData.FromBytes(data.Bytes), password);

            if (tox2.Id != tox1.Id)
            {
                Assert.Fail("Failed to load tox data correctly, tox id's don't match");
            }

            if (tox2.Name != tox1.Name)
            {
                Assert.Fail("Failed to load tox data correctly, names don't match");
            }

            if (tox2.StatusMessage != tox1.StatusMessage)
            {
                Assert.Fail("Failed to load tox data correctly, status messages don't match");
            }

            tox1.Dispose();
            tox2.Dispose();
        }
Exemplo n.º 10
0
        public void TestToxIsDataEncrypted()
        {
            var tox  = new Tox(ToxOptions.Default);
            var data = tox.GetData();

            Assert.IsFalse(data.IsEncrypted);
        }
Exemplo n.º 11
0
        public ProfileInfo CreateNew(string userName, string statusMessage)
        {
            string profilePath = Path.Combine(ProfileDataPath, userName + ProfileInfo.DotExt);

            if (File.Exists(profilePath))
            {
                Logger.Log(LogLevel.Warning, "Attempt to override existing profile: " + userName);
                return(null);
            }

            using (Tox tox = new Tox(ToxOptions.Default))
            {
                tox.Name          = userName;
                tox.StatusMessage = statusMessage;

                try
                {
                    if (!Directory.Exists(ProfileDataPath))
                    {
                        Directory.CreateDirectory(ProfileDataPath);
                    }
                }
                catch
                {
                    return(null);
                }

                if (!tox.GetData().Save(profilePath))
                {
                    return(null);
                }
            }

            return(new ProfileInfo(profilePath));
        }
Exemplo n.º 12
0
        public void TestToxLoadData()
        {
            var tox1 = new Tox(ToxOptions.Default);

            tox1.Name          = "Test";
            tox1.StatusMessage = "Hey";

            var data = tox1.GetData();
            var tox2 = new Tox(ToxOptions.Default, ToxData.FromBytes(data.Bytes));

            if (tox2.Id != tox1.Id)
            {
                Assert.Fail("Failed to load tox data correctly, tox id's don't match");
            }

            if (tox2.Name != tox1.Name)
            {
                Assert.Fail("Failed to load tox data correctly, names don't match");
            }

            if (tox2.StatusMessage != tox1.StatusMessage)
            {
                Assert.Fail("Failed to load tox data correctly, status messages don't match");
            }

            tox1.Dispose();
            tox2.Dispose();
        }
Exemplo n.º 13
0
        public static FileTransfer AddNewFileTransfer(this FlowDocument doc, Tox tox, int friendnumber, int filenumber, string filename, ulong filesize, bool is_sender)
        {
            var fileTableCell       = new TableCell();
            var fileTransferControl = new FileTransferControl(tox.GetName(friendnumber), friendnumber, filenumber, filename, filesize, fileTableCell);
            var transfer            = new FileTransfer()
            {
                FriendNumber = friendnumber, FileNumber = filenumber, FileName = filename, FileSize = filesize, IsSender = is_sender, Control = fileTransferControl
            };

            var usernameParagraph = new Section();
            var newTableRow       = new TableRow();

            newTableRow.Tag = transfer;

            var fileTransferContainer = new BlockUIContainer();

            fileTransferControl.HorizontalAlignment        = HorizontalAlignment.Stretch;
            fileTransferControl.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            fileTransferContainer.Child = fileTransferControl;

            usernameParagraph.Blocks.Add(fileTransferContainer);
            usernameParagraph.Padding = new Thickness(0);


            fileTableCell.ColumnSpan = 3;
            fileTableCell.Blocks.Add(usernameParagraph);
            newTableRow.Cells.Add(fileTableCell);
            fileTableCell.Padding = new Thickness(0, 10, 0, 10);

            var MessageRows = (TableRowGroup)doc.FindName("MessageRows");

            MessageRows.Rows.Add(newTableRow);

            return(transfer);
        }
Exemplo n.º 14
0
        public static FileTransferControl AddNewFileTransfer(this FlowDocument doc, Tox tox, FileTransfer transfer)
        {
            var fileTableCell       = new TableCell();
            var fileTransferControl = new FileTransferControl(transfer, fileTableCell);

            var usernameParagraph = new Section();
            var newTableRow       = new TableRow();

            newTableRow.Tag = transfer;

            var fileTransferContainer = new BlockUIContainer();

            fileTransferControl.HorizontalAlignment        = HorizontalAlignment.Stretch;
            fileTransferControl.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            fileTransferContainer.Child = fileTransferControl;

            usernameParagraph.Blocks.Add(fileTransferContainer);
            usernameParagraph.Padding = new Thickness(0);


            fileTableCell.ColumnSpan = 3;
            fileTableCell.Blocks.Add(usernameParagraph);
            newTableRow.Cells.Add(fileTableCell);
            fileTableCell.Padding = new Thickness(0, 10, 0, 10);

            var MessageRows = (TableRowGroup)doc.FindName("MessageRows");

            MessageRows.Rows.Add(newTableRow);

            return(fileTransferControl);
        }
Exemplo n.º 15
0
        public IncomingFileTransfer(ToxEventArgs.FileSendRequestEventArgs e, Tox tox, string savepath)
        {
            Tox = tox;

            ViewModel.SavePath   = savepath;
            ViewModel.ID         = e.FileNumber;
            ViewModel.Sender     = e.FriendNumber;
            ViewModel.TotalBytes = e.FileSize;

            try
            {
                FileStream = new FileStream(ViewModel.SavePath, FileMode.Create);
            }
            catch
            {
                Dispose();
            }

            Tox.FileControl(ViewModel.Sender, ViewModel.ID, ToxFileControl.Resume);

            Tox.OnFileChunkReceived   += Tox_OnFileChunkReceived;
            Tox.OnFileControlReceived += Tox_OnFileControlReceived;

            OnComplete += (v) => { Dispose(); };
        }
Exemplo n.º 16
0
        public void SwitchProfile(Tox tox, ToxAv toxAv)
        {
            _tox = tox;

            _tox.OnConnectionStatusChanged       += Tox_OnConnectionStatusChanged;
            _tox.OnFriendConnectionStatusChanged += Tox_OnFriendConnectionStatusChanged;
        }
Exemplo n.º 17
0
 public ReceiveFile()
 {
     _tox = new Tox(new ToxOptions(true, false));
     _tox.OnFileControl     += tox_OnFileControl;
     _tox.OnFileData        += tox_OnFileData;
     _tox.OnFileSendRequest += tox_OnFileSendRequest;
     _tox.Start();
 }
Exemplo n.º 18
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);
 }
Exemplo n.º 19
0
        public SendFile()
        {
            _tox = new Tox(new ToxOptions(true, false));
            _tox.OnFileControl += tox_OnFileControl;
            _tox.Start();

            int fileNumber = _tox.NewFileSender(0, 1337, "file.dat");
        }
Exemplo n.º 20
0
        public ToxCall(Tox tox, ToxAv toxav, int callindex, int friendnumber)
        {
            this.tox          = tox;
            this.toxav        = toxav;
            this.FriendNumber = friendnumber;

            CallIndex = callindex;
        }
Exemplo n.º 21
0
        public ToxEventObservables(Tox tox, IScheduler scheduler)
        {
            this.tox       = tox ?? throw new ArgumentNullException(nameof(tox));
            this.scheduler = scheduler ?? throw new ArgumentNullException(nameof(scheduler));

            this.Friends    = new ToxFriendObservables(tox, scheduler);
            this.Files      = new ToxFileObservables(tox, scheduler);
            this.Conference = new ToxConferenceObservables(tox, scheduler);
        }
Exemplo n.º 22
0
        public void SwitchProfile(Tox tox, ToxAv toxAv)
        {
            _tox   = tox;
            _toxAv = toxAv;

            _tox.OnFriendMessageReceived += Tox_OnFriendMessageReceived;
            _tox.OnGroupMessage          += Tox_OnGroupMessage;
            _tox.OnGroupAction           += Tox_OnGroupAction;
        }
Exemplo n.º 23
0
        public FriendAddViewModel(Tox tox)
        {
            if (tox == null)
            {
                throw new ArgumentNullException(nameof(tox));
            }

            this.Add = ReactiveCommand.Create(() => tox.AddFriend(new ToxId(this.ID), this.Message, out _), this.WhenAnyValue(x => x.ID, (string id) => ToxId.IsValid(id)));
        }
Exemplo n.º 24
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();
        }
Exemplo n.º 25
0
 public FileTransfer(Tox tox, int fileNumber, int friendNumber, ToxFileKind kind, long fileSize, string fileName, string path)
 {
     Tox          = tox;
     FileNumber   = fileNumber;
     FriendNumber = friendNumber;
     Kind         = kind;
     FileSize     = fileSize;
     FileName     = fileName;
     Path         = path;
 }
Exemplo n.º 26
0
        public void Remove(Tox tox, EventHandler <TEventArgs> handler)
        {
            if ([email protected]().Length == 1)
            {
                this.register(tox.Handle, null);
                this.tDelegate = null;
            }

            this.@event -= handler;
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        public void TestToxId()
        {
            var tox   = new Tox(ToxOptions.Default);
            var toxId = new ToxId(tox.Id.PublicKey.GetBytes(), tox.Id.Nospam);

            if (toxId != tox.Id)
            {
                Assert.Fail("Tox id's are not equal");
            }
        }
Exemplo n.º 29
0
        public void InitManager(Tox tox, ToxAv toxAv)
        {
            if (tox == null)
            {
                throw new ArgumentNullException("tox");
            }

            this.tox = tox;
            this.tox.OnConnectionStatusChanged += this.OnToxConnectionStatusChanged;
        }
Exemplo n.º 30
0
        public static void AddNewMessageRow(this FlowDocument document, Tox tox, MessageData data)
        {
            document.IsEnabled = true;

            //Make a new row
            TableRow newTableRow = new TableRow();

            //Make a new cell and create a paragraph in it
            TableCell usernameTableCell = new TableCell();

            usernameTableCell.Name    = "usernameTableCell";
            usernameTableCell.Padding = new Thickness(10, 0, 0, 0);

            Paragraph usernameParagraph = new Paragraph();

            usernameParagraph.TextAlignment = data.IsAction ? TextAlignment.Right : TextAlignment.Left;
            usernameParagraph.Foreground    = new SolidColorBrush(Color.FromRgb(164, 164, 164));

            if (data.Username != tox.GetSelfName())
            {
                usernameParagraph.SetResourceReference(Paragraph.ForegroundProperty, "AccentColorBrush");
            }

            usernameParagraph.Inlines.Add(data.Username);
            usernameTableCell.Blocks.Add(usernameParagraph);

            //Make a new cell and create a paragraph in it
            TableCell messageTableCell = new TableCell();
            Paragraph messageParagraph = new Paragraph();

            messageParagraph.TextAlignment = TextAlignment.Left;

            ProcessMessage(data, messageParagraph, false);

            //messageParagraph.Inlines.Add(fakeHyperlink);
            messageTableCell.Blocks.Add(messageParagraph);

            TableCell timestampTableCell = new TableCell();
            Paragraph timestamParagraph  = new Paragraph();

            timestampTableCell.TextAlignment = TextAlignment.Right;
            timestamParagraph.Inlines.Add(DateTime.Now.ToShortTimeString());
            timestampTableCell.Blocks.Add(timestamParagraph);
            timestamParagraph.Foreground = new SolidColorBrush(Color.FromRgb(164, 164, 164));
            //Add the two cells to the row we made before
            newTableRow.Cells.Add(usernameTableCell);
            newTableRow.Cells.Add(messageTableCell);
            newTableRow.Cells.Add(timestampTableCell);

            //Adds row to the Table > TableRowGroup
            TableRowGroup MessageRows = (TableRowGroup)document.FindName("MessageRows");

            MessageRows.Rows.Add(newTableRow);
        }