Skip to content

Instantly share code, notes, and snippets.

View hendrikswan's full-sized avatar

hendrik swanepoel hendrikswan

View GitHub Profile
io.on('connection', (client) => {
// here you can start emitting events to the client
});
const io = require('socket.io')();
const io = require('socket.io')();
const port = 8000;
io.on('connection', (client) => {
client.on('subscribeToTimer', (interval) => {
console.log('client is subscribing to timer with interval ', interval);
setInterval(() => {
client.emit('timer', new Date());
}, interval);
const sync = createSync({
maxRetries: 3,
delayBetweenRetries: 2000,
syncAction: api.syncEvent,
});
// success
sync.syncedItems.subscribe(x => console.log(x.item));
// failure
const sync = createSync({
maxRetries: 3,
delayBetweenRetries: 2000,
syncAction: api.syncEvent,
});
// success
sync.syncedItems.subscribe(x => console.log(x.item));
// failure
const pendingItems = new Rx.Subject();
const failedItems = new Rx.Subject();
const syncedItems = new Rx.Subject();
const maxRetries = 3;
const queue = (item) => {
let workingItem = item;
if (!workingItem.sync) {
workingItem = {
pendingItems
.map(item => Rx.Observable.of(item).delay(item.sync.counter > 0 ? delayBetweenRetries : 0))
.mergeAll()
.subscribe((itemWithMetaData) => {
api.syncEvent(itemWithMetaData.item)
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event, going to try again');
const pendingItems = new Rx.Subject();
const maxRetries = 3;
const queue = (item) => {
let workingItem = item;
if (!workingItem.sync) {
workingItem = {
sync: { counter: 0 },
item,
const pendingItems = new Rx.Subject();
pendingItems.subscribe((item) => {
api.syncEvent(item)
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event, going to try again');
pendingItems.next(item);
const pendingItems = new Rx.Subject();
pendingItems.subscribe((item) => {
api.syncEvent(item)
.then((result) => {
console.log('successfully synced a mouse event');
})
.catch((reason) => {
console.error('got an error while trying to sync an event')
});