private void OnMessageRecevied(SignalServiceMessagePipe sender, SignalServiceEnvelope envelope) { Log.Debug("Push message recieved"); var task = new PushContentReceiveTask(); task.handle(envelope, false); //throw new NotImplementedException("OnMessageReceived"); }
private void InitNetwork() { MessageReceiver = new SignalServiceMessageReceiver(CancelSource.Token, LibUtils.ServiceUrls, new StaticCredentialsProvider(Store.Username, Store.Password, Store.SignalingKey, (int)Store.DeviceId), LibUtils.USER_AGENT); Pipe = MessageReceiver.createMessagePipe(); MessageSender = new SignalServiceMessageSender(CancelSource.Token, LibUtils.ServiceUrls, Store.Username, Store.Password, (int)Store.DeviceId, new Store(), Pipe, null, LibUtils.USER_AGENT); IncomingMessagesTask = Task.Factory.StartNew(() => new IncomingMessages(CancelSource.Token, Pipe, this).HandleIncomingMessages(), TaskCreationOptions.LongRunning); OutgoingMessagesTask = Task.Factory.StartNew(() => new OutgoingMessages(CancelSource.Token, MessageSender, this).HandleOutgoingMessages(), TaskCreationOptions.LongRunning); }
protected void RunWebsocket() { Task.Factory.StartNew(() => { try { var messageReceiver = TextSecureCommunicationFactory.createReceiver(); pipe = messageReceiver.createMessagePipe(); pipe.MessageReceived += OnMessageRecevied; pipe.ConnectionFailed += OnConnectionFailed; } catch (Exception ex) { Debug.WriteLine("Failed asd:" + ex.Message); } }); }
/// <summary> /// Initializes the websocket connection handling. Must not not be called on a UI thread. Must not be called on a task which holds the handle lock. /// </summary> private async Task InitNetwork() { try { MessageReceiver = new SignalServiceMessageReceiver(LibUtils.ServiceConfiguration, new StaticCredentialsProvider(Store.Username, Store.Password, Store.SignalingKey, (int)Store.DeviceId), LibUtils.USER_AGENT); Pipe = await MessageReceiver.CreateMessagePipe(CancelSource.Token, new SignalWebSocketFactory()); MessageSender = new SignalServiceMessageSender(CancelSource.Token, LibUtils.ServiceConfiguration, Store.Username, Store.Password, (int)Store.DeviceId, new Store(), Pipe, null, LibUtils.USER_AGENT); IncomingMessagesTask = Task.Factory.StartNew(async() => await new IncomingMessages(CancelSource.Token, Pipe, MessageReceiver).HandleIncomingMessages(), TaskCreationOptions.LongRunning); OutgoingMessages = new OutgoingMessages(CancelSource.Token, MessageSender, this); OutgoingMessagesTask = Task.Factory.StartNew(async() => await OutgoingMessages.HandleOutgoingMessages(), TaskCreationOptions.LongRunning); } catch (Exception e) { Logger.LogError("InitNetwork failed: {0}\n{1}", e.Message, e.StackTrace); await HandleAuthFailure(); } }
public IncomingMessages(CancellationToken token, SignalServiceMessagePipe pipe, SignalServiceMessageReceiver messageReceiver) { Token = token; Pipe = pipe; MessageReceiver = messageReceiver; }
public async Task Init() { Debug.WriteLine("Init lock wait"); using (await ActionInProgress.LockAsync(CancelSource.Token)) { Debug.WriteLine("Init lock grabbed"); Running = true; CancelSource = new CancellationTokenSource(); try { await Task.Run(async() => { SignalDBContext.FailAllPendingMessages(); List <SignalContact> contacts = SignalDBContext.GetAllContactsLocked(); List <SignalGroup> groups = SignalDBContext.GetAllGroupsLocked(); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { try { int amountContacts = contacts.Count; int amountGroups = groups.Count; int contactsIdx = 0; int groupsIdx = 0; while (contactsIdx < amountContacts || groupsIdx < amountGroups) { if (contactsIdx < amountContacts) { SignalConversation contact = contacts[contactsIdx]; if (groupsIdx < amountGroups) { SignalConversation group = groups[groupsIdx]; if (contact.LastActiveTimestamp > group.LastActiveTimestamp) { contactsIdx++; AddThread(contact); } else { groupsIdx++; AddThread(group); } } else { contactsIdx++; AddThread(contact); } } else if (groupsIdx < amountGroups) { SignalConversation group = groups[groupsIdx]; groupsIdx++; AddThread(group); } } } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); } }); MessageReceiver = new SignalServiceMessageReceiver(CancelSource.Token, App.ServiceUrls, new StaticCredentialsProvider(App.Store.Username, App.Store.Password, App.Store.SignalingKey, (int)App.Store.DeviceId), App.USER_AGENT); Pipe = MessageReceiver.createMessagePipe(); MessageSender = new SignalServiceMessageSender(CancelSource.Token, App.ServiceUrls, App.Store.Username, App.Store.Password, (int)App.Store.DeviceId, new Store(), Pipe, null, App.USER_AGENT); IncomingMessagesTask = Task.Factory.StartNew(HandleIncomingMessages, TaskCreationOptions.LongRunning); OutgoingMessagesTask = Task.Factory.StartNew(HandleOutgoingMessages, TaskCreationOptions.LongRunning); }); } catch (AuthorizationFailedException) { Debug.WriteLine("OWS server rejected our credentials - redirecting to StartPage"); Running = false; CancelSource.Cancel(); View.Frame.Navigate(typeof(StartPage)); } catch (Exception e) { Debug.WriteLine(e.Message); Debug.WriteLine(e.StackTrace); } } Debug.WriteLine("Init lock released"); }
public IncomingMessages(CancellationToken token, SignalServiceMessagePipe pipe, SignalLibHandle handle) { Token = token; Pipe = pipe; Handle = handle; }