- make a config js file for URIs and debug mode
- clean up the ordering of stuff in game.jsp - only back off 1ms after a successful longpoll, but do the normal backoff delays after error
This commit is contained in:
parent
f08785cdaa
commit
987c01cc5a
|
@ -2,7 +2,13 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8" %>
|
||||
<%@ page import="javax.servlet.http.HttpSession" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<%
|
||||
// Ensure a session exists for the user.
|
||||
@SuppressWarnings("unused")
|
||||
HttpSession hSession = request.getSession(true);
|
||||
%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
@ -11,6 +17,7 @@
|
|||
<script type="text/javascript" src="js/jquery.cookie.js"></script>
|
||||
<script type="text/javascript" src="js/QTransform.js"></script>
|
||||
<script type="text/javascript" src="js/cah.js"></script>
|
||||
<script type="text/javascript" src="js/cah.config.js"></script>
|
||||
<%-- cah must be first, ajax must be before app. app probably has to be last. --%>
|
||||
<%-- TODO make this be dynamic with looking at the filesystem and using jquery --%>
|
||||
<%-- except that is nontrivial thanks to dependency ordering -_- --%>
|
||||
|
@ -28,11 +35,6 @@
|
|||
<link rel="stylesheet" type="text/css" href="cah.css" media="screen" />
|
||||
</head>
|
||||
<body>
|
||||
<%-- Ensure a session exists for the user. --%>
|
||||
<% HttpSession hSession = request.getSession(true); %>
|
||||
<%--
|
||||
< % = new net.socialgamer.cah.data.WhiteDeck().getNextCard().toString() % >
|
||||
--%>
|
||||
|
||||
<%--
|
||||
<div id="browser" class="hide">
|
||||
|
|
|
@ -36,7 +36,7 @@ $(document).ready(function() {
|
|||
success : cah.Ajax.instance.done,
|
||||
timeout : cah.DEBUG ? undefined : 10 * 1000, // 10 second timeout for normal requests
|
||||
type : 'POST',
|
||||
url : '/cah/AjaxServlet'
|
||||
url : cah.AJAX_URI,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -64,13 +64,15 @@ cah.Ajax.prototype.error = function(jqXHR, textStatus, errorThrown) {
|
|||
// TODO deal with this somehow
|
||||
// and figure out which request it was so we can remove it from pending
|
||||
debugger;
|
||||
cah.log.error(textStatus);
|
||||
cah.log.error(textStatus + " " + errorThrown);
|
||||
};
|
||||
|
||||
cah.Ajax.prototype.done = function(data) {
|
||||
cah.log.debug("ajax done", data);
|
||||
if (data[cah.$.AjaxResponse.ERROR]) {
|
||||
// TODO cancel any timers or whatever we may have, and disable interface
|
||||
// or probably in individual error handlers as there are some errors that are fine like
|
||||
// "you don't have that card" etc.
|
||||
var req = this.pendingRequests[data[cah.$.AjaxResponse.SERIAL]];
|
||||
if (req && cah.ajax.ErrorHandlers[req.getOp()]) {
|
||||
cah.ajax.ErrorHandlers[req.getOp()](data);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* Configuration file.
|
||||
*
|
||||
* @author ajanata
|
||||
*/
|
||||
|
||||
cah.DEBUG = false;
|
||||
cah.SILENT_DEBUG = false;
|
||||
|
||||
cah.AJAX_URI = "/cah/AjaxServlet";
|
||||
cah.LONGPOLL_URI = "/cah/LongPollServlet";
|
|
@ -1,8 +1,5 @@
|
|||
var cah = {};
|
||||
|
||||
cah.DEBUG = false;
|
||||
cah.SILENT_DEBUG = false;
|
||||
|
||||
/**
|
||||
* This client's nickname.
|
||||
*
|
||||
|
|
|
@ -7,7 +7,18 @@
|
|||
cah.longpoll = {};
|
||||
cah.longpoll.TIMEOUT = 2 * 60 * 1000;
|
||||
// cah.longpoll.TIMEOUT = 30 * 1000;
|
||||
/**
|
||||
* Backoff when there was an error.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
cah.longpoll.INITIAL_BACKOFF = 500;
|
||||
/**
|
||||
* Backoff after a successful request.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
cah.longpoll.NORMAL_BACKOFF = 1;
|
||||
cah.longpoll.Backoff = cah.longpoll.INITIAL_BACKOFF;
|
||||
cah.longpoll.Resume = true;
|
||||
cah.longpoll.ErrorCodeHandlers = {};
|
||||
|
@ -20,7 +31,7 @@ cah.longpoll.longPoll = function() {
|
|||
error : cah.longpoll.error,
|
||||
success : cah.longpoll.done,
|
||||
timeout : cah.longpoll.TIMEOUT,
|
||||
url : '/cah/LongPollServlet',
|
||||
url : cah.LONGPOLL_URI,
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -65,13 +76,17 @@ cah.longpoll.done = function(data_list) {
|
|||
}
|
||||
|
||||
// reset the backoff to normal when there's a successful operation
|
||||
cah.longpoll.Backoff = cah.longpoll.INITIAL_BACKOFF;
|
||||
cah.longpoll.Backoff = cah.longpoll.NORMAL_BACKOFF;
|
||||
};
|
||||
|
||||
cah.longpoll.error = function(jqXHR, textStatus, errorThrown) {
|
||||
// TODO deal with this somehow
|
||||
cah.log.debug(textStatus);
|
||||
cah.longpoll.Backoff *= 2;
|
||||
if (cah.longpoll.Backoff < cah.longpoll.INITIAL_BACKOFF) {
|
||||
cah.longpoll.Backoff = cah.longpoll.INITIAL_BACKOFF;
|
||||
} else {
|
||||
cah.longpoll.Backoff *= 2;
|
||||
}
|
||||
cah.log
|
||||
.error("Error communicating with server. Will try again in " + (cah.longpoll.Backoff / 1000)
|
||||
+ " second" + (cah.longpoll.Backoff != 1000 ? "s" : "") + ".");
|
||||
|
|
Loading…
Reference in New Issue