@@ -9,11 +9,17 @@ type APIOptions = {
99 enableMockTransport ?: boolean
1010}
1111
12- function delay ( time : number ) {
12+ function mimicNetworkDelay ( ) {
13+ const MINIMUM_DELAY = 100
14+ const MAXIMUM_DELAY = 500
15+
1316 return new Promise < void > ( ( resolve , _ ) => {
14- setTimeout ( ( ) => {
15- resolve ( )
16- } , time )
17+ setTimeout (
18+ ( ) => {
19+ resolve ( )
20+ } ,
21+ Math . random ( ) * ( MAXIMUM_DELAY - MINIMUM_DELAY ) + MINIMUM_DELAY
22+ )
1723 } )
1824}
1925
@@ -32,10 +38,11 @@ export class API {
3238 this . rpcTransport = createRouterTransport ( ( { service } ) => {
3339 service ( WebService , {
3440 async updateConfig ( { updatedConfig : _ } ) {
35- await delay ( 1000 )
3641 return { }
3742 } ,
38- getConfig ( ) {
43+ async getConfig ( ) {
44+ await mimicNetworkDelay ( )
45+
3946 return {
4047 config : `watch_directories:
4148 - path: /media
@@ -83,7 +90,9 @@ server:
8390` ,
8491 }
8592 } ,
86- getSubtitleSegments ( { id } ) {
93+ async getSubtitleSegments ( { id } ) {
94+ await mimicNetworkDelay ( )
95+
8796 return {
8897 segments : [
8998 {
@@ -119,7 +128,9 @@ server:
119128 ] ,
120129 }
121130 } ,
122- getSubtitle ( { id } ) {
131+ async getSubtitle ( { id } ) {
132+ await mimicNetworkDelay ( )
133+
123134 let name = 'English'
124135 switch ( id ) {
125136 case 0 :
@@ -135,7 +146,9 @@ server:
135146
136147 return { name }
137148 } ,
138- getVideo ( { id } ) {
149+ async getVideo ( { id } ) {
150+ await mimicNetworkDelay ( )
151+
139152 let filepath = ''
140153 switch ( id ) {
141154 case 0 :
@@ -158,7 +171,9 @@ server:
158171
159172 return { filepath, subtitleIds : [ 0 , 1 , 2 ] }
160173 } ,
161- getDirectory ( { path } ) {
174+ async getDirectory ( { path } ) {
175+ await mimicNetworkDelay ( )
176+
162177 if ( path == '/media/series' ) {
163178 return {
164179 childrenDirectoryNames : [ 'Horimiya' ] ,
@@ -178,12 +193,16 @@ server:
178193 videoIds : [ 0 , 1 , 2 , 3 ] ,
179194 }
180195 } ,
181- getMediaDirectories ( ) {
196+ async getMediaDirectories ( ) {
197+ await mimicNetworkDelay ( )
198+
182199 return {
183200 paths : [ '/media/series' ] ,
184201 }
185202 } ,
186- getGlobalStatistics ( ) {
203+ async getGlobalStatistics ( ) {
204+ await mimicNetworkDelay ( )
205+
187206 return {
188207 Exported : 92 ,
189208 Formated : 41 ,
0 commit comments