Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.

Commit 2c2f0e6

Browse files
committed
use await-async correctly and better error handling of WebSocket-classes
1 parent bf8ab20 commit 2c2f0e6

File tree

9 files changed

+331
-198
lines changed

9 files changed

+331
-198
lines changed

unity-project/Assets/Moulin/DDP/account/DdpAccount.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
using UnityEngine;
2626
using System;
2727
using System.Text;
28+
using System.Threading.Tasks;
2829
#if WINDOWS_UWP
2930
using Windows.Security.Cryptography;
3031
using Windows.Security.Cryptography.Core;
@@ -109,41 +110,37 @@ private void HandleLogoutResult(MethodCall logoutCall) {
109110
}
110111
}
111112

112-
public IEnumerator CreateUserAndLogin(string username, string password) {
113+
public async Task CreateUserAndLogin(string username, string password) {
113114
JSONObject loginPasswordObj = JSONObject.Create();
114115
loginPasswordObj.AddField("username", username);
115116
loginPasswordObj.AddField("password", GetPasswordObj(password));
116117

117-
MethodCall loginCall = connection.Call("createUser", loginPasswordObj);
118-
yield return loginCall.WaitForResult();
119-
HandleLoginResult(loginCall);
118+
MethodCall loginCall = await connection.CallAsync("createUser", loginPasswordObj);
119+
loginCall.OnResult += HandleLoginResult;
120120
}
121121

122-
public IEnumerator Login(string username, string password) {
122+
public async Task Login(string username, string password) {
123123
JSONObject userObj = JSONObject.Create();
124124
userObj.AddField("username", username);
125125

126126
JSONObject loginPasswordObj = JSONObject.Create();
127127
loginPasswordObj.AddField("user", userObj);
128128
loginPasswordObj.AddField("password", GetPasswordObj(password));
129129

130-
MethodCall loginCall = connection.Call("login", loginPasswordObj);
131-
yield return loginCall.WaitForResult();
132-
HandleLoginResult(loginCall);
130+
MethodCall loginCall = await connection.CallAsync("login", loginPasswordObj);
131+
loginCall.OnResult += HandleLoginResult;
133132
}
134133

135-
public IEnumerator ResumeSession(string token) {
134+
public async Task ResumeSession(string token) {
136135
JSONObject tokenObj = JSONObject.Create();
137136
tokenObj.AddField("resume", token);
138137

139-
MethodCall loginCall = connection.Call("login", tokenObj);
140-
yield return loginCall.WaitForResult();
141-
HandleLoginResult(loginCall);
138+
MethodCall loginCall = await connection.CallAsync("login", tokenObj);
139+
loginCall.OnResult += HandleLoginResult;
142140
}
143141

144-
public IEnumerator Logout() {
145-
MethodCall logoutCall = connection.Call("logout");
146-
yield return logoutCall.WaitForResult();
142+
public async Task Logout() {
143+
MethodCall logoutCall = await connection.CallAsync("logout");
147144
HandleLogoutResult(logoutCall);
148145
}
149146

0 commit comments

Comments
 (0)