1
1
declare const io : Function ;
2
2
declare const socket : any ;
3
3
declare const server : string ;
4
+ declare class RestClient {
5
+ public _key : string ;
6
+ public key : string ;
7
+ public authType : string ;
8
+ public api : string ;
9
+ public computedHeaders : any ;
10
+
11
+ constructor ( key : string , authType : "Session" , api ?: string ) ;
12
+
13
+ fetchPromotions ( ) : Promise < any [ ] > ;
14
+ fetchUser ( user : string ) : Promise < any > ;
15
+ fetchRooms ( ) : Promise < any > ;
16
+ switchBlob ( newBlob : string ) : Promise < any > ;
17
+ redeemDailyBonus ( ) : Promise < any > ;
18
+ ping ( ) : Promise < number > ;
19
+ static extractSessionID ( ) : string ;
20
+ }
21
+
22
+ const rest : RestClient = new RestClient ( RestClient . extractSessionID ( ) , "Session" ) ;
4
23
5
24
function randomNumber ( min : number , max : number ) : number {
6
25
return Math . floor ( Math . random ( ) * ( max - min ) + min ) ;
@@ -626,7 +645,7 @@ if (["Android", "iOS"].some(v => window.navigator.userAgent.includes(v))) {
626
645
// -------------
627
646
// Canvas
628
647
// -------------
629
- function animationFrame ( ) : any {
648
+ async function animationFrame ( ) : Promise < any > {
630
649
if ( windowBlur ) {
631
650
return window . requestAnimationFrame ( animationFrame ) ;
632
651
}
@@ -647,14 +666,12 @@ if (["Android", "iOS"].some(v => window.navigator.userAgent.includes(v))) {
647
666
// Ping
648
667
if ( Date . now ( ) - lastTick > 2500 ) {
649
668
displayLeaderboard ( ) ;
650
- const timestampBefore : number = Date . now ( ) ;
651
- fetch ( "/api/ping" ) . then ( async res => {
652
- const request : any = await res . json ( ) ;
653
- const diff : number = ping = ( request . arrived - timestampBefore ) ;
654
- const latencyElement : HTMLElement | null = document . getElementById ( "latency" ) ;
655
- if ( ! latencyElement ) return ;
656
- latencyElement . innerHTML = `• Ping: <span style="color: #${ diff < 100 ? '00ff00' : ( diff < 200 ? 'ccff99' : ( diff < 250 ? 'ffff99' : ( diff < 500 ? 'ff9966' : 'ff0000' ) ) ) } ">${ diff } ms</span>` ;
657
- } ) ;
669
+ ping = await rest . ping ( ) ;
670
+
671
+ const latencyElement : HTMLElement | null = document . getElementById ( "latency" ) ;
672
+ if ( ! latencyElement ) return ;
673
+
674
+ latencyElement . innerHTML = `• Ping: <span style="color: #${ ping < 100 ? '00ff00' : ( ping < 200 ? 'ccff99' : ( ping < 250 ? 'ffff99' : ( ping < 500 ? 'ff9966' : 'ff0000' ) ) ) } ">${ ping } ms</span>` ;
658
675
lastTick = Date . now ( ) ;
659
676
}
660
677
0 commit comments