Skip to content

Commit 56f5eba

Browse files
author
ranpeng
committed
refactor: 修改demo 内容
1 parent 6f41558 commit 56f5eba

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

Diff for: demo/demo.html

+9-32
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,22 @@
3030
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.21.1/axios.min.js"></script>
3131
<script>
3232

33-
const tryLock = async () => {
34-
// 需要server 端实现调度接口 tryLock,文档参考 https://cloud.tencent.com/document/product/1162/47523
35-
// 接口调用参考 https://cloud.tencent.com/document/api/1162/40738
36-
37-
const url = 'https://xxxx/tryLock';
38-
const { data } = await axios.post(url, {
39-
GameId: 'game-id',
40-
UserId: 'user-id',
41-
Appid: 1234567,
42-
});
43-
const { code, data: { Error } } = data;
44-
45-
console.log('%c tryLock res', 'color: blue; font-size: 14px', data);
33+
const startCloudGame = async () => {
4634

47-
if (code === 0) {
48-
await createSession();
49-
} else {
50-
// your logics
51-
}
52-
};
53-
54-
const createSession = async () => {
55-
// 需要server 端实现调度接口 createSession,文档参考 https://cloud.tencent.com/document/product/1162/47523
56-
// 接口调用参考 https://cloud.tencent.com/document/api/1162/40740
35+
const url = 'https://xxxx/StartCloudGame'; // 后台服务可以参考函数方式创建(serverless) 方案
36+
// 接口 StartCloudGame 其实就是后台串行调用了云API的 TrylockWorker + CreateSession
37+
// 尝试锁定机器(TrylockWorker) https://cloud.tencent.com/document/api/1162/40738
38+
// 创建会话(CreateSession) https://cloud.tencent.com/document/api/1162/40740
5739

58-
const url = 'https://xxxx/createSession';
5940
const { data } = await axios.post(url, {
6041
GameId: 'game-id',
6142
UserId: 'user-id',
62-
Appid: 1234567,
63-
ClientSession: TCGSDK.getClientSession()
43+
ClientSession: TCGSDK.getClientSession(),
6444
});
45+
const { code, data: { Error } } = data;
6546

66-
console.log('%c createSession res', 'color: blue; font-size: 14px', data);
67-
const {code, data: {Error, ServerSession}} = data
47+
console.log('%c startCloudGame res', 'color: blue; font-size: 14px', data);
6848

69-
// 伪代码,成功后调用start 启动游戏
7049
if (code === 0) {
7150
TCGSDK.start(ServerSession);
7251
} else {
@@ -78,8 +57,6 @@
7857
TCGSDK.init({
7958
appid: 1234567,
8059
mount: 'mount-point',
81-
showLogo: true,
82-
preloadTime: 0,
8360
debugSetting: {
8461
showLog: true,
8562
},
@@ -112,7 +89,7 @@
11289
onInitSuccess: async (res) => {
11390
console.log('%c onInitSuccess', 'color: red', res);
11491

115-
await tryLock();
92+
await startCloudGame();
11693
}
11794
});
11895

0 commit comments

Comments
 (0)