Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var r = require('rethinkdb');
var WebSocket = require('ws');
var ws = new WebSocket('wss://tictac.io/live/');
var conn = null;
r.connect({host: process.env.DB_HOST, db: 'tictactoe'})
.then(function (connection) {
conn = connection;
});
var emptyGrid = [[null, null, null],[null, null, null],[null, null, null]];
var currentGame = {
id: null,
team: null,
grid: emptyGrid,
winner: null,
frames: []
};
var gridToFrame = function (grid) {
// convert a 2-dimensional grid array to a 9-character string of only [0-2]
'host': 'localhost',
'port': 28015,
'db': 'realtime_photo_tutorial'
};
r.connections = [];
r.getNewConnection = function () {
return r.connect(dbConnection)
.then(function (conn) {
conn.use(dbConnection.db);
r.connections.push(conn);
return conn;
});
};
r.connect(dbConnection)
.then(function (conn) {
r.conn = conn;
r.connections.push(conn);
return r.dbCreate(dbConnection.db).run(r.conn)
.catch(function () {})
.then(function () {
r.conn.use(dbConnection.db);
// Create Tables
return r.tableList().run(r.conn)
.then(function (tableList) {
return q()
.then(function() {
if (tableList.indexOf('images') === -1) {
return r.tableCreate('images').run(r.conn);
}
});
let query = r.row('drawingId').eq(drawingId);
if (from) {
query = query.and(r.row('timestamp').ge(new Date(from)))
}
return r.table('lines')
.filter(query)
.changes({ include_initial: true, include_types: true })
.run(connection)
.then((cursor) => {
cursor.each((err, lineRow) => client.emit(`drawingLine:${drawingId}`, lineRow.new_val));
});
}
r.connect({
host: 'localhost',
port: 28015,
db: 'awesome_whiteboard'
}).then((connection) => {
io.on('connection', (client) => {
client.on('createDrawing', ({ name }) => {
createDrawing({ connection, name });
});
client.on('subscribeToDrawings', () => subscribeToDrawings({
client,
connection,
}));
client.on('publishLine', (line, callback) => handleLinePublish({
line,
function addIncoming(self, recordId, idToAdd){
return r.connect(self.connection).then(function(conn){
return r.table('data')
.get(recordId)
.update({ in: r.row('in').setInsert(idToAdd) })
.run(conn);
})
}
_init_connection () {
this._retry_timer = null
return r.connect(this._rdb_options).then((conn) => {
if (this._interrupted_err) {
return Promise.reject(this._interrupted_err)
}
this._conn = conn
logger.debug('Connection to RethinkDB established.')
return new Metadata(this._rdb_options.db,
conn,
this._clients,
this._auto_create_collection,
this._auto_create_index).ready()
}).then((metadata) => {
logger.info('Connection to RethinkDB ready: ' +
`${this._rdb_options.user} @ ${this._rdb_options.host}:${this._rdb_options.port}`)
this._metadata = metadata
this._reconnect_delay = 0
async online () : Promise {
try {
const conn = await r.connect( this.server.config.get( 'database' ) );
await conn.close();
return true;
} catch ( error ) {
return false;
}
}
async function checkConnection(crash, delay) {
var r = require('rethinkdb')
r.connect({
db: cxnOptions.db
}, function(err, conn) {
if (err) {
pino().error('\x1b[31m%s\x1b[0m', '... rethinkdb error')
setTimeout(function() {
pino().info('\x1b[33m%s\x1b[0m', '... retrying connection')
checkConnection(true, delay)
}, 5000)
} else {
if (crash) {
setTimeout(function() {}, delay)
}
}
})
}
async function processSuccess(job) {
function connect() {
return r.connect({ host: rethinkServer, port: 28015 });
}
return new Promise(function (resolve, reject) {
if (Connection) {
return resolve(Connection);
}
return r.connect({
db: DB_NAME,
host: process.env.RETHINKDB_HOST || 'ttt_db'
})
.then(function (conn) {
Connection = conn;
return;
})
.then(function () {
return resolve(Connection);
});
});
}