Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace infinite retrying by promise-request-retry module #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"dependencies": {
"http_ece": "^1.0.5",
"long": "^3.2.0",
"promise-request-retry": "^1.0.2",
"protobufjs": "^6.8.0",
"request": "^2.81.0",
"request-promise": "^4.2.1",
Expand Down
20 changes: 17 additions & 3 deletions src/gcm/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
const path = require('path');
const request = require('../utils/request');
const request = require('promise-request-retry');
const protobuf = require('protobufjs');
const Long = require('long');
const { waitFor } = require('../utils/timeout');
const fcmKey = require('../fcm/server-key');
const { toBase64 } = require('../utils/base64');


const RETRY_DELAY = 500;
const RETRY_COUNT = 6
const RETRY_FACOR = 2
// Delay after each failed step: 1:500, 2:1000, 3:2000, 4:4000, 5:8000 -> max 15,5sec


// Hack to fix PHONE_REGISTRATION_ERROR #17 when bundled with webpack
// https://github.com/dcodeIO/protobuf.js#browserify-integration
protobuf.util.Long = Long
Expand Down Expand Up @@ -34,14 +41,18 @@ async function checkIn(androidId, securityToken) {
await loadProtoFile();
const buffer = getCheckinRequest(androidId, securityToken);
const body = await request({
url : CHECKIN_URL,
uri : CHECKIN_URL,
method : 'POST',
headers : {
'Content-Type' : 'application/x-protobuf',
},
body : buffer,
encoding : null,
delay: RETRY_DELAY,
factor: RETRY_FACOR,
retry: RETRY_COUNT,
});

const message = AndroidCheckinResponse.decode(body);
const object = AndroidCheckinResponse.toObject(message, {
longs : String,
Expand Down Expand Up @@ -70,13 +81,16 @@ async function doRegister({ androidId, securityToken }, appId) {

async function postRegister({ androidId, securityToken, body, retry = 0 }) {
const response = await request({
url : REGISTER_URL,
uri : REGISTER_URL,
method : 'POST',
headers : {
Authorization : `AidLogin ${androidId}:${securityToken}`,
'Content-Type' : 'application/x-www-form-urlencoded',
},
form : body,
delay: RETRY_DELAY,
factor: RETRY_FACOR,
retry: RETRY_COUNT,
});
if (response.includes('Error')) {
console.warn(`Register request has failed with ${response}`);
Expand Down
27 changes: 0 additions & 27 deletions src/utils/request/index.js

This file was deleted.

Loading