esoftplay 0.0.111-y → 0.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/modules/lib/curl.ts +71 -58
  2. package/package.json +1 -1
@@ -167,33 +167,30 @@ export default class ecurl {
167
167
  }
168
168
  let ps = Object.keys(_post).map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(_post[key])).join('&');
169
169
  var options: any = {
170
- url: this.url + this.uri + (token_uri || 'get_token'),
170
+ signal: this.signal,
171
171
  method: "POST",
172
- cancelToken: this.abort.token,
173
- transformResponse: [(data) => { return data; }],
174
172
  headers: {
175
173
  ...this.header,
176
174
  ["Content-Type"]: "application/x-www-form-urlencoded;charset=UTF-8"
177
175
  },
178
- data: ps,
176
+ body: ps,
179
177
  cache: "no-store",
180
178
  _post: _post
181
179
  }
182
- this.initTimeout();
183
- axios(options).then(async (res: any) => {
184
- this.cancelTimeout();
185
- let resText = res.data;
180
+ fetch(this.url + this.uri + (token_uri || 'get_token'), options).then(async (res) => {
181
+ let resText = await res.text()
186
182
  this.onFetched(resText,
187
183
  (res, msg) => {
188
184
  this.init(uri, { ...post, access_token: res }, onDone, onFailed, debug);
189
185
  }, (msg) => {
190
186
  if (onFailed)
191
- onFailed(this.refineErrorMessage(msg), false)
187
+ onFailed(msg, false)
192
188
  }, debug)
193
- }).catch((r: string) => {
194
- this.cancelTimeout();
195
- LibToastProperty.show("Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi")
189
+ }).catch((r) => {
196
190
  LibProgress.hide()
191
+ this.onFetchFailed(r)
192
+ // if (onFailed)
193
+ // onFailed(r, true)
197
194
  })
198
195
  }
199
196
  }
@@ -289,7 +286,6 @@ export default class ecurl {
289
286
  }
290
287
  await this.setHeader()
291
288
  var options: any = {
292
- url: this.url + this.uri,
293
289
  signal: this.signal,
294
290
  method: !this.post ? "GET" : "POST",
295
291
  headers: {
@@ -313,14 +309,39 @@ export default class ecurl {
313
309
  if (onDone) onDone(resJson, false)
314
310
  this.onDone(resJson)
315
311
  } else {
312
+ // Alert.alert(this.alertTimeout.title, this.alertTimeout.message, [
313
+ // {
314
+ // text: this.alertTimeout.ok,
315
+ // style: 'cancel',
316
+ // onPress: () => this.custom(uri, post, onDone, debug)
317
+ // },
318
+ // {
319
+ // text: this.alertTimeout.cancel,
320
+ // style: 'destructive',
321
+ // onPress: () => { }
322
+ // }
323
+ // ])
316
324
  this.onFetchFailed(resText)
317
325
  LibProgress.hide()
318
326
  this.onError(resText)
319
327
  }
320
328
  }).catch((e) => {
321
- this.onError(e)
322
329
  LibProgress.hide()
330
+ // Alert.alert(this.alertTimeout.title, this.alertTimeout.message, [
331
+ // {
332
+ // text: this.alertTimeout.ok,
333
+ // style: 'cancel',
334
+ // onPress: () => this.custom(uri, post, onDone, debug)
335
+ // },
336
+ // {
337
+ // text: this.alertTimeout.cancel,
338
+ // style: 'destructive',
339
+ // onPress: () => { }
340
+ // }
341
+ // ])
323
342
  this.onFetchFailed(e)
343
+ // if (onDone)
344
+ // onDone(e, true)
324
345
  })
325
346
  }
326
347
  }
