sud.getZoneId
Synchronously retrieves the current service zone ID. Mini-game developers (CPs) can use this value to determine which regional game server the game client should connect to.
Usage
zoneId corresponds to a game release region configured in the OpenPaaS developer console. The game client can call this API in the mini-game JS environment loaded by the SDK to obtain the current zone ID.
For example, a CP releases a game in Mainland China (cn) and Southeast Asia (sea), with a game server deployed in each region:
- When the API returns
cn, the game client connects to the CP's server in Mainland China. - When the API returns
sea, the game client connects to the CP's server in Southeast Asia.
The CP must maintain a mapping from zone IDs to game server URLs based on its actual deployments. This API only provides the zone ID. It does not return a game server URL or automatically switch the client's connection to the CP's server.
Parameters
None.
Return Value
string
The current service zone ID, with the following values:
| Return Value | Region |
|---|---|
cn | Mainland China |
sea | Southeast Asia |
eu | Europe |
ru | Russia |
Returns an empty string "" if the SDK has not obtained zone information. If the value is empty or the CP has not configured a server for the returned zone, the game client should display a message or handle it according to its business requirements, rather than use an undefined server URL. CPs must update their URL mappings as new regions are added.
Example
This example assumes that the game has been released in Mainland China and Southeast Asia. The domains are placeholders; replace them with the CP's actual game server URLs.
const gameServerUrls = new Map([
['cn', 'https://cn.game.example.com'],
['sea', 'https://sea.game.example.com'],
]);
const zoneId = sud.getZoneId();
const gameServerUrl = gameServerUrls.get(zoneId);
if (!gameServerUrl) {
// No zone or no configured server: do not connect; notify the user or handle it in the game.
console.error('No game server configured for the current zone', zoneId);
} else {
// Use gameServerUrl to initialize the game connection or as the destination for game requests.
console.log('Current zone and game server URL', zoneId, gameServerUrl);
}