public TextSecureMessagePipe(WebSocketConnection websocket, CredentialsProvider credentialsProvider) { this.websocket = websocket; this.websocket.MessageReceived += OnMessageReceived; this.credentialsProvider = credentialsProvider; this.websocket.connect(); }
private void OnMessageReceived(WebSocketConnection sender, WebSocketRequestMessage request) { WebSocketResponseMessage response = createWebSocketResponse(request); Debug.WriteLine($"Verb: {request.Verb}, Path {request.Path}, Body({request.Body.Length}): {request.Body}, Id: {request.Id}"); try { if (isTextSecureEnvelope(request)) { TextSecureEnvelope envelope = new TextSecureEnvelope(request.Body.ToByteArray(), credentialsProvider.GetSignalingKey()); MessageReceived(this, envelope); } } //catch (Exception e) { } // ignore for now finally { websocket.sendResponse(response); } }
/** * Retrieves a TextSecure attachment. * * @param pointer The {@link org.whispersystems.textsecure.api.messages.TextSecureAttachmentPointer} * received in a {@link TextSecureDataMessage}. * @param destination The download destination for this attachment. * * @return An InputStream that streams the plaintext attachment contents. * @throws IOException * @throws InvalidMessageException */ /*public IInputStream retrieveAttachment(TextSecureAttachmentPointer pointer, File destination) { socket.retrieveAttachment(pointer.getRelay().orNull(), pointer.getId(), destination); return new AttachmentCipherInputStream(destination, pointer.getKey()); }*/ /** * Creates a pipe for receiving TextSecure messages. * * Callers must call {@link TextSecureMessagePipe#shutdown()} when finished with the pipe. * * @return A TextSecureMessagePipe for receiving TextSecure messages. */ public TextSecureMessagePipe createMessagePipe() { WebSocketConnection webSocket = new WebSocketConnection(url, trustStore, credentialsProvider, userAgent); return new TextSecureMessagePipe(webSocket, credentialsProvider); }