esoftplay 0.0.111-e → 0.0.111-h

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.
@@ -0,0 +1,126 @@
1
+ // noPage
2
+
3
+ import { LibComponent } from "esoftplay";
4
+ import { Audio } from "expo-av";
5
+
6
+ export interface ContentAudioProps {
7
+ code: string,
8
+ onStatusChange: (status: any) => void
9
+ }
10
+
11
+ export interface ContentAudioState {
12
+ playbackInstanceName: string,
13
+ muted: boolean,
14
+ playbackInstancePosition: any,
15
+ playbackInstanceDuration: any,
16
+ shouldPlay: boolean,
17
+ isPlaying: boolean,
18
+ isBuffering: boolean,
19
+ isLoading: boolean,
20
+ volume: number,
21
+ }
22
+
23
+ // create a component
24
+ class eaudio extends LibComponent<ContentAudioProps, ContentAudioState> {
25
+ playbackInstance: any
26
+ state: ContentAudioState;
27
+ props: ContentAudioProps;
28
+ constructor(props: ContentAudioProps) {
29
+ super(props)
30
+ this.props = props;
31
+ this.playbackInstance = null;
32
+ this.state = {
33
+ playbackInstanceName: "loading...",
34
+ muted: false,
35
+ playbackInstancePosition: null,
36
+ playbackInstanceDuration: null,
37
+ shouldPlay: false,
38
+ isPlaying: false,
39
+ isBuffering: false,
40
+ isLoading: true,
41
+ volume: 1.0,
42
+ };
43
+ this._onPlaybackStatusUpdate = this._onPlaybackStatusUpdate.bind(this)
44
+ this._loadNewPlaybackInstance = this._loadNewPlaybackInstance.bind(this)
45
+ this._onPlayPausePressed = this._onPlayPausePressed.bind(this)
46
+ }
47
+
48
+ componentDidMount(): void {
49
+ super.componentDidMount();
50
+ Audio.setAudioModeAsync({
51
+ allowsRecordingIOS: false,
52
+ interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
53
+ playsInSilentModeIOS: true,
54
+ shouldDuckAndroid: true,
55
+ staysActiveInBackground: false,
56
+ interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
57
+ playThroughEarpieceAndroid: false
58
+ });
59
+ this._loadNewPlaybackInstance(false);
60
+ }
61
+
62
+ componentWillUnmount(): void {
63
+ super.componentWillUnmount();
64
+ (async () => {
65
+ if (this.playbackInstance != null) {
66
+ await this.playbackInstance.unloadAsync();
67
+ this.playbackInstance.setOnPlaybackStatusUpdate(null);
68
+ this.playbackInstance = null;
69
+ }
70
+ })()
71
+ }
72
+
73
+ async _loadNewPlaybackInstance(playing: boolean): Promise<void> {
74
+ if (this.playbackInstance != null) {
75
+ await this.playbackInstance.unloadAsync();
76
+ this.playbackInstance.setOnPlaybackStatusUpdate(null);
77
+ this.playbackInstance = null;
78
+ }
79
+
80
+ const source = { uri: "https://api.soundcloud.com/tracks/" + this.props.code + "/stream?client_id=4a584e57dbc1c522b0ccdb68464f6ec3" };
81
+ const initialStatus = {
82
+ shouldPlay: playing,
83
+ volume: this.state.volume,
84
+ isMuted: this.state.muted,
85
+ };
86
+ const { sound, status } = await Audio.Sound.createAsync(
87
+ source,
88
+ initialStatus,
89
+ this._onPlaybackStatusUpdate
90
+ );
91
+ this.playbackInstance = sound;
92
+ }
93
+
94
+ _onPlaybackStatusUpdate(status: any): void {
95
+ if (status.isLoaded) {
96
+ this.setState({
97
+ playbackInstancePosition: status.positionMillis,
98
+ playbackInstanceDuration: status.durationMillis,
99
+ shouldPlay: status.shouldPlay,
100
+ isPlaying: status.isPlaying,
101
+ isBuffering: status.isBuffering,
102
+ muted: status.isMuted,
103
+ volume: status.volume,
104
+ }, () => this.props.onStatusChange(this.state.isPlaying));
105
+ } else {
106
+ if (status.error) {
107
+ }
108
+ }
109
+ };
110
+
111
+ _onPlayPausePressed(): void {
112
+ if (this.playbackInstance != null) {
113
+ if (this.state.isPlaying) {
114
+ this.playbackInstance.pauseAsync()
115
+ } else {
116
+ this.playbackInstance.playAsync()
117
+ }
118
+ }
119
+ }
120
+
121
+ render(): any {
122
+ return null
123
+ }
124
+ }
125
+
126
+ export default eaudio;
@@ -1,5 +1,4 @@
1
- // noPage
2
- import { esp, LibCrypt, LibNet_status, LibObject, LibProgress, LibUtils, LogStateProperty } from 'esoftplay';
1
+ import { esp, LibCrypt, LibNet_status, LibObject, LibProgress, LibToastProperty, LibUtils, LogStateProperty } from 'esoftplay';
3
2
  import { reportApiError } from "esoftplay/error";
