// Optional callback to get error status
add: function(game, callback) {
// Optional callback to get error status
add: function(game, callback) {
// obj: chat, move, fen, clocks, score[Msg], initime, ...
update: function(gameId, obj) {
// obj: chat, move, fen, clocks, score[Msg], initime, ...
update: function(gameId, obj) {
let objectStore = db
.transaction("games", "readwrite")
.objectStore("games");
objectStore.get(gameId).onsuccess = function(event) {
// Ignoring error silently: shouldn't happen now. TODO?
let objectStore = db
.transaction("games", "readwrite")
.objectStore("games");
objectStore.get(gameId).onsuccess = function(event) {
// Ignoring error silently: shouldn't happen now. TODO?
let game = event.target.result;
// Hidden tabs are delayed, to prevent multi-updates:
if (obj.moveIdx < game.moves.length) return;
Object.keys(obj).forEach(k => {
if (k == "move") game.moves.push(obj[k]);
else if (k == "chat") game.chats.push(obj[k]);
let game = event.target.result;
// Hidden tabs are delayed, to prevent multi-updates:
if (obj.moveIdx < game.moves.length) return;
Object.keys(obj).forEach(k => {
if (k == "move") game.moves.push(obj[k]);
else if (k == "chat") game.chats.push(obj[k]);
// Retrieve completed local games
getNext: function(upperDt, callback) {
// Retrieve completed local games
getNext: function(upperDt, callback) {
// NOTE: need callback because result is obtained asynchronously
get: function(gameId, callback) {
// NOTE: need callback because result is obtained asynchronously
get: function(gameId, callback) {
let objectStore = db.transaction("games").objectStore("games");
objectStore.get(gameId).onsuccess = function(event) {
// event.target.result is null if game not found
let objectStore = db.transaction("games").objectStore("games");
objectStore.get(gameId).onsuccess = function(event) {
// event.target.result is null if game not found
// Delete a game in indexedDB
remove: function(gameId, callback) {
// Delete a game in indexedDB
remove: function(gameId, callback) {
if (!err) {
let transaction = db.transaction("games", "readwrite");
transaction.oncomplete = function() {
if (!err) {
let transaction = db.transaction("games", "readwrite");
transaction.oncomplete = function() {