function getRtcConfig (cb) { xhr({ url: 'https://instant.io/_rtcConfig', timeout: 10000 }, (err, res) => { if (err || res.statusCode !== 200) { cb(new Error('Could not get WebRTC config from server. Using default (without TURN).')) } else { var rtcConfig try { rtcConfig = JSON.parse(res.body) } catch (err) { return cb(new Error('Got invalid WebRTC config from server: ' + res.body)) } cb(null, rtcConfig) } }) }
var loadComments = function() { xhr({ method: 'GET', uri: '/comments/load' + (LoginStore.getToken() ? '?token=' + LoginStore.getToken() : ''), responseType: 'json' }, function(err, resp, body) { if (err || !body) { return; } index = createIndex(body, {'0': { children: body }}); dispatch('0'); }); }
function doXHR(options) { return new Promise(function (resolve, reject) { xhr(options, function (err, resp, body) { if (err) { return reject(err.message); } if (resp.statusCode !== 200) { return reject(body); } var data = (typeof body === 'string')? JSON.parse(body) : body; resolve(data); }); }); }
xhr.get('/api/chat/channel/' + encodedGroupName + '/messages?limit=' + limit + '&offset=' + offset, { json: true, headers: { 'Content-Type': 'application/json' } }, function (err, resp) { if (err || resp.body.error) { me.events.fire('history-error', resp.rawRequest); return; } me._on_group_history_recvd(grp, resp.body); });
export function fetchData(url) { return function thunk(dispatch) { xhr({ url: url }, function (err, data) { var body = JSON.parse(data.body); var list = body.list; var dates = []; var temps = []; for (var i = 0; i < list.length; i++) { dates.push(list[i].dt_txt); temps.push(list[i].main.temp); } dispatch(setData(body)); dispatch(setDates(dates)); dispatch(setTemps(temps)); dispatch(setSelectedTemp(null)); dispatch(setSelectedDate('')); }); } }
xhr({ method: 'POST', uri: '/auth/verify', json: { user: user, token: token } }, function(err, resp, data) { if (!err && data.error === null) { // Use last token return; } user = ''; token = ''; emit(); });