4
3
  import moment from "esoftplay/moment";
5
4
  import Constants from 'expo-constants';
@@ -171,6 +170,7 @@ export default class ecurl {
171
170
  url: this.url + this.uri + (token_uri || 'get_token'),
172
171
  method: "POST",
173
172
  cancelToken: this.abort.token,
173
+ transformResponse: [(data) => { return data; }],
174
174
  headers: {
175
175
  ...this.header,
176
176
  ["Content-Type"]: "application/x-www-form-urlencoded;charset=UTF-8"
@@ -191,15 +191,9 @@ export default class ecurl {
191
191
  onFailed(this.refineErrorMessage(msg), false)
192
192
  }, debug)
193
193
  }).catch((r: string) => {
194
- this.cancelTimeout();
195
- if (this.maxRetry > 0) {
196
- this.init(uri, post, onDone, onFailed, debug)
197
- this.maxRetry = this.maxRetry - 1
198
- } else {
199
- this.onFetched(r, onDone, onFailed, debug)
200
- }
194
+ this.cancelTimeout();
195
+ LibToastProperty.show("Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi")
201
196
  LibProgress.hide()
202
- this.onFetchFailed(r)
203
197
  })
204
198
  }
205
199
  }
@@ -301,9 +295,10 @@ export default class ecurl {
301
295
  cancelToken: this.abort.token,
302
296
  headers: {
303
297
  ...this.header,
304
- ["Content-Type"]: "application/x-www-form-urlencoded;charset=UTF-8"
298
+ ["Content-Type"]: "application/x-www-form-urlencoded;charset=UTF-8",
305
299
  },
306
300
  data: !this.post ? undefined : this.post,
301
+ transformResponse: [(data) => { return data; }],
307
302
  Cache: "no-store",
308
303
  Pragma: "no-cache",
309
304
  ['Cache-Control']: "no-store",
@@ -323,10 +318,9 @@ export default class ecurl {
323
318
  }
324
319
  LibProgress.hide()
325
320
  }).catch((r: string) => {
326
- // this.cancelTimeout()
327
- this.onFetchFailed(r)
321
+ LibToastProperty.show("Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi")
328
322
  LibProgress.hide()
329
- this.onError(r)
323
+ // this.cancelTimeout()
330
324
  })
331
325
  }
332
326
  }
@@ -363,19 +357,21 @@ export default class ecurl {
363
357
  url: this.url + this.uri,
364
358
  method: !this.post ? "GET" : "POST",
365
359
  headers: this.header,
360
+ transformResponse: [(data) => { return data; }],
366
361
  data: !this.post ? undefined : this.post,
367
362
  cancelToken: this.abort.token,
368
363
  cache: "no-store",
364
+
369
365
  Pragma: "no-cache",
370
366
  ["Cache-Control"]: 'no-cache, no-store, must-revalidate',
371
367
  ["Expires"]: 0,
372
368
  mode: "cors",
373
369
  _post: post
374
370
  }
375
- // if (debug == 1) {
376
- // console.log(this.url + this.uri, { ...options, cancelToken: undefined })
377
- // }
378
-
371
+ if (debug == 1) {
372
+ console.log(this.url + this.uri, { ...options, cancelToken: undefined })
373
+ }
374
+
379
375
  if (esp.isDebug('apitest') && manifest?.packagerOpts?.dev && LogStateProperty) {
380
376
  const allData = LogStateProperty.state().get() || []
381
377
  const logEnable = LogStateProperty.enableLog().get()
@@ -409,6 +405,7 @@ export default class ecurl {
409
405
  this.fetchConf = { url: this.url + this.uri, options: options }
410
406
  this.initTimeout(upload ? 120000 : undefined)
411
407
  axios(options).then(async (res: any) => {
408
+ console.log(typeof res.data)
412
409
  this.cancelTimeout()
413
410
  this.onFetched(res.data, onDone, onFailed, debug)
414
411
  }).catch((e: any) => {
@@ -417,7 +414,8 @@ export default class ecurl {
417
414
  this.init(uri, post, onDone, onFailed, debug)
418
415
  this.maxRetry = this.maxRetry - 1
419
416
  } else {
420
- this.onFetched(e, onDone, onFailed, debug)
417
+ LibToastProperty.show("Koneksi internet anda tidak stabil, silahkan coba beberapa saat lagi")
418
+ LibProgress.hide()
421
419
  }
422
420
  })
423
421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.111-e",
3
+ "version": "0.0.111-h",
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",