Skip to content

Commit 9869f95

Browse files
author
Paul Gilmore
committed
Merge pull request #13 from PlayFab/JS-versioned
JavaScript overhauled and ready for versioning
2 parents 8047905 + e80e8d1 commit 9869f95

File tree

322 files changed

+6595
-248062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+6595
-248062
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
testTitleData.json

PlayFabApiTest.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>PlayFab JavaScript Unit Tests</title>
6+
<link rel="stylesheet" href="code.jquery.com/qunit/qunit-1.19.0.css">
7+
</head>
8+
<body>
9+
<div id="qunit"></div>
10+
<div id="qunit-fixture"></div>
11+
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
12+
<script src="code.jquery.com/qunit/qunit-1.19.0.js"></script>
13+
<script src="PlayFabSDK/PlayFabAdminApi.js"></script>
14+
<script src="PlayFabSDK/PlayFabClientApi.js"></script>
15+
<script src="PlayFabSDK/PlayFabMatchmakerApi.js"></script>
16+
<script src="PlayFabSDK/PlayFabServerApi.js"></script>
17+
<script src="PlayFabApiTest.js"></script>
18+
</body>
19+
</html>

PlayFabApiTest.js

Lines changed: 420 additions & 0 deletions
Large diffs are not rendered by default.

PlayFabSDK/PlayFabAdminApi.js

Lines changed: 446 additions & 0 deletions
Large diffs are not rendered by default.

PlayFabSDK/PlayFabClientApi.js

Lines changed: 759 additions & 0 deletions
Large diffs are not rendered by default.

PlayFabSDK/PlayFabMatchmakerApi.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
var PlayFab = typeof PlayFab != 'undefined' ? PlayFab : {};
2+
3+
if(!PlayFab.settings) {
4+
PlayFab.settings = {
5+
titleID: null,
6+
developerSecretKey: null // For security reasons you must never expose this value to the client or players
7+
}
8+
}
9+
10+
if(!PlayFab._internalSettings) {
11+
PlayFab._internalSettings = {
12+
sessionTicket: null,
13+
sdkVersion: "0.0.151019",
14+
apiVersion: "1.7.20151019",
15+
productionServerUrl: ".playfabapi.com",
16+
logicServerUrl: null,
17+
18+
getServerUrl: function () {
19+
return "https://" + PlayFab.settings.titleId + PlayFab._internalSettings.productionServerUrl;
20+
},
21+
22+
getLogicServerUrl: function () {
23+
return PlayFab._internalSettings.logicServerUrl;
24+
},
25+
26+
executeRequest: function (completeUrl, data, authkey, authValue, callback) {
27+
if (callback != null && typeof (callback) != "function") {
28+
throw "Callback must be null of a function";
29+
}
30+
31+
if (data == null) {
32+
data = {};
33+
}
34+
35+
var startTime = new Date();
36+
37+
var requestBody = JSON.stringify(data);
38+
39+
var xhr = new XMLHttpRequest();completeUrl
40+
// window.console.log("URL: " + completeUrl);
41+
xhr.open("POST", completeUrl, true);
42+
43+
xhr.setRequestHeader('Content-Type', 'application/json');
44+
45+
if (authkey != null)
46+
xhr.setRequestHeader(authkey, authValue);
47+
48+
xhr.setRequestHeader('X-PlayFabSDK', "JavaScriptSDK-" + PlayFab._internalSettings.sdkVersion + "-" + PlayFab._internalSettings.apiVersion);
49+
50+
xhr.onloadend = function () {
51+
if (callback == null)
52+
return;
53+
54+
var result = null;
55+
try {
56+
// window.console.log("parsing json result: " + xhr.responseText);
57+
result = JSON.parse(xhr.responseText);
58+
} catch (e) {
59+
result = {
60+
code: 503, // Service Unavailable
61+
status: "Service Unavailable",
62+
error: "Connection error",
63+
errorCode: 2, // PlayFabErrorCode.ConnectionError
64+
errorMessage: xhr.responseText
65+
};
66+
}
67+
68+
result.CallBackTimeMS = new Date() - startTime;
69+
70+
if (result.code == 200)
71+
callback(result.data, null);
72+
else
73+
callback(null, result);
74+
}
75+
76+
xhr.onerror = function () {
77+
if (callback == null)
78+
return;
79+
80+
var result = null;
81+
try {
82+
result = JSON.parse(xhr.responseText);
83+
} catch (e) {
84+
result = {
85+
code: 503, // Service Unavailable
86+
status: "Service Unavailable",
87+
error: "Connection error",
88+
errorCode: 2, // PlayFabErrorCode.ConnectionError
89+
errorMessage: xhr.responseText
90+
};
91+
}
92+
93+
result.CallBackTimeMS = new Date() - startTime;
94+
callback(null, result);
95+
}
96+
97+
xhr.send(requestBody);
98+
}
99+
}
100+
}
101+
102+
PlayFab.MatchmakerApi = {
103+
AuthUser: function (request, callback) {
104+
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
105+
106+
PlayFab._internalSettings.executeRequest(PlayFab._internalSettings.getServerUrl() + "/Matchmaker/AuthUser", request, "X-SecretKey", PlayFab.settings.developerSecretKey, callback);
107+
},
108+
109+
PlayerJoined: function (request, callback) {
110+
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
111+
112+
PlayFab._internalSettings.executeRequest(PlayFab._internalSettings.getServerUrl() + "/Matchmaker/PlayerJoined", request, "X-SecretKey", PlayFab.settings.developerSecretKey, callback);
113+
},
114+
115+
PlayerLeft: function (request, callback) {
116+
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
117+
118+
PlayFab._internalSettings.executeRequest(PlayFab._internalSettings.getServerUrl() + "/Matchmaker/PlayerLeft", request, "X-SecretKey", PlayFab.settings.developerSecretKey, callback);
119+
},
120+
121+
StartGame: function (request, callback) {
122+
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
123+
124+
PlayFab._internalSettings.executeRequest(PlayFab._internalSettings.getServerUrl() + "/Matchmaker/StartGame", request, "X-SecretKey", PlayFab.settings.developerSecretKey, callback);
125+
},
126+
127+
UserInfo: function (request, callback) {
128+
if (PlayFab.settings.developerSecretKey == null) throw "Must have PlayFab.settings.developerSecretKey set to call this method";
129+
130+
PlayFab._internalSettings.executeRequest(PlayFab._internalSettings.getServerUrl() + "/Matchmaker/UserInfo", request, "X-SecretKey", PlayFab.settings.developerSecretKey, callback);
131+
},
132+
133+
};
134+
135+
var PlayFabMatchmakerSDK = PlayFab.MatchmakerApi;

0 commit comments

Comments
 (0)