Skip to content

Commit 545f3d3

Browse files
authored
Add ws ping schedule (#47)
* add websocket ping schedule * fix logger
1 parent a970487 commit 545f3d3

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

jsproxy/proxy.jslib

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ var EzyFoxServerClientPlugin = {
8686
.getClient(clientName)
8787
.send(cmd, sendData);
8888
},
89+
'startPing': function (clientName, callback) {
90+
EzyLogger.console('start ping: clientName = ' + clientName);
91+
ezy.client.pingSchedule.start();
92+
},
93+
'stopPing': function (clientName, callback) {
94+
EzyLogger.console('start ping: clientName = ' + clientName);
95+
ezy.client.pingSchedule.stop();
96+
},
8997
}
9098
},
9199

unity/EzyWSClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public EzyWSClient(EzyClientConfig config)
3838
this.config = config;
3939
this.status = EzyConnectionStatus.NULL;
4040
this.pingManager = new EzySimplePingManager(config.getPing());
41-
this.pingSchedule = new EzyPingSchedule(this);
41+
this.pingSchedule = new EzyWSPingSchedule(this);
4242
this.handlerManager = new EzySimpleHandlerManager(this);
4343
this.settingUp = new EzySimpleSetup(handlerManager);
4444
}

unity/EzyWSPingSchedule.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using AOT;
3+
using com.tvd12.ezyfoxserver.client.logger;
4+
using com.tvd12.ezyfoxserver.client.socket;
5+
6+
namespace com.tvd12.ezyfoxserver.client.unity
7+
{
8+
public class EzyWSPingSchedule : EzyPingSchedule
9+
{
10+
private static readonly EzyLogger LOGGER = EzyUnityLoggerFactory.getLogger(typeof(EzyWSPingSchedule));
11+
12+
public EzyWSPingSchedule(EzyClient client) : base(client)
13+
{
14+
}
15+
16+
public override void start()
17+
{
18+
EzyWSProxy.run3(
19+
client.getName(),
20+
"startPing",
21+
startPingCallback
22+
);
23+
}
24+
25+
[MonoPInvokeCallback(typeof(EzyDelegates.Delegate2))]
26+
public static void startPingCallback(
27+
String clientName,
28+
String jsonData
29+
)
30+
{
31+
LOGGER.debug(
32+
"startPingCallback: clientName = " +
33+
clientName + ", jsonData = " + jsonData
34+
);
35+
}
36+
37+
public override void stop()
38+
{
39+
EzyWSProxy.run3(
40+
client.getName(),
41+
"stopPing",
42+
stopPingCallback
43+
);
44+
}
45+
46+
[MonoPInvokeCallback(typeof(EzyDelegates.Delegate2))]
47+
public static void stopPingCallback(
48+
String clientName,
49+
String jsonData
50+
)
51+
{
52+
LOGGER.debug(
53+
"stopPingCallback: clientName = " +
54+
clientName + ", jsonData = " + jsonData
55+
);
56+
}
57+
58+
public override void setSocketEventQueue(EzySocketEventQueue socketEventQueue)
59+
{
60+
throw new InvalidOperationException("not supported");
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)