Commit e1a8a636 authored by 范雪寒's avatar 范雪寒

test:

parent bbc33eb8
......@@ -7,14 +7,8 @@ export class NetworkHelper {
}
async init(roomType: string, maxPlayers: number) {
try {
await this.initRoom();
// await this.initListener();
return await this.joinRoom(roomType, maxPlayers);
} catch (e) {
console.log(e);
// return null;
}
await this.initRoom();
return await this.joinRoom(roomType, maxPlayers);
}
async startGame() {
......@@ -30,103 +24,17 @@ export class NetworkHelper {
listenerInited = false;
initListener() {
this.log("MGOBE.Player.id = " + MGOBE.Player.id);
this.log("MGOBE.Player.openId = " + MGOBE.Player.openId);
if (MGOBE.Player.id !== undefined) {
return;
}
// MGOBE.Listener;
return new Promise((resolve, reject) => {
const gameId = "obg-i4ql53h1"; //替换为控制台上的 游戏 ID
const openId = "openid_op_16" + Math.random();
const gameInfo: MGOBE.types.GameInfoPara = {
gameId: gameId,
openId: openId,
createSignature: (callback) => {
this.callNetworkApiGet(
"http://staging-teach.ireadabc.com",
"/api/oxford/game/v1/config",
{
gameid: gameId,
openid: openId,
},
(data) => {
callback(JSON.parse(data));
}
);
},
};
const serverUrl = "i4ql53h1.wxlagame.com"; //替换为控制台上的 域名
const config = {
url: serverUrl,
reconnectMaxTimes: 3,
reconnectInterval: 1000,
resendInterval: 1000,
resendTimeout: 5000,
cacertNativeUrl: "",
};
MGOBE.DebuggerLog.enable = false;
// 如果是原生平台,则加载 Cert 证书,否则会提示 WSS 错误
if (cc.sys.isNative) {
let cacertFile;
const cacertNode = cc.find("cacertNode");
if (cacertNode) {
cacertFile = cacertNode.getComponent("cacert").cacertFile;
}
if (!cacertFile) {
console.log("没有cacertFile!!!");
}
config.cacertNativeUrl =
cc.loader.md5Pipe && cc.ENGINE_VERSION < "2.4.0"
? cc.loader.md5Pipe.transformURL(cacertFile.nativeUrl)
: cacertFile.nativeUrl;
}
this.log("initListener");
MGOBE.Listener.init(gameInfo, config, async (event) => {
this.log(JSON.stringify(event));
if (event.code !== 0) {
this.log("初始化失败: " + event.code);
reject();
return;
}
this.listenerInited = true;
this.log("初始化成功");
resolve(null);
});
this.log("initListener2");
});
}
room: GOBE.Room;
client: GOBE.Client;
room: any;
client: any;
async initRoom() {
this.client = new window.GOBE.Client({
this.client = new (<any>(window)).GOBE.Client({
clientId: '857970243220294656',// 客户端ID
clientSecret: '489BFFB5D22BC39FDA0B1878F01F38C8049EBF68C856E25E63E7403A723A140D',// 客户端密钥
appId: '243650030995634151',// 应用的ID
appId: '105879509',// 应用的ID
openId: 'op_16' + Math.random(),// 玩家ID
});
console.log(this.client);
console.log('喵喵喵1');
let playerId;
this.client.init().then(() => {
// 初始化成功
playerId = this.client.playerId;
}).catch((e) => {
// 初始化失败
console.log('初始化失败')
console.log(e)
});
console.log('喵喵喵2');
await this.client.init();
}
player: any;
......@@ -140,12 +48,24 @@ export class NetworkHelper {
customRoomProperties: '',
maxPlayers: maxPlayers,
};
// 在线匹配参数
const matchPlayerConfig = {
playerInfo: {
playerId: 'xxxxxx',
matchParams: {
test: 1, // 匹配参数的属性需要与matchCode所属规则中配置的属性对应
},
},
matchCode: 'cc4dc617d3aa4f849824a12c3e8290c8',
};
const playerConfig = {
customPlayerStatus: 0,
customPlayerProperties: ''
};
console.log('汪汪汪1')
this.room = await this.client.matchRoom(matchRoomConfig, playerConfig);
console.log('汪汪汪1');
// this.room = await this.client.createRoom(matchRoomConfig, playerConfig);
this.room = await this.client.matchPlayer(matchPlayerConfig, playerConfig);
console.log('汪汪汪2' + JSON.stringify(this.room));
this.player = this.room.player;
this.room.onJoin(this.onJoinRoom.bind(this));
......@@ -155,7 +75,9 @@ export class NetworkHelper {
this.room.onRecvFrame(this.onRecvFrame.bind(this));
this.room.onDisconnect(this.onDisconnect.bind(this));
this.room.onDismiss(this.onDisconnect.bind(this));
console.log('汪汪汪2')
console.log('汪汪汪3' + this.player.playerId);
return this.player.playerId;
}
async leaveRoom() {
......@@ -200,7 +122,7 @@ export class NetworkHelper {
if (this._eventListeners["playerJoin"]) {
this._eventListeners["playerJoin"](event);
}
console.log("新玩家加入", event.data.joinPlayerId);
console.log("新玩家加入", JSON.stringify(event));
}
onLeaveRoom(event) {
console.log("onLeaveRoom");
......@@ -234,7 +156,7 @@ export class NetworkHelper {
async onDestroy() {
try {
console.log("onDestroy1");
MGOBE.Listener.clear();
// MGOBE.Listener.clear();
this.stopFrameSync();
this.closeRoom();
this.dismissRoom();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment