textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
42 lines (41 loc) • 1.99 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../core/api");
const handlers_1 = require("../helpers/handlers");
/**
* Observe is an API to stream updates from a thread or all threads
*/
class Observe extends api_1.API {
/**
* Observe to updates in a thread or all threads
* An update is generated when a new block is added to a thread. See [[Block.BlockType]] for
* details and a list of block types to which you can observe.
*
* @param types List of event types to stream (e.g., ['FILES', 'COMMENTS', 'LIKES']. Leave
* undefined or empty to include all types.
* @param thread Limit updates to a single thread. Leave undefined or an empty stream to
* stream events across all threads.
* @returns A ReadableStream of FeedItem objects.
*/
events(types, thread) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet(`observe${thread ? `/${thread}` : ''}`, undefined, {
type: (types || []).join('|')
});
if (!response.body) {
throw Error('Empty response stream');
}
return handlers_1.streamHandler(response.body);
});
}
}
exports.default = Observe;
;