theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
39 lines (38 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.EventWebSocket = void 0;
var _NativeThetaClientReactNative = _interopRequireDefault(require("../NativeThetaClientReactNative"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const NOTIFY_EVENT = 'EVENT-WEBSOCKET-EVENT';
const NOTIFY_CLOSE = 'EVENT-WEBSOCKET-CLOSE';
class EventWebSocket {
constructor(notify) {
this.notify = notify;
}
async start(onReceive, onClose) {
this.notify.addNotify(NOTIFY_EVENT, event => {
if (event.params != null) {
onReceive(event.params.event);
}
});
this.notify.addNotify(NOTIFY_CLOSE, () => {
onClose();
this.notify.removeNotify(NOTIFY_EVENT);
this.notify.removeNotify(NOTIFY_CLOSE);
});
try {
await _NativeThetaClientReactNative.default.eventWebSocketStart();
} catch (error) {
this.notify.removeNotify(NOTIFY_EVENT);
this.notify.removeNotify(NOTIFY_CLOSE);
throw error;
}
}
async stop() {
await _NativeThetaClientReactNative.default.eventWebSocketStop();
}
}
exports.EventWebSocket = EventWebSocket;
//# sourceMappingURL=event-websocket.js.map