UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

39 lines (38 loc) 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventWebSocket = void 0; var _reactNative = require("react-native"); const ThetaClientReactNative = _reactNative.NativeModules.ThetaClientReactNative; 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 ThetaClientReactNative.eventWebSocketStart(); } catch (error) { this.notify.removeNotify(NOTIFY_EVENT); this.notify.removeNotify(NOTIFY_CLOSE); throw error; } } async stop() { await ThetaClientReactNative.eventWebSocketStop(); } } exports.EventWebSocket = EventWebSocket; //# sourceMappingURL=event-websocket.js.map