Skip to content

Commit 8ef7668

Browse files
authored
add isMobile, openUrlWithCookies (#64)
* add isMobile, openUrlWithCookies * add data.target
1 parent bbe47ea commit 8ef7668

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

jsproxy/proxy.jslib

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ var EzyFoxServerClientPlugin = {
9494
EzyLogger.console('start ping: clientName = ' + clientName);
9595
ezy.client.pingSchedule.stop();
9696
},
97+
'openUrlWithCookies': function(clientName, jsonData, callback) {
98+
var data = JSON.parse(jsonData);
99+
document.cookie = data.cookies;
100+
var newTab = window.open(data.url, data.target || '_blank');
101+
if (!newTab) {
102+
EzyLogger.console('Failed to open the new tab.');
103+
}
104+
}
97105
}
98106
},
99107

@@ -109,6 +117,14 @@ var EzyFoxServerClientPlugin = {
109117
EzyLogger.debug = value;
110118
},
111119

120+
isMobile: function () {
121+
var userAgent = window.navigator.userAgent.toLowerCase();
122+
var mobilePattern = /android|iphone|ipad|ipod/i;
123+
124+
return userAgent.search(mobilePattern) !== -1
125+
|| (userAgent.indexOf("macintosh") !== -1 && "ontouchend" in document);
126+
},
127+
112128
run4: function (clientName, functionName, jsonData, callback) {
113129
var clientNameString = UTF8ToString(clientName);
114130
var functionNameString = UTF8ToString(functionName);

unity/EzyWSClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public static void setJsDebug(bool value)
4848
jsDebug = value;
4949
}
5050

51+
public static bool isMobile()
52+
{
53+
#if UNITY_WEBGL && !UNITY_EDITOR
54+
return EzyWSProxy.isMobile();
55+
#else
56+
return false;
57+
#endif
58+
}
59+
5160
public void init()
5261
{
5362
String configJson = JsonConvert.SerializeObject(

unity/EzyWSProxy.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ EzyDelegates.DataHandlerDelegate callback
1717

1818
[DllImport("__Internal")]
1919
public static extern void setDebug(bool debug);
20+
21+
[DllImport("__Internal")]
22+
public static extern bool isMobile();
2023

2124
[DllImport("__Internal")]
2225
public static extern void run3(

0 commit comments

Comments
 (0)