better rich presence retry logic
This commit is contained in:
		
							parent
							
								
									6b90fbd8d4
								
							
						
					
					
						commit
						9d0588d9a9
					
				
					 1 changed files with 15 additions and 5 deletions
				
			
		
							
								
								
									
										18
									
								
								src/index.js
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								src/index.js
									
										
									
									
									
								
							| 
						 | 
					@ -81,12 +81,22 @@ client.on("error", function () {});
 | 
				
			||||||
rpc.on("connected", function () {
 | 
					rpc.on("connected", function () {
 | 
				
			||||||
  updatePresence();
 | 
					  updatePresence();
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					let retryingRPC = false;
 | 
				
			||||||
rpc.once("ready", function () {
 | 
					rpc.once("ready", function () {
 | 
				
			||||||
  rpc.transport.on("close", async function () {
 | 
					  rpc.transport.on("close", function () {
 | 
				
			||||||
    try {
 | 
					    if (!retryingRPC) {
 | 
				
			||||||
      await rpc.transport.connect();
 | 
					      retryingRPC = true;
 | 
				
			||||||
    } catch (err) {
 | 
					      setTimeout(function () {
 | 
				
			||||||
 | 
					        rpc.transport
 | 
				
			||||||
 | 
					          .connect()
 | 
				
			||||||
 | 
					          .then(() => {
 | 
				
			||||||
 | 
					            retryingRPC = false;
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					          .catch((err) => {
 | 
				
			||||||
 | 
					            retryingRPC = false;
 | 
				
			||||||
            rpc.transport.emit("close");
 | 
					            rpc.transport.emit("close");
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					      }, 5000);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue