0.0.52 • Published 5 years ago
speedee v0.0.52
🚀 Client Socket COM Library.
Author: shuo, Wang
Email: jacshuo@gmail.com
Build Command:
npm run build:var // for build directory to browser usages.
npm run build:amd // for Javascript AMD standard.
npm run build:umd // for Javascript UMD standard.
npm run build:umd-cocos // for cocos/egret clients.
npm run protobuild // for building new protobuf after updating the .proto files.
Usage:
// initialize speedee lib with client type & Gateway service lists.
speedee.init(speedee.CLIENT,'http://100.64.15.101:9000', 5000) // note: 5000 for 5000ms interval heartbeats.
// websocket connection ready.
speedee.eventEmitter.on(speedee.READY,(socket)=>{
// User Login now is a public function provided by speedee.
// invoke system login like this (invoke common functions ONLY in speedee.READY callback!)
speedee.common.login('account','password', true) // note: 'password' should NOT be md5 hashed.
// then you can just bind listener on 'LOG_IN_SUCCESS' or 'LOG_IN_FAILED'.
// socket has some lower interface exposed for you to have more control on customized websocket, etc.
// Log
speedee.logger.info(1,2,'hey, how R you?')
// bussiness data
speedee.send(speedee.Commands.CMD_ENTERROOM_REQ, pbdata) // bussiness data transfer.
})
// connection error
speedee.eventEmitter.on(speedee.ERROR,(err)=>{
// console.error(`error:${err}`)
// error handlings
})
// websocket reconnect ready handling:
speedee.eventEmitter.on(speedee.RECONNECTED,()=>{
speedee.send(speedee.Commands.CMD_ENTERROOM_REQ, pbdata) // bussiness data transfer.
})
// websocket incomming message handling:
speedee.eventEmitter.on(speedee.MESSAGE,(message)=>{
// console.log(msg)
// msg type is Protobuffer.
// Bussiness code should dealing with unpacking pb msg according to Commands type.
/*
interface message {
cmd: <Commands> // for commands type.
msg: <ArrayBuffer> // raw arraybuffer pbdata.
}
*/
// do sth with message.cmd & message.msg
...
})
// Client login successfully
speedee.eventEmitter.on(speedee.LOG_IN_SUCCESS,(resp)=>{
// resp.result
// resp.passport <number>
// resp.agreed <boolean>
...
})
// Client login failed
speedee.eventEmitter.on(speedee.LOG_IN_FAILED,()=>{
// do sth with LOG IN FAILED.
})
speedee.EVENTS
enum Event {
ERROR = 'error', // websocket连接失败
READY = 'ready', // websocket连接建立成功
RECONNECTED = 'reconnected', // 重连成功
MESSAGE = 'message', // 需要业务端处理的Websocket业务类消息
TIMEOUT = 'timeout', // 连接超时
FETCH_GATEWAY_FAILED = 'fetch_gateway_failed', // 拉取网关列表失败
FETCH_GATEWAY_SUCCESS = 'fetch_gateway_success', // 拉取网关列表成功
LOG_IN_SUCCESS = 'login_success',// 客户端登录成功
LOG_IN_FAILED = 'login_failed',// 客户端登录失败
NOTIFY = 'notify', // GS->C, 通知消息
ENTER_ROOM_RSP = 'room_enter_response', // 进入房间消息返回
ENTER_TABLE_RSP='enter_table_response',// 入桌返回
ROOM_INFO_NOTIFY = 'room_info_notify' // GS->C, 通知房间的一些必要信息(只在Enter成功后通知)
}
speedee.LOGGER
class Logger{
//.....
public debug(subSys: string, clientId: string, data: string | Object | any): void {
this.log(subSys, clientId, data, 'debug');
}
public info(subSys: string, clientId: string, data: string | Object | any): void {
this.log(subSys, clientId, data, 'info');
}
public warn(subSys: string, clientId: string, data: string | Object | any): void {
this.log(subSys, clientId, data, 'warn');
}
public fatal(subSys: string, clientId: string, data: string | Object | any): void {
this.log(subSys, clientId, data, 'fatal');
}
//....
}
speedee.COMMANDS
enum Commands {
CMD_HEART_BEAT = 10000, // 心跳命令
CMD_LOG, // 日志服消息
CMD_REG, // 内部模块在网关注册的命令(外部网关朝内部网关注册也使用该命令)
CMD_GWNOTIFY, // GW回发的自己的识别符
CMD_SERVER_ONLINE, // 服务器上线
CMD_SERVER_BREAKLINE, // 服务器断线
CMD_BREAKLINE, // 客户端断线
CMD_NOTIFY, // GS->C, 通知消息
CMD_LOGIN_REQ, // C->AS, 登录请求
CMD_LOGIN_RSP, // AS->C, 登录返回
CMD_ENTERROOM_REQ, // C->MS, 进入游戏服
CMD_ENTERROOM_RSP, // GS->C, 进入游戏服的返回
CMD_ROOMINFO_NOTIFY, // GS->C, 通知房间的一些必要信息(只在Enter成功后通知)
CMD_ENTERTABLE_REQ, // C->GS, 入桌
CMD_ENTERTABLE_RSP, // GS->C, 入桌返回
CMD_LOOKON_REQ, // C->GS, 请求旁观
CMD_LOOKON_RSP, // GS->C, 旁观返回
CMD_GAME_SNAPSHOT, // GS->C, 重回only, 游戏快照
CMD_GAME, // GS<->C, 游戏内消息
CMD_KICKOFF, // R->GS, 裁判端要求踢人
CMD_DB_SERVERLOGIN_REQ, // 业务端请求登录DB
CMD_DB_SERVERLOGIN_RSP, // DB返回登录结果
CMD_DB_SERVERLOGOUT, // 服务器请求登出
CMD_DB_EXECUTE_REQ, // 请求执行
CMD_DB_EXECUTE_RSP, // 执行返回
CMD_DB_BATCHEXECUTE_REQ, // 请求批量执行
CMD_DB_BATCHEXECUTE_RSP // 批量返回
}
Automatically reconnection & refetching gateway service lists also implemented.
NOTE for the current version:
- Polling the best gateway algorithms NOT implemented due to upstream working flow still in progress.
- Polling now is just random picking.
- Incomming MSG type is Protobuffer since v0.0.23. DON'T USE PLAIN JSON STRING for sending data!
// service list example:
{
"100.64.15.101": {
"broadcast": [
{
"ip": "100.64.15.101",
"port": "23460"
}
],
"client": [
{
"ip": "100.64.15.101",
"port": "21006"
}
],
"judge": [
{
"ip": "100.64.15.101",
"port": "21005"
}
],
"ob": [
{
"ip": "100.64.15.101",
"port": "20001"
}
]
},
"100.64.15.102": {
"broadcast": [
{
"ip": "100.64.15.102",
"port": "23460"
}
],
"client": [
{
"ip": "100.64.15.102",
"port": "21006"
}
],
"judge": [
{
"ip": "100.64.15.102",
"port": "21005"
}
],
"ob": [
{
"ip": "100.64.15.102",
"port": "20001"
}
]
},
"100.64.15.103": {
"broadcast": [
{
"ip": "100.64.15.103",
"port": "23460"
}
],
"client": [
{
"ip": "100.64.15.103",
"port": "21006"
}
],
"judge": [
{
"ip": "100.64.15.103",
"port": "21005"
}
],
"ob": [
{
"ip": "100.64.15.103",
"port": "20001"
}
]
},
"100.64.15.104": {
"broadcast": [
{
"ip": "100.64.15.104",
"port": "23460"
}
],
"client": [
{
"ip": "100.64.15.104",
"port": "21006"
}
],
"judge": [
{
"ip": "100.64.15.104",
"port": "21005"
}
],
"ob": [
{
"ip": "100.64.15.104",
"port": "20001"
}
]
}
}
0.0.51
5 years ago
0.0.52
5 years ago
0.0.50
5 years ago
0.0.48
5 years ago
0.0.49
5 years ago
0.0.47
5 years ago
0.0.40
5 years ago
0.0.41
5 years ago
0.0.42
5 years ago
0.0.43
5 years ago
0.0.44
5 years ago
0.0.45
5 years ago
0.0.46
5 years ago
0.0.37
5 years ago
0.0.38
5 years ago
0.0.39
5 years ago
0.0.36
5 years ago
0.0.35
5 years ago
0.0.34
5 years ago
0.0.33
5 years ago
0.0.32
5 years ago
0.0.31
5 years ago
0.0.30
5 years ago
0.0.29
5 years ago
0.0.28
5 years ago
0.0.27
5 years ago
0.0.26
5 years ago
0.0.25
5 years ago
0.0.24
5 years ago
0.0.23
5 years ago
0.0.22
5 years ago
0.0.21
5 years ago
0.0.20
5 years ago
0.0.18
5 years ago
0.0.17
5 years ago
0.0.16
5 years ago
0.0.15
5 years ago
0.0.14
5 years ago
0.0.11
5 years ago
0.0.12
5 years ago
0.0.13
5 years ago
0.0.10
5 years ago
0.0.9
5 years ago
0.0.8
5 years ago
0.0.7
5 years ago
0.0.6
5 years ago
0.0.5
5 years ago
0.0.4
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago