tsrpc creator 2.4.7 demo
This commit is contained in:
4377
examples/cocos-creator-2.4.7/frontend/assets/Lobby.fire
Normal file
4377
examples/cocos-creator-2.4.7/frontend/assets/Lobby.fire
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"ver": "1.3.2",
|
||||
"uuid": "afd1e858-cfd0-487d-9bb2-08a676dc214e",
|
||||
"importer": "scene",
|
||||
"asyncLoadAssets": false,
|
||||
"autoReleaseAssets": false,
|
||||
"subMetas": {}
|
||||
}
|
13
examples/cocos-creator-2.4.7/frontend/assets/prefabs.meta
Normal file
13
examples/cocos-creator-2.4.7/frontend/assets/prefabs.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.3",
|
||||
"uuid": "c7b20543-c770-4080-b07d-a2e073bcc0a0",
|
||||
"importer": "folder",
|
||||
"isBundle": false,
|
||||
"bundleName": "",
|
||||
"priority": 1,
|
||||
"compressionType": {},
|
||||
"optimizeHotUpdate": {},
|
||||
"inlineSpriteFrames": {},
|
||||
"isRemoteBundle": {},
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.3",
|
||||
"uuid": "35dbc052-8b38-4ebc-a2d2-51bb5a939c87",
|
||||
"importer": "folder",
|
||||
"isBundle": false,
|
||||
"bundleName": "",
|
||||
"priority": 1,
|
||||
"compressionType": {},
|
||||
"optimizeHotUpdate": {},
|
||||
"inlineSpriteFrames": {},
|
||||
"isRemoteBundle": {},
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
|
||||
import { BaseWsClient } from 'tsrpc-base-client';
|
||||
import { WsClient as WsClientBrowser } from 'tsrpc-browser';
|
||||
import { MsgChat } from '../../scripts/shared/protocols/MsgChat';
|
||||
import { serviceProto, ServiceType } from '../../scripts/shared/protocols/serviceProto';
|
||||
import { ChatBoxMsgItem } from './ChatBox_MsgItem/ChatBoxMsgItem';
|
||||
const {ccclass, property} = cc._decorator;
|
||||
|
||||
|
||||
@ccclass('ChatBox')
|
||||
export class ChatBox extends cc.Component {
|
||||
|
||||
@property
|
||||
roomName = '';
|
||||
|
||||
// Prefabs
|
||||
@property(cc.Prefab)
|
||||
prefabMsgItem!: cc.Prefab;
|
||||
|
||||
// Nodes
|
||||
@property(cc.Label)
|
||||
labelTitle!: cc.Label;
|
||||
@property(cc.ScrollView)
|
||||
msgScroll!: cc.ScrollView;
|
||||
@property(cc.EditBox)
|
||||
inputSend!: cc.EditBox;
|
||||
|
||||
client!: BaseWsClient<ServiceType>;
|
||||
|
||||
onLoad() {
|
||||
// Create client by platform
|
||||
|
||||
this.client = new WsClientBrowser(serviceProto, {
|
||||
server: 'ws://127.0.0.1:3000',
|
||||
logger: console
|
||||
})
|
||||
|
||||
|
||||
// Connect at startup
|
||||
this.connect();
|
||||
|
||||
// Listen Msg
|
||||
this.client.listenMsg('Chat', v => { this.onChatMsg(v) })
|
||||
|
||||
// When disconnected
|
||||
this.client.flows.postDisconnectFlow.push(v => {
|
||||
// Retry after 2 seconds
|
||||
this.labelTitle.string = `🔴 Disconnected`;
|
||||
setTimeout(() => {
|
||||
this.connect();
|
||||
}, 2000)
|
||||
return v;
|
||||
})
|
||||
}
|
||||
|
||||
async connect(): Promise<void> {
|
||||
this.labelTitle.string = `🟡 Connecting...`;
|
||||
let res = await this.client.connect();
|
||||
if (!res.isSucc) {
|
||||
this.labelTitle.string = `🔴 Disconnected`;
|
||||
|
||||
// Retry after 2 seconds
|
||||
await new Promise(rs => { setTimeout(rs, 2000) });
|
||||
await this.connect();
|
||||
}
|
||||
|
||||
this.labelTitle.string = '🟢 ' + this.roomName;
|
||||
}
|
||||
|
||||
async send() {
|
||||
if (!this.inputSend.string) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ret = await this.client.callApi('Send', {
|
||||
content: this.inputSend.string
|
||||
});
|
||||
|
||||
// Error
|
||||
if (!ret.isSucc) {
|
||||
alert(ret.err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Success
|
||||
this.inputSend.string = '';
|
||||
}
|
||||
|
||||
onChatMsg(msg: MsgChat) {
|
||||
let node = cc.instantiate(this.prefabMsgItem);
|
||||
this.msgScroll.content!.addChild(node);
|
||||
node.getComponent(ChatBoxMsgItem)!.options = {
|
||||
msg: msg
|
||||
}
|
||||
this.msgScroll.scrollToBottom(0.2);
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"uuid": "59518273-f805-4423-bf97-815010a3a3ba",
|
||||
"importer": "typescript",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.3",
|
||||
"uuid": "6696c433-4f30-4fe7-8b17-0c4b44ab970b",
|
||||
"importer": "folder",
|
||||
"isBundle": false,
|
||||
"bundleName": "",
|
||||
"priority": 1,
|
||||
"compressionType": {},
|
||||
"optimizeHotUpdate": {},
|
||||
"inlineSpriteFrames": {},
|
||||
"isRemoteBundle": {},
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
import { MsgChat } from "../../../scripts/shared/protocols/MsgChat";
|
||||
|
||||
|
||||
|
||||
const { ccclass, property } = cc._decorator;
|
||||
|
||||
export interface ChatBoxMsgItemOptions {
|
||||
msg: MsgChat
|
||||
}
|
||||
|
||||
@ccclass('ChatBoxMsgItem')
|
||||
export class ChatBoxMsgItem extends cc.Component {
|
||||
|
||||
@property(cc.Label)
|
||||
labelMessage!: cc.Label;
|
||||
@property(cc.Label)
|
||||
labelTime!: cc.Label;
|
||||
|
||||
|
||||
private _options!: ChatBoxMsgItemOptions;
|
||||
public get options(): ChatBoxMsgItemOptions {
|
||||
return this._options;
|
||||
}
|
||||
public set options(v: ChatBoxMsgItemOptions) {
|
||||
this._options = v;
|
||||
|
||||
this.labelMessage.string = v.msg.content;
|
||||
this.labelTime.string = v.msg.time.toLocaleTimeString();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"ver": "1.1.0",
|
||||
"uuid": "78d1aea4-2634-4860-a2c9-782a04d067db",
|
||||
"importer": "typescript",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,421 @@
|
||||
[
|
||||
{
|
||||
"__type__": "cc.Prefab",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"_native": "",
|
||||
"data": {
|
||||
"__id__": 1
|
||||
},
|
||||
"optimizationPolicy": 0,
|
||||
"asyncLoadAssets": false,
|
||||
"readonly": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "ChatBox_MsgItem",
|
||||
"_objFlags": 0,
|
||||
"_parent": null,
|
||||
"_children": [
|
||||
{
|
||||
"__id__": 2
|
||||
},
|
||||
{
|
||||
"__id__": 6
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 10
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 12
|
||||
},
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 500,
|
||||
"height": 100
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
0,
|
||||
-60,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "message",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 3
|
||||
},
|
||||
{
|
||||
"__id__": 4
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 5
|
||||
},
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 0,
|
||||
"g": 0,
|
||||
"b": 0,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 450,
|
||||
"height": 54.239999999999995
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 1
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
-230,
|
||||
45,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_string": "messageeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffff",
|
||||
"_N$string": "messageeeeeeeeeeeeeeeeeeeffffffffffffffffffffffffffffffffffffffffff",
|
||||
"_fontSize": 24,
|
||||
"_lineHeight": 24,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_styleFlags": 0,
|
||||
"_underlineHeight": 0,
|
||||
"_N$horizontalAlign": 0,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 3,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 2
|
||||
},
|
||||
"_enabled": true,
|
||||
"alignMode": 1,
|
||||
"_target": null,
|
||||
"_alignFlags": 9,
|
||||
"_left": 20,
|
||||
"_right": 0,
|
||||
"_top": 5,
|
||||
"_bottom": 0,
|
||||
"_verticalCenter": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 0,
|
||||
"_originalHeight": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "2eXmKmE9BLPI02lVkytbrL",
|
||||
"sync": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "time",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 7
|
||||
},
|
||||
{
|
||||
"__id__": 8
|
||||
}
|
||||
],
|
||||
"_prefab": {
|
||||
"__id__": 9
|
||||
},
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 75,
|
||||
"g": 128,
|
||||
"b": 187,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 450,
|
||||
"height": 30.240000000000002
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 1,
|
||||
"y": 1
|
||||
},
|
||||
"_trs": {
|
||||
"__type__": "TypedArray",
|
||||
"ctor": "Float64Array",
|
||||
"array": [
|
||||
220,
|
||||
-14.759999999999998,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
]
|
||||
},
|
||||
"_eulerAngles": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_is3DNode": false,
|
||||
"_groupIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_string": "10.22.22",
|
||||
"_N$string": "10.22.22",
|
||||
"_fontSize": 24,
|
||||
"_lineHeight": 24,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_styleFlags": 0,
|
||||
"_underlineHeight": 0,
|
||||
"_N$horizontalAlign": 2,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 3,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Widget",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"alignMode": 1,
|
||||
"_target": null,
|
||||
"_alignFlags": 36,
|
||||
"_left": 20,
|
||||
"_right": 30,
|
||||
"_top": 5,
|
||||
"_bottom": 5,
|
||||
"_verticalCenter": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_isAbsLeft": true,
|
||||
"_isAbsRight": true,
|
||||
"_isAbsTop": true,
|
||||
"_isAbsBottom": true,
|
||||
"_isAbsHorizontalCenter": true,
|
||||
"_isAbsVerticalCenter": true,
|
||||
"_originalWidth": 450,
|
||||
"_originalHeight": 54.239999999999995,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "c4C1Aq66VNEpCu0sJZFvMD",
|
||||
"sync": false
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Sprite",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"_materials": [
|
||||
{
|
||||
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
|
||||
}
|
||||
],
|
||||
"_srcBlendFactor": 770,
|
||||
"_dstBlendFactor": 771,
|
||||
"_spriteFrame": {
|
||||
"__uuid__": "a23235d1-15db-4b95-8439-a2e005bfff91"
|
||||
},
|
||||
"_type": 0,
|
||||
"_sizeMode": 0,
|
||||
"_fillType": 0,
|
||||
"_fillCenter": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"_fillStart": 0,
|
||||
"_fillRange": 0,
|
||||
"_isTrimmedMode": true,
|
||||
"_atlas": null,
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "78d1a6kJjRIYKLJeCoE0Gfb",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 1
|
||||
},
|
||||
"_enabled": true,
|
||||
"labelMessage": {
|
||||
"__id__": 3
|
||||
},
|
||||
"labelTime": {
|
||||
"__id__": 7
|
||||
},
|
||||
"_id": ""
|
||||
},
|
||||
{
|
||||
"__type__": "cc.PrefabInfo",
|
||||
"root": {
|
||||
"__id__": 1
|
||||
},
|
||||
"asset": {
|
||||
"__id__": 0
|
||||
},
|
||||
"fileId": "",
|
||||
"sync": false
|
||||
}
|
||||
]
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.3.2",
|
||||
"uuid": "1aa44a1e-ba27-4984-b173-f385fca2a8b2",
|
||||
"importer": "prefab",
|
||||
"optimizationPolicy": "AUTO",
|
||||
"asyncLoadAssets": false,
|
||||
"readonly": false,
|
||||
"subMetas": {}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.3.2",
|
||||
"uuid": "ba339ce2-edd5-4916-8935-f8550c2e0c42",
|
||||
"importer": "prefab",
|
||||
"optimizationPolicy": "AUTO",
|
||||
"asyncLoadAssets": false,
|
||||
"readonly": false,
|
||||
"subMetas": {}
|
||||
}
|
13
examples/cocos-creator-2.4.7/frontend/assets/scripts.meta
Normal file
13
examples/cocos-creator-2.4.7/frontend/assets/scripts.meta
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.3",
|
||||
"uuid": "8edf980c-ff26-4b68-aca8-080c936b14dc",
|
||||
"importer": "folder",
|
||||
"isBundle": false,
|
||||
"bundleName": "",
|
||||
"priority": 1,
|
||||
"compressionType": {},
|
||||
"optimizeHotUpdate": {},
|
||||
"inlineSpriteFrames": {},
|
||||
"isRemoteBundle": {},
|
||||
"subMetas": {}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ver": "1.1.3",
|
||||
"uuid": "063ca637-20a7-466e-96c2-4cd414367a1d",
|
||||
"importer": "folder",
|
||||
"isBundle": false,
|
||||
"bundleName": "",
|
||||
"priority": 1,
|
||||
"compressionType": {},
|
||||
"optimizeHotUpdate": {},
|
||||
"inlineSpriteFrames": {},
|
||||
"isRemoteBundle": {},
|
||||
"subMetas": {}
|
||||
}
|
Reference in New Issue
Block a user