conwetlab / ngsi-proxy

Proxy allowing receiving notifications from Orion Context Broker on browser environments
GNU Affero General Public License v3.0
8 stars 9 forks source link

Improve documentation - API use without wirecloud #12

Open pabSec opened 5 years ago

pabSec commented 5 years ago

I would love to know how could it be used without Wirecloud, just as a proxy between Orion Context Broker and our custom react app.

How do we manage the Orion subscription from the proxy?

Thanks

PanagiotisFlorous commented 10 months ago

I am beyond late for this to be relevant for @pabSec but in case anyone else ends up watching this issue and needs an answer for this the documentation posted by @ammopt in https://github.com/conwetlab/ngsi-proxy/issues/19 works great.

For my React application I managed to get dynamic updates from Stellio and re-render my dashboard using:

const [myState, setMyState] = useState(0)

useEffect(() => {
        const sse = new EventSource(
            "http://{ngsiproxyurl}/eventsource/08e19900-bf77-11ee-b2d3-5f8162a71691"
        );
        sse.addEventListener("notification", function (e) {
            const payload = JSON.parse(JSON.parse(e.data).payload);
            setMyState(payload.data[0].state.value);
        });
    });