From 714c73e1b5facde193854344bc12c6dddda0a170 Mon Sep 17 00:00:00 2001 From: Ahab Hyde Date: Fri, 19 Oct 2018 10:24:24 +0200 Subject: [PATCH] Added 30 seconds timeout long polling --- src/com/em/miguelbridge/botmatrix/MatrixBot.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/com/em/miguelbridge/botmatrix/MatrixBot.java b/src/com/em/miguelbridge/botmatrix/MatrixBot.java index e287253..e98f8ee 100644 --- a/src/com/em/miguelbridge/botmatrix/MatrixBot.java +++ b/src/com/em/miguelbridge/botmatrix/MatrixBot.java @@ -18,9 +18,14 @@ import javax.imageio.ImageIO; public class MatrixBot { //https://matrix.org/docs/guides/client-server.html private final String homeUrl; - private String accessToken; - + private final int timeoutMs; + + public MatrixBot() throws IOException, FileNotFoundException, ParseException { + homeUrl = getHomeServer(); + timeoutMs = 30 * 1000; //30 seconds + } + public String getAccessToken() { return accessToken; } @@ -29,10 +34,6 @@ public class MatrixBot { this.accessToken = accessToken; } - public MatrixBot() throws IOException, FileNotFoundException, ParseException { - homeUrl = getHomeServer(); - } - public static String readBotUserName() throws FileNotFoundException, IOException, ParseException { FileReader file = new FileReader(Launcher.fileSettings); BufferedReader in = new BufferedReader(file); @@ -240,7 +241,7 @@ public class MatrixBot { try { String filtro = URLEncoder.encode("{\"room\":{\"timeline\":{\"limit\":1}}}", "UTF-8"); String requestUrl = homeUrl + - String.format("client/r0/sync?filter=%s&access_token=%s", + String.format("client/r0/sync?filter=%s&timeout=" + timeoutMs + "&access_token=%s", filtro, accessToken); String[] risposta = RequestHandler.getRequest(requestUrl);