import { NativeModules, DeviceEventEmitter } from 'react-native'; const Server = NativeModules.HttpServerBridge; const httpServerBridge = { start: function ( port: number, serviceName: any, callback: (data: any) => void ) { if (port === 80) { throw 'Invalid server port specified. Port 80 is reserved.'; } Server.start(port, serviceName); DeviceEventEmitter.addListener('httpServerResponseReceived', callback); }, stop: function () { Server.stop(); DeviceEventEmitter.removeAllListeners('httpServerResponseReceived'); }, respond: function (requestId: any, code: any, type: any, body: any) { Server.respond(requestId, code, type, body); }, }; export default httpServerBridge;