ZEGOCLOUD provides sample server code for Node.js and sample client code for iOS. You can create an application and experience all features of the mini-games with activated permissions by running the two scripts of sample code. You can also learn how to implement a mini-game service by reading the sample code.
This topic involves the following sections:
The sample server code cannot be used in a production environment for data security. ZEGO is not liable for any risks or losses that are caused if you use the sample server code in a production environment.
Before you run the sample server code for Node.js, make sure that the development environment meets the following requirements:
AppID
and ServerSecret
parameters of the project are obtained. For more information, see How to view project information.The following section describes the directory structure of the sample server code. All file paths involved in this topic are based on the directory structure.
ZegoMiniGameServerDemo
├── index.js # The main file.
├── package.json # The configuration file.
└── utils
├── config.js # Enter the values of the `AppID` and `ServerSecret` parameters that you obtain in the ZEGO console.
├── gameToken.js # The token generated by the server.
└── getToken04.js
Decompress the ZegoMiniGameServerDemo.zip
package of the sample server code to obtain the ZegoMiniGameServerDemo
folder.
Modify the ZegoMiniGameServerDemo/utils/config.js
file by specifying the appID
parameter in the red-framed part as shown in the following figure.
ZegoMiniGameServerDemo/utils/config.js
file, specify the serverSecret
parameter.
The https://mini-game-api.zego.im
host address provided in this file is the endpoint of the mini-game server and cannot be modified.
Go to the ZegoMiniGameServerDemo
folder and run the following code on the terminal to start the mini-game server:
npm i # Install dependencies.
node index.js
Obtain the server address, which can be used as the backend address in the sample client code.
The following figure shows the output after the sample server code is run.
Before you run the sample client code for iOS, make sure that the development environment meets the following requirements:
AppID
parameter of the project is obtained. For more information, see How to view project information.The following section describes the directory structure of sample code for iOS. All file paths involved in this section are based on the directory structure.
ZegoMiniGameEngineDemo/
├── Podfile
├── Podfile.lock
├── ZegoMiniGameEngineDemo
├── ZegoMiniGameEngineDemo.xcodeproj
└── ZegoMiniGameEngineDemo.xcworkspace
Open the App Store and search Xcode. Then, download and install Xcode.
Decompress the iOS client example source code package to get the folder "ZegoMiniGameEngineDemoSrc-iOS", and navigate to the folder using the terminal.
Execute the pod repo update
command to update the local index and ensure the latest version of the SDK can be installed.
Execute the pod install
command to install the SDK.
Open Xcode, select the menu at the top left "File > Open...", and find and open the "ZegoMiniGameEngineDemo.xcworkspace" file in the extracted example source code folder.
Log in as a developer.
Open Xcode. In the upper-left corner in the top navigation bar, choose Xcode > Preferences.
Click the Accounts tab. In the lower-left corner, click the plus icon (+). In the dialog that appears, select Apple ID and click Continue.
Enter your Apple ID and password to log in.
Modify the bundle identifier and the developer certificate.
Open Xcode. In the left-side navigation pane, click the ZegoMiniGameEngineDemo project. Click the Signing & Capabilities tab and modify the Team
and Bundle Identifier
parameters as needed.
Modify the file "/ZegoMiniGameEngineDemo/KeyCenter.m", fill in the appID
necessary for SDK initialization, and update the hostUrl
address to the one obtained after successfully running the sample server code (as described in the Prerequisites section of this document).
Connect the iOS device to your computer and click Any iOS Device in the upper part of Xcode. In the dialog that appears, select the iOS device or the emulator.
In the upper-left corner of Xcode, click Build to compile and run the sample code. Then, you can experience the mini-game.