2020-05-10 04:24:46 -07:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
|
|
class UrbitApi {
|
|
|
|
setAuthTokens(authTokens) {
|
|
|
|
this.authTokens = authTokens;
|
|
|
|
this.bindPaths = [];
|
|
|
|
}
|
|
|
|
|
2020-05-10 04:30:23 -07:00
|
|
|
bind(path, method, ship = this.authTokens.ship, appl = "barttile", success, fail) {
|
2020-05-10 04:24:46 -07:00
|
|
|
this.bindPaths = _.uniq([...this.bindPaths, path]);
|
|
|
|
|
|
|
|
window.subscriptionId = window.urb.subscribe(ship, appl, path,
|
|
|
|
(err) => {
|
|
|
|
fail(err);
|
|
|
|
},
|
|
|
|
(event) => {
|
|
|
|
success({
|
|
|
|
data: event,
|
|
|
|
from: {
|
|
|
|
ship,
|
|
|
|
path
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
fail(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-10 04:30:23 -07:00
|
|
|
barttile(data) {
|
|
|
|
this.action("barttile", "json", data);
|
2020-05-10 04:24:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
action(appl, mark, data) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
window.urb.poke(ship, appl, mark, data,
|
|
|
|
(json) => {
|
|
|
|
resolve(json);
|
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
reject(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export let api = new UrbitApi();
|
|
|
|
window.api = api;
|