@@ -354,23 +375,18 @@ export default class ecurl {
354
375
  if (!upload)
355
376
  this.header["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8"
356
377
  var options: any = {
357
- url: this.url + this.uri,
378
+ signal: this.signal,
358
379
  method: !this.post ? "GET" : "POST",
359
380
  headers: this.header,
360
- transformResponse: [(data) => { return data; }],
361
- data: !this.post ? undefined : this.post,
362
- cancelToken: this.abort.token,
381
+ body: this.post,
363
382
  cache: "no-store",
364
-
365
383
  Pragma: "no-cache",
366
384
  ["Cache-Control"]: 'no-cache, no-store, must-revalidate',
367
385
  ["Expires"]: 0,
368
386
  mode: "cors",
369
387
  _post: post
370
388
  }
371
- if (debug == 1) {
372
- esp.log(this.url + this.uri, { ...options, cancelToken: undefined })
373
- }
389
+
374
390
 
375
391
  if (manifest?.packagerOpts?.dev && LogStateProperty) {
376
392
  const allData = LogStateProperty.state().get() || []
@@ -429,45 +445,42 @@ export default class ecurl {
429
445
  }
430
446
  }
431
447
 
432
- this.fetchConf = { url: this.url + this.uri, options: options }
433
448
  this.initTimeout(upload ? 120000 : undefined)
434
- axios(options).then(async (res: any) => {
435
- this.cancelTimeout()
436
- this.onFetched(res.data, onDone, onFailed, debug)
437
- }).catch((error: any) => {
438
- this.cancelTimeout()
439
-
440
- if (error.response) {
441
- /*
442
- * The request was made and the server responded with a
443
- * status code that falls out of the range of 2xx
444
- */
445
- console.log(error.response.data);
446
- console.log(error.response.status);
447
- console.log(error.response.headers);
448
- this.onError(JSON.stringify(error.response))
449
- LibToastProperty.show('Terjadi kesalahan, biar ' + esp.appjson()?.expo?.name + ' bereskan, silahkan coba beberapa saat lagi atau kembali ke halaman utama')
450
- } else if (error.request) {
451
- /*
452
- * The request was made but no response was received, `error.request`
453
- * is an instance of XMLHttpRequest in the browser and an instance
454
- * of http.ClientRequest in Node.js
455
- */
456
-
457
- if (this.maxRetry > 0) {
458
- this.init(uri, post, onDone, onFailed, debug)
459
- this.maxRetry = this.maxRetry - 1
460
- } else {
461
- LibToastProperty.show("Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi")
462
- console.log(error.request);
463
- }
464
- } else {
465
- // Something happened in setting up the request and triggered an Error
466
- this.onError(JSON.stringify(error.message))
467
- console.log('Error', error.message);
468
- }
449
+ if (debug == 1) esp.log(this.url + this.uri, options)
450
+ this.fetchConf = { url: this.url + this.uri, options: options }
451
+
452
+ // if (Platform.OS == 'android' && Platform.Version <= 22) {
453
+ // var res = await fetch(this.url + this.uri, options);
454
+ // let resText = await res.text()
455
+ // this.onFetched(resText, onDone, onFailed, debug)
456
+ // } else
457
+ // if (!upload) {
458
+ // LibWorker.curl(this.url + this.uri, options, async (resText) => {
459
+ // if (typeof resText == 'string') {
460
+ // this.onFetched(resText, onDone, onFailed, debug)
461
+ // }
462
+ // })
463
+ // } else {
464
+ fetch(this.url + this.uri, options).then(async (res) => {
465
+ let resText = await res.text()
466
+ this.onFetched(resText, onDone, onFailed, debug)
467
+ }).catch((r) => {
468
+ // Alert.alert(this.alertTimeout.title, this.alertTimeout.message, [
469
+ // {
470
+ // text: this.alertTimeout.ok,
471
+ // style: 'cancel',
472
+ // onPress: () => this.init(uri, post, onDone, onFailed, debug)
473
+ // },
474
+ // {
475
+ // text: this.alertTimeout.cancel,
476
+ // style: 'destructive',
477
+ // onPress: () => { }
478
+ // }
479
+ // ])
480
+ this.onFetchFailed(r)
469
481
  LibProgress.hide()
470
482
  })
483
+ // }
471
484
  }
472
485
 
473
486
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.111-y",
3
+ "version": "0.0.112",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",