theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
32 lines • 964 B
JavaScript
import { NativeModules } from 'react-native';
const ThetaClientReactNative = NativeModules.ThetaClientReactNative;
const NOTIFY_EVENT = 'EVENT-WEBSOCKET-EVENT';
const NOTIFY_CLOSE = 'EVENT-WEBSOCKET-CLOSE';
export 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();
}
}
//# sourceMappingURL=event-websocket.js.map