Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix event recievers

ammarahm-ed1a37f0cef3a6
diff --git a/apps/mobile/src/utils/EventSource.js b/apps/mobile/src/utils/EventSource.js
new file mode 100644
index 000000000..48f80f366
--- /dev/null
+++ b/apps/mobile/src/utils/EventSource.js
@@ -0,0 +1,33 @@
+import {NativeEventEmitter, NativeModules, Platform} from 'react-native';
+
+const NativeEventSource = Platform.OS === "ios"? null : NativeModules.EventSource;
+const EventEmitter = Platform.OS === "ios"? null : new NativeEventEmitter(NativeEventSource);
+
+export default class EventSource {
+ constructor(url, options) {
+ this.url = url;
+ this.options = options;
+ this.connect();
+ }
+
+ connect() {
+ this.registerEvents();
+ NativeEventSource.initRequest(this.url, this.options.headers);
+ }
+
+ close() {
+ NativeEventSource.close();
+ }
+
+ registerEvents() {
+ EventEmitter.addListener('open', () => {
+ this.onopen();
+ });
+
+ EventEmitter.addListener("message", (ev) => {
+ const {message} = ev;
+ const eventData = {data: message};
+ this.onmessage(eventData);
+ });
+ }
+}
diff --git a/apps/mobile/src/utils/utils.js b/apps/mobile/src/utils/utils.js
index f27f4e1ef..b86c40e4d 100755
--- a/apps/mobile/src/utils/utils.js
+++ b/apps/mobile/src/utils/utils.js
@@ -1,16 +1,22 @@
-import {Dimensions} from 'react-native';
-import Database from "notes-core/api/";
+import {Dimensions, Platform} from 'react-native';
+import Database from 'notes-core/api/';
import {eSendEvent} from '../services/eventManager';
import {eShowToast, eHideToast} from '../services/events';
import {DeviceDetectionService} from './deviceDetection';
import StorageInterface, {MMKV} from './storage';
import {updateEvent} from '../components/DialogManager/recievers';
import {ACTIONS} from '../provider/actions';
-import EventSource from "rn-eventsource";
-global.Buffer = require("buffer").Buffer;
+import ESource from './event-source';
+import EventSource from 'rn-eventsource';
+
+global.Buffer = require('buffer').Buffer;
export const DDS = new DeviceDetectionService();
-export const db = new Database(StorageInterface, EventSource);
+export const db = new Database(
+ StorageInterface,
+ Platform.OS === 'ios' ? EventSource : ESource,
+);
+db.host('http://192.168.10.8:8000');
export async function setSetting(settings, name, value) {
let s = {...settings};