Queueing connections to server to preserve bandwidth in case of multiple calls (deck stats, card info) by cancelling previous unfinished calls.
This commit is contained in:
@@ -47,6 +47,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery/jquery-1.6.2.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.ajaxq-0.0.1.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.cookie.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.layout.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.touchSwipe.js"></script>
|
||||
|
||||
@@ -125,6 +125,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery/jquery-1.6.2.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.ajaxq-0.0.1.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.cookie.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.spinnercontrol.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.touchSwipe.js"></script>
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery/jquery-1.6.2.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.ajaxq-0.0.1.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/inheritance.js"></script>
|
||||
<script type="text/javascript" src="js/logging.js"></script>
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/jquery/jquery-1.6.2.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>
|
||||
<script type="text/javascript" src="js/jquery/jquery.ajaxq-0.0.1.js"></script>
|
||||
|
||||
<script type="text/javascript" src="js/inheritance.js"></script>
|
||||
<script type="text/javascript" src="js/logging.js"></script>
|
||||
|
||||
@@ -8,7 +8,7 @@ var GempLotrCommunication = Class.extend({
|
||||
},
|
||||
|
||||
startGameSession: function(callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("gameState", {
|
||||
type: "GET",
|
||||
url: this.url + "/game/" + getUrlParam("gameId"),
|
||||
cache: false,
|
||||
@@ -19,7 +19,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
updateGameState: function(callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("gameState", {
|
||||
type: "POST",
|
||||
url: this.url + "/game/" + getUrlParam("gameId"),
|
||||
cache: false,
|
||||
@@ -30,7 +30,8 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
getGameCardModifiers: function(cardId, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("gameCardModifiers");
|
||||
$.ajaxq("gameCardModifiers", {
|
||||
type: "GET",
|
||||
url: this.url + "/game/" + getUrlParam("gameId") + "/cardInfo",
|
||||
cache: false,
|
||||
@@ -42,7 +43,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
gameDecisionMade: function(decisionId, response, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("gameState", {
|
||||
type: "POST",
|
||||
url: this.url + "/game/" + getUrlParam("gameId"),
|
||||
cache: false,
|
||||
@@ -56,7 +57,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
concede: function() {
|
||||
$.ajax({
|
||||
$.ajaxq("gameState", {
|
||||
type: "POST",
|
||||
url: this.url + "/game/" + getUrlParam("gameId") + "/concede",
|
||||
cache: false,
|
||||
@@ -67,7 +68,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
getDeck: function(deckType, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("deck", {
|
||||
type: "GET",
|
||||
url: this.url + "/deck/" + deckType,
|
||||
cache: false,
|
||||
@@ -79,7 +80,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
getCollection: function(collectionType, filter, start, count, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("collection", {
|
||||
type: "GET",
|
||||
url: this.url + "/collection/" + collectionType,
|
||||
cache: false,
|
||||
@@ -94,7 +95,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
saveDeck: function(deckType, contents, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("deck", {
|
||||
type: "POST",
|
||||
url: this.url + "/deck/" + deckType,
|
||||
cache: false,
|
||||
@@ -107,7 +108,8 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
getDeckStats: function(contents, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("deckStats");
|
||||
$.ajaxq("deckStats", {
|
||||
type: "POST",
|
||||
url: this.url + "/deck",
|
||||
cache: false,
|
||||
@@ -120,7 +122,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
startChat: function(room, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("chat", {
|
||||
type: "GET",
|
||||
url: this.url + "/chat/" + room,
|
||||
cache: false,
|
||||
@@ -132,7 +134,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
updateChat: function(room, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("chat", {
|
||||
type: "POST",
|
||||
url: this.url + "/chat/" + room,
|
||||
cache: false,
|
||||
@@ -144,7 +146,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
sendChatMessage: function(room, message, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("chat", {
|
||||
type: "POST",
|
||||
url: this.url + "/chat/" + room,
|
||||
cache: false,
|
||||
@@ -157,7 +159,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
getHall: function(callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("hall", {
|
||||
type: "GET",
|
||||
url: this.url + "/hall",
|
||||
cache: false,
|
||||
@@ -169,7 +171,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
joinTable: function(tableId, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("hall", {
|
||||
type: "POST",
|
||||
url: this.url + "/hall/" + tableId,
|
||||
cache: false,
|
||||
@@ -181,7 +183,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
createTable: function(format, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("hall", {
|
||||
type: "POST",
|
||||
url: this.url + "/hall",
|
||||
cache: false,
|
||||
@@ -194,7 +196,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
leaveTable: function() {
|
||||
$.ajax({
|
||||
$.ajaxq("hall", {
|
||||
type: "POST",
|
||||
url: this.url + "/hall/leave",
|
||||
cache: false,
|
||||
@@ -205,7 +207,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
getStatus: function(callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("status", {
|
||||
type: "GET",
|
||||
url: this.url + "/",
|
||||
cache: false,
|
||||
@@ -217,7 +219,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
login: function(login, password, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("login", {
|
||||
type: "POST",
|
||||
url: this.url + "/login",
|
||||
cache: false,
|
||||
@@ -231,7 +233,7 @@ var GempLotrCommunication = Class.extend({
|
||||
});
|
||||
},
|
||||
register: function(login, password, callback) {
|
||||
$.ajax({
|
||||
$.ajaxq("register", {
|
||||
type: "POST",
|
||||
url: this.url + "/register",
|
||||
cache: false,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* jQuery AjaxQ - AJAX request queueing for jQuery
|
||||
*
|
||||
* Version: 0.0.1
|
||||
* Date: July 22, 2008
|
||||
*
|
||||
* Copyright (c) 2008 Oleg Podolsky (oleg.podolsky@gmail.com)
|
||||
* Licensed under the MIT (MIT-LICENSE.txt) license.
|
||||
*
|
||||
* http://plugins.jquery.com/project/ajaxq
|
||||
* http://code.google.com/p/jquery-ajaxq/
|
||||
*/
|
||||
|
||||
jQuery.ajaxq = function (queue, options)
|
||||
{
|
||||
// Initialize storage for request queues if it's not initialized yet
|
||||
if (typeof document.ajaxq == "undefined") document.ajaxq = {q:{}, r:null};
|
||||
|
||||
// Initialize current queue if it's not initialized yet
|
||||
if (typeof document.ajaxq.q[queue] == "undefined") document.ajaxq.q[queue] = [];
|
||||
|
||||
if (typeof options != "undefined") // Request settings are given, enqueue the new request
|
||||
{
|
||||
// Copy the original options, because options.complete is going to be overridden
|
||||
|
||||
var optionsCopy = {};
|
||||
for (var o in options) optionsCopy[o] = options[o];
|
||||
options = optionsCopy;
|
||||
|
||||
// Override the original callback
|
||||
|
||||
var originalCompleteCallback = options.complete;
|
||||
|
||||
options.complete = function (request, status)
|
||||
{
|
||||
// Dequeue the current request
|
||||
document.ajaxq.q[queue].shift();
|
||||
document.ajaxq.r = null;
|
||||
|
||||
// Run the original callback
|
||||
if (originalCompleteCallback) originalCompleteCallback(request, status);
|
||||
|
||||
// Run the next request from the queue
|
||||
if (document.ajaxq.q[queue].length > 0) document.ajaxq.r = jQuery.ajax(document.ajaxq.q[queue][0]);
|
||||
};
|
||||
|
||||
// Enqueue the request
|
||||
document.ajaxq.q[queue].push(options);
|
||||
|
||||
// Also, if no request is currently running, start it
|
||||
if (document.ajaxq.q[queue].length == 1) document.ajaxq.r = jQuery.ajax(options);
|
||||
}
|
||||
else // No request settings are given, stop current request and clear the queue
|
||||
{
|
||||
if (document.ajaxq.r)
|
||||
{
|
||||
document.ajaxq.r.abort();
|
||||
document.ajaxq.r = null;
|
||||
}
|
||||
|
||||
document.ajaxq.q[queue] = [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user