drgame-cc 1.0.17 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-templates/web-mobile/bg.png +0 -0
- package/build-templates/web-mobile/index.html +3 -3
- package/build-templates/web-mobile/jz-jdt-3.png +0 -0
- package/build-templates/web-mobile/jz-jdt-4.png +0 -0
- package/build-templates/web-mobile/logo.png +0 -0
- package/build-templates/web-mobile/style-mobile.css +85 -73
- package/drscript/ExitWin.ts +0 -2
- package/drscript/GameAnalytics.ts +162 -0
- package/drscript/PlatformAdapter.ts +58 -12
- package/drscript/Util.ts +11 -0
- package/drscript/ad-sdk/reporters/reporter.js +19 -0
- package/drscript/ad-sdk/reporters/superset-lewo.js +382 -242
- package/drscript/focus/FocusManager.ts +8 -8
- package/drscript/focus/FocusVisualLayer.ts +40 -40
- package/drscript/input/KeyboardMove.ts +55 -0
- package/drscript/virtualgamepad/VirtualGamepadClient.ts +214 -0
- package/drscript/virtualgamepad/VirtualGamepadClient.ts.meta +10 -0
- package/drscript/virtualgamepad/VirtualGamepadConfig.ts +70 -0
- package/drscript/virtualgamepad/VirtualGamepadConfig.ts.meta +10 -0
- package/drscript/virtualgamepad/VirtualGamepadManager.ts +809 -0
- package/drscript/virtualgamepad/VirtualGamepadManager.ts.meta +10 -0
- package/drscript/virtualgamepad/VirtualGamepadView.ts +346 -0
- package/drscript/virtualgamepad/VirtualGamepadView.ts.meta +10 -0
- package/package.json +5 -4
- package/build-templates/web-mobile/bg1.jpg +0 -0
- package/build-templates/web-mobile/splash_en - /345/211/257/346/234/254.png +0 -0
- package/drscript/README - /345/211/257/346/234/254.md" +0 -814
|
@@ -450,16 +450,16 @@ export default class FocusManager {
|
|
|
450
450
|
|
|
451
451
|
private static invokeButton(button: cc.Button) {
|
|
452
452
|
if (!button || !button.node || !button.node.activeInHierarchy || !button.interactable) return;
|
|
453
|
+
var event = new cc.Event.EventCustom(cc.Node.EventType.TOUCH_END, true);
|
|
454
|
+
event.target = button.node;
|
|
453
455
|
if (button.clickEvents && button.clickEvents.length > 0) {
|
|
454
|
-
cc.Component.EventHandler.emitEvents(button.clickEvents,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
button.
|
|
458
|
-
|
|
459
|
-
// 模拟一个touch end事件
|
|
460
|
-
var event = new cc.Event.EventCustom(cc.Node.EventType.TOUCH_END, true);
|
|
461
|
-
button.node.emit(cc.Node.EventType.TOUCH_END, event);
|
|
456
|
+
cc.Component.EventHandler.emitEvents(button.clickEvents, event);
|
|
457
|
+
}
|
|
458
|
+
if (button instanceof cc.Toggle) {
|
|
459
|
+
button.isChecked = !button.isChecked;
|
|
460
|
+
cc.Component.EventHandler.emitEvents(button.checkEvents, event);
|
|
462
461
|
}
|
|
462
|
+
button.node.emit(cc.Node.EventType.TOUCH_END, event);
|
|
463
463
|
}
|
|
464
464
|
|
|
465
465
|
private static emitFocusChanged(item: FocusRuntimeItem | null, previous?: FocusRuntimeItem | null) {
|
|
@@ -167,59 +167,59 @@ export default class FocusVisualLayer extends cc.Component {
|
|
|
167
167
|
this.graphics.stroke();
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
private positionIcon(item: FocusRuntimeItem, iconConfig: TvUiIconItem) {
|
|
171
|
-
if (!item || !item.node || !item.node.isValid) return;
|
|
172
|
-
let focusConfig = TvUiConfigManager.getConfig().focus || {};
|
|
173
|
-
|
|
174
|
-
let node = item.node;
|
|
175
|
-
let worldPos = node.parent.convertToWorldSpaceAR(node.position);
|
|
176
|
-
let local = this.node.convertToNodeSpaceAR(worldPos);
|
|
177
|
-
|
|
178
|
-
let contentSize = node.getContentSize();
|
|
179
|
-
let scaleX = node.scaleX;
|
|
180
|
-
let scaleY = node.scaleY;
|
|
181
|
-
let width = contentSize.width * scaleX;
|
|
182
|
-
let height = contentSize.height * scaleY;
|
|
183
|
-
|
|
184
|
-
let iconWidth = iconConfig.width || 60;
|
|
185
|
-
let iconHeight = iconConfig.height || 60;
|
|
186
|
-
let offsetX = iconConfig.offsetX;
|
|
187
|
-
let offsetY = iconConfig.offsetY;
|
|
188
|
-
if (offsetX === undefined) offsetX = focusConfig.iconOffsetX || 0;
|
|
189
|
-
if (offsetY === undefined) offsetY = focusConfig.iconOffsetY || 0;
|
|
190
|
-
if (!this.iconNode) return;
|
|
191
|
-
|
|
192
|
-
let x = local.x + width / 2 + offsetX;
|
|
193
|
-
let y = local.y + height / 2 + offsetY;
|
|
194
|
-
if ((focusConfig.iconPlacement || "bottomRight") == "bottomRight") {
|
|
195
|
-
y = local.y - height / 2 - offsetY;
|
|
196
|
-
}
|
|
197
|
-
this.iconNode.setContentSize(iconWidth, iconHeight);
|
|
198
|
-
this.iconNode.setPosition(x, y);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
170
|
// private positionIcon(item: FocusRuntimeItem, iconConfig: TvUiIconItem) {
|
|
202
171
|
// if (!item || !item.node || !item.node.isValid) return;
|
|
203
172
|
// let focusConfig = TvUiConfigManager.getConfig().focus || {};
|
|
204
|
-
|
|
205
|
-
// let
|
|
206
|
-
// let
|
|
207
|
-
// let
|
|
208
|
-
|
|
173
|
+
|
|
174
|
+
// let node = item.node;
|
|
175
|
+
// let worldPos = node.parent.convertToWorldSpaceAR(node.position);
|
|
176
|
+
// let local = this.node.convertToNodeSpaceAR(worldPos);
|
|
177
|
+
|
|
178
|
+
// let contentSize = node.getContentSize();
|
|
179
|
+
// let scaleX = node.scaleX;
|
|
180
|
+
// let scaleY = node.scaleY;
|
|
181
|
+
// let width = contentSize.width * scaleX;
|
|
182
|
+
// let height = contentSize.height * scaleY;
|
|
183
|
+
|
|
184
|
+
// let iconWidth = iconConfig.width || 60;
|
|
185
|
+
// let iconHeight = iconConfig.height || 60;
|
|
209
186
|
// let offsetX = iconConfig.offsetX;
|
|
210
187
|
// let offsetY = iconConfig.offsetY;
|
|
211
188
|
// if (offsetX === undefined) offsetX = focusConfig.iconOffsetX || 0;
|
|
212
189
|
// if (offsetY === undefined) offsetY = focusConfig.iconOffsetY || 0;
|
|
213
190
|
// if (!this.iconNode) return;
|
|
214
|
-
|
|
215
|
-
// let
|
|
191
|
+
|
|
192
|
+
// let x = local.x + width / 2 + offsetX;
|
|
193
|
+
// let y = local.y + height / 2 + offsetY;
|
|
216
194
|
// if ((focusConfig.iconPlacement || "bottomRight") == "bottomRight") {
|
|
217
|
-
// y = local.y -
|
|
195
|
+
// y = local.y - height / 2 - offsetY;
|
|
218
196
|
// }
|
|
219
|
-
// this.iconNode.setContentSize(
|
|
197
|
+
// this.iconNode.setContentSize(iconWidth, iconHeight);
|
|
220
198
|
// this.iconNode.setPosition(x, y);
|
|
221
199
|
// }
|
|
222
200
|
|
|
201
|
+
private positionIcon(item: FocusRuntimeItem, iconConfig: TvUiIconItem) {
|
|
202
|
+
if (!item || !item.node || !item.node.isValid) return;
|
|
203
|
+
let focusConfig = TvUiConfigManager.getConfig().focus || {};
|
|
204
|
+
let box = item.node.getBoundingBoxToWorld();
|
|
205
|
+
let center = cc.v2(box.x + box.width / 2, box.y + box.height / 2);
|
|
206
|
+
let local = this.node.convertToNodeSpaceAR(center);
|
|
207
|
+
let width = iconConfig.width || 60;
|
|
208
|
+
let height = iconConfig.height || 60;
|
|
209
|
+
let offsetX = iconConfig.offsetX;
|
|
210
|
+
let offsetY = iconConfig.offsetY;
|
|
211
|
+
if (offsetX === undefined) offsetX = focusConfig.iconOffsetX || 0;
|
|
212
|
+
if (offsetY === undefined) offsetY = focusConfig.iconOffsetY || 0;
|
|
213
|
+
if (!this.iconNode) return;
|
|
214
|
+
let x = local.x + box.width / 2 + offsetX;
|
|
215
|
+
let y = local.y + box.height / 2 + offsetY;
|
|
216
|
+
if ((focusConfig.iconPlacement || "bottomRight") == "bottomRight") {
|
|
217
|
+
y = local.y - box.height / 2 - offsetY;
|
|
218
|
+
}
|
|
219
|
+
this.iconNode.setContentSize(width, height);
|
|
220
|
+
this.iconNode.setPosition(x, y);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
223
|
private resizeToParent() {
|
|
224
224
|
let parent = this.node.parent;
|
|
225
225
|
let width = parent && parent.width ? parent.width : (cc.winSize && cc.winSize.width) || 1920;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import TvUi from "../core/TvUi";
|
|
2
|
+
import { TvRemoteKey } from "./KeyCodeAdapter";
|
|
3
|
+
|
|
4
|
+
const { ccclass, property } = cc._decorator;
|
|
5
|
+
|
|
6
|
+
@ccclass
|
|
7
|
+
export default class KeyboardMove extends cc.Component {
|
|
8
|
+
/**
|
|
9
|
+
* 按键移动回调
|
|
10
|
+
*/
|
|
11
|
+
public callback: (dir: cc.Vec2) => void;
|
|
12
|
+
private _keys: Set<TvRemoteKey> = new Set();
|
|
13
|
+
private _dir: cc.Vec2 = cc.v2(0, 0);
|
|
14
|
+
|
|
15
|
+
onLoad(): void {
|
|
16
|
+
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
|
17
|
+
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
onDestroy(): void {
|
|
21
|
+
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this);
|
|
22
|
+
cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this);
|
|
23
|
+
this._keys.clear();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private onKeyDown(event: cc.Event.EventKeyboard): void {
|
|
27
|
+
let key = TvUi.input.toRemoteKey(event.keyCode);
|
|
28
|
+
this._keys.add(key);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private onKeyUp(event: cc.Event.EventKeyboard): void {
|
|
32
|
+
let key = TvUi.input.toRemoteKey(event.keyCode);
|
|
33
|
+
this._keys.delete(key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
update(dt: number): void {
|
|
37
|
+
if (this._keys.size === 0)
|
|
38
|
+
return;
|
|
39
|
+
|
|
40
|
+
const dir = this._dir;
|
|
41
|
+
dir.x = 0;
|
|
42
|
+
dir.y = 0;
|
|
43
|
+
|
|
44
|
+
if (this._keys.has(TvRemoteKey.Left)) dir.x -= 1;
|
|
45
|
+
if (this._keys.has(TvRemoteKey.Right)) dir.x += 1;
|
|
46
|
+
if (this._keys.has(TvRemoteKey.Down)) dir.y -= 1;
|
|
47
|
+
if (this._keys.has(TvRemoteKey.Up)) dir.y += 1;
|
|
48
|
+
|
|
49
|
+
if (dir.x !== 0 || dir.y !== 0) {
|
|
50
|
+
dir.normalizeSelf();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (this.callback) this.callback(dir);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
export interface VirtualGamepadClientOptions {
|
|
2
|
+
wsUrl: string;
|
|
3
|
+
roomId: string;
|
|
4
|
+
deviceId: string;
|
|
5
|
+
game: string;
|
|
6
|
+
userId: string;
|
|
7
|
+
userType: "xiaomi" | "guest";
|
|
8
|
+
guestId?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
maxMembers: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type VirtualGamepadConnectionState = "idle" | "connecting" | "open" | "joined" | "closed" | "error";
|
|
14
|
+
|
|
15
|
+
export default class VirtualGamepadClient {
|
|
16
|
+
private socket: WebSocket | null = null;
|
|
17
|
+
private options: VirtualGamepadClientOptions | null = null;
|
|
18
|
+
private manualClose: boolean = false;
|
|
19
|
+
private reconnectCount: number = 0;
|
|
20
|
+
private heartbeatTimer: any = -1;
|
|
21
|
+
private reconnectTimer: any = -1;
|
|
22
|
+
private readonly maxReconnectCount: number = 3;
|
|
23
|
+
private readonly heartbeatMs: number = 10000;
|
|
24
|
+
|
|
25
|
+
public onStateChange: ((state: VirtualGamepadConnectionState, reason?: string) => void) | null = null;
|
|
26
|
+
public onMessage: ((message: any) => void) | null = null;
|
|
27
|
+
|
|
28
|
+
public connect(options: VirtualGamepadClientOptions) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.manualClose = false;
|
|
31
|
+
this.clearReconnect();
|
|
32
|
+
this.openSocket();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public close() {
|
|
36
|
+
this.manualClose = true;
|
|
37
|
+
this.clearHeartbeat();
|
|
38
|
+
this.clearReconnect();
|
|
39
|
+
if (this.socket) {
|
|
40
|
+
this.socket.onopen = null;
|
|
41
|
+
this.socket.onmessage = null;
|
|
42
|
+
this.socket.onclose = null;
|
|
43
|
+
this.socket.onerror = null;
|
|
44
|
+
try {
|
|
45
|
+
this.socket.close();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
this.socket = null;
|
|
50
|
+
this.emitState("closed");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public send(message: any): boolean {
|
|
54
|
+
if (!this.socket || this.socket.readyState != WebSocket.OPEN) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
this.socket.send(JSON.stringify(message));
|
|
59
|
+
return true;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private openSocket() {
|
|
66
|
+
if (!this.options || !this.options.wsUrl) return;
|
|
67
|
+
this.clearHeartbeat();
|
|
68
|
+
this.emitState("connecting");
|
|
69
|
+
let options = this.options;
|
|
70
|
+
let query: { [key: string]: string } = {
|
|
71
|
+
roomId: options.roomId,
|
|
72
|
+
deviceId: options.deviceId,
|
|
73
|
+
role: "game",
|
|
74
|
+
userId: options.userId,
|
|
75
|
+
userType: options.userType,
|
|
76
|
+
maxMembers: String(options.maxMembers)
|
|
77
|
+
};
|
|
78
|
+
if (options.guestId) query.guestId = options.guestId;
|
|
79
|
+
if (options.token) query.token = options.token;
|
|
80
|
+
let url = this.appendParams(options.wsUrl, query);
|
|
81
|
+
try {
|
|
82
|
+
this.socket = new WebSocket(url);
|
|
83
|
+
this.socket.onopen = this.handleOpen.bind(this);
|
|
84
|
+
this.socket.onmessage = this.handleMessage.bind(this);
|
|
85
|
+
this.socket.onclose = this.handleClose.bind(this);
|
|
86
|
+
this.socket.onerror = this.handleError.bind(this);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
this.handleError(e);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private handleOpen() {
|
|
93
|
+
if (!this.options) return;
|
|
94
|
+
this.reconnectCount = 0;
|
|
95
|
+
this.emitState("open");
|
|
96
|
+
let joinMessage: any = {
|
|
97
|
+
type: "join",
|
|
98
|
+
roomId: this.options.roomId,
|
|
99
|
+
role: "game",
|
|
100
|
+
deviceId: this.options.deviceId,
|
|
101
|
+
userId: this.options.userId,
|
|
102
|
+
userType: this.options.userType,
|
|
103
|
+
maxMembers: this.options.maxMembers,
|
|
104
|
+
game: this.options.game
|
|
105
|
+
};
|
|
106
|
+
if (this.options.guestId) joinMessage.guestId = this.options.guestId;
|
|
107
|
+
if (this.options.token) joinMessage.token = this.options.token;
|
|
108
|
+
console.log("[VirtualGamepad][WSS][Send] join", {
|
|
109
|
+
type: joinMessage.type,
|
|
110
|
+
roomId: joinMessage.roomId,
|
|
111
|
+
role: joinMessage.role,
|
|
112
|
+
deviceId: joinMessage.deviceId,
|
|
113
|
+
userId: joinMessage.userId,
|
|
114
|
+
userType: joinMessage.userType,
|
|
115
|
+
guestId: joinMessage.guestId || "",
|
|
116
|
+
maxMembers: joinMessage.maxMembers,
|
|
117
|
+
game: joinMessage.game,
|
|
118
|
+
hasToken: !!joinMessage.token
|
|
119
|
+
});
|
|
120
|
+
this.send(joinMessage);
|
|
121
|
+
this.startHeartbeat();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private handleMessage(event: MessageEvent) {
|
|
125
|
+
let data = event && event.data;
|
|
126
|
+
let message: any = null;
|
|
127
|
+
try {
|
|
128
|
+
message = typeof data == "string" ? JSON.parse(data) : data;
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!message) return;
|
|
133
|
+
if (message.type != "pong") {
|
|
134
|
+
console.log("[VirtualGamepad][WSS][Receive]", message);
|
|
135
|
+
}
|
|
136
|
+
if (message.type == "joined" || message.type == "welcome") {
|
|
137
|
+
this.emitState("joined");
|
|
138
|
+
}
|
|
139
|
+
if (this.onMessage) {
|
|
140
|
+
this.onMessage(message);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private handleClose(event?: any) {
|
|
145
|
+
this.clearHeartbeat();
|
|
146
|
+
this.socket = null;
|
|
147
|
+
this.emitState("closed", event && event.reason);
|
|
148
|
+
if (!this.manualClose) {
|
|
149
|
+
this.scheduleReconnect();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private handleError(event?: any) {
|
|
154
|
+
this.emitState("error", event && event.message);
|
|
155
|
+
if (!this.manualClose && (!this.socket || this.socket.readyState == WebSocket.CLOSED)) {
|
|
156
|
+
this.scheduleReconnect();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private startHeartbeat() {
|
|
161
|
+
this.clearHeartbeat();
|
|
162
|
+
this.heartbeatTimer = setInterval(() => {
|
|
163
|
+
if (!this.options) return;
|
|
164
|
+
this.send({
|
|
165
|
+
type: "ping",
|
|
166
|
+
roomId: this.options.roomId,
|
|
167
|
+
deviceId: this.options.deviceId,
|
|
168
|
+
role: "game",
|
|
169
|
+
timestamp: Date.now(),
|
|
170
|
+
ts: Date.now()
|
|
171
|
+
});
|
|
172
|
+
}, this.heartbeatMs);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private scheduleReconnect() {
|
|
176
|
+
if (this.reconnectCount >= this.maxReconnectCount) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
this.clearReconnect();
|
|
180
|
+
this.reconnectCount++;
|
|
181
|
+
this.reconnectTimer = setTimeout(() => {
|
|
182
|
+
this.openSocket();
|
|
183
|
+
}, 1200 * this.reconnectCount);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private appendParams(url: string, params: { [key: string]: string }): string {
|
|
187
|
+
let query = [];
|
|
188
|
+
for (let key in params) {
|
|
189
|
+
query.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key] || ""));
|
|
190
|
+
}
|
|
191
|
+
let separator = url.indexOf("?") >= 0 ? "&" : "?";
|
|
192
|
+
return url + separator + query.join("&");
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private emitState(state: VirtualGamepadConnectionState, reason?: string) {
|
|
196
|
+
if (this.onStateChange) {
|
|
197
|
+
this.onStateChange(state, reason);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private clearHeartbeat() {
|
|
202
|
+
if (this.heartbeatTimer != -1) {
|
|
203
|
+
clearInterval(this.heartbeatTimer);
|
|
204
|
+
this.heartbeatTimer = -1;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private clearReconnect() {
|
|
209
|
+
if (this.reconnectTimer != -1) {
|
|
210
|
+
clearTimeout(this.reconnectTimer);
|
|
211
|
+
this.reconnectTimer = -1;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export const VIRTUAL_GAMEPAD_GAME_ID = "rexueqiangshou";
|
|
2
|
+
declare const global: any;
|
|
3
|
+
export const VIRTUAL_GAMEPAD_PLAYER_ID = "player1";
|
|
4
|
+
export const VIRTUAL_GAMEPAD_DEVELOPMENT_WS_URL = "ws://10.40.92.42:3000";
|
|
5
|
+
export const VIRTUAL_GAMEPAD_PRODUCTION_WS_URL = "wss://hyp.huyingpai.com/huyingpai/lewo/ws";
|
|
6
|
+
export const VIRTUAL_GAMEPAD_H5_URL = "https://docp.daoran.tv/vconsole/index.html";
|
|
7
|
+
export const VIRTUAL_GAMEPAD_DEVELOPMENT_WXACODE_URL = "https://hyp.huyingpai.com/API_USER_CS/wxacode/unlimited";
|
|
8
|
+
export const VIRTUAL_GAMEPAD_PRODUCTION_WXACODE_URL = "https://hyp.huyingpai.com/API_USER/wxacode/unlimited";
|
|
9
|
+
export const VIRTUAL_GAMEPAD_WXACODE_PAGE = "pages/gamepad/gamepad";
|
|
10
|
+
export const VIRTUAL_GAMEPAD_WXACODE_PROJECT_CODE = "lewo";
|
|
11
|
+
export const VIRTUAL_GAMEPAD_MAX_MEMBERS = 2;
|
|
12
|
+
export const VIRTUAL_GAMEPAD_STOP_TIMEOUT_MS = 500;
|
|
13
|
+
export type VirtualGamepadEnvironment = "development" | "production";
|
|
14
|
+
export const VIRTUAL_GAMEPAD_DEFAULT_ENVIRONMENT: VirtualGamepadEnvironment = "production";
|
|
15
|
+
export type VirtualGamepadQrMode = "h5" | "json";
|
|
16
|
+
export const VIRTUAL_GAMEPAD_QR_MODE: VirtualGamepadQrMode = "h5";
|
|
17
|
+
|
|
18
|
+
export default class VirtualGamepadConfig {
|
|
19
|
+
public static getWsUrl(): string {
|
|
20
|
+
return this.getRuntimeValue("RXQS_GAMEPAD_WS_URL") ||
|
|
21
|
+
(this.getEnvironment() == "production" ? VIRTUAL_GAMEPAD_PRODUCTION_WS_URL : VIRTUAL_GAMEPAD_DEVELOPMENT_WS_URL);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static getWxacodeUrl(): string {
|
|
25
|
+
return this.getRuntimeValue("RXQS_GAMEPAD_WXACODE_URL") ||
|
|
26
|
+
(this.getEnvironment() == "production" ? VIRTUAL_GAMEPAD_PRODUCTION_WXACODE_URL : VIRTUAL_GAMEPAD_DEVELOPMENT_WXACODE_URL);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public static getEnvironment(): VirtualGamepadEnvironment {
|
|
30
|
+
let environment = this.getRuntimeValue("RXQS_GAMEPAD_ENVIRONMENT");
|
|
31
|
+
if (environment == "development" || environment == "production") {
|
|
32
|
+
return environment;
|
|
33
|
+
}
|
|
34
|
+
if (environment == "test") {
|
|
35
|
+
return "development";
|
|
36
|
+
}
|
|
37
|
+
return VIRTUAL_GAMEPAD_DEFAULT_ENVIRONMENT;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static getH5Url(): string {
|
|
41
|
+
return this.getRuntimeValue("RXQS_GAMEPAD_H5_URL") || VIRTUAL_GAMEPAD_H5_URL;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public static getRoomId(): string {
|
|
45
|
+
return this.getRuntimeValue("RXQS_GAMEPAD_ROOM_ID");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public static getToken(): string {
|
|
49
|
+
return this.getRuntimeValue("RXQS_GAMEPAD_TOKEN");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static getQrMode(): VirtualGamepadQrMode {
|
|
53
|
+
let mode = this.getRuntimeValue("RXQS_GAMEPAD_QR_MODE");
|
|
54
|
+
return mode == "json" ? "json" : VIRTUAL_GAMEPAD_QR_MODE;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private static getRuntimeValue(key: string): string {
|
|
58
|
+
let runtimeRoot: any = typeof window != "undefined" ? window : (typeof global != "undefined" ? global : null);
|
|
59
|
+
if (runtimeRoot && runtimeRoot[key]) {
|
|
60
|
+
return String(runtimeRoot[key]);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
if (cc && cc.sys && cc.sys.localStorage) {
|
|
64
|
+
return cc.sys.localStorage.getItem(key) || "";
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {
|
|
67
|
+
}
|
|
68
|
+
return "";
|
|
69
|
+
}
|
|
70
|
+
}
|