xspanger3770 / GlobalQuake

Experimental application for monitoring earthquakes world-wide in near real time. Capable of issuing its own earthquake early warnings (EEW).
MIT License
281 stars 41 forks source link

Realtime WebSockets Event Server #261

Open DecryptingElectrons opened 3 months ago

DecryptingElectrons commented 3 months ago

This is a http server with only websocket support. All other connections and path requests will be dropped.

Clients may connect over http and will be sent: -Event Creations -Event Updates -Event Deletions

5 new settings have been added.. -enableRTWSEventServer; -RTWSEventIP; -RTWSEventPort; -RTWSEventMaxConnections; -RTWSMaxConnectionsPerUniqueIP;

RTWSEventMaxConnections is the total number of connections allowed to the server.

RTWSMaxConnectionsPerUniqueIP is the total number of connections allowed for one unique IP address, for example, 1.1.1.1 | 8.8.8.8 are both unique IPs that can only have a certain number of connections each.

By default it is disabled.

Its init and start are a part of the main servers load sequence (when enabled).

Its path is /realtime_events/v1

This first version is meant to mimic the system available from EMSC at https://www.seismicportal.eu/realtime.html

Later i would like to improve it, adding many more features and options then the EMSC service. Soon also i will provide a sample html page to connect to the server and display the events.

dzlandis commented 3 months ago

May I suggest adding additional data to the ArchivedQuake part of things in order to allow for the transmission of additional important information such as quality and intensity levels? I think a lot of this information is crucial to the interpretation of websocket data.

Here's an example of how a few additional paramaters (quality and intensity levels) could be added but feel free to modify and add more properties as needed:

// ArchivedQuake.java
public JSONObject getGeoJSON() {
    JSONObject earthquakeJSON = new JSONObject();
    JSONObject estimatedIntensityJSON = new JSONObject();

    // more properties here...

    properties.put("quality", getQualityClass().toString());

    calculatePGA();
    estimatedIntensityJSON.put("mmi",
            IntensityScales.MMI.getLevel(getMaxPGA()) != null ? IntensityScales.MMI.getLevel(getMaxPGA()).toString()
                    : null);
    estimatedIntensityJSON.put("shindo",
            IntensityScales.SHINDO.getLevel(getMaxPGA()) != null
                    ? IntensityScales.SHINDO.getLevel(getMaxPGA()).toString()
                    : null);

    properties.put("estimated_intensity", estimatedIntensityJSON);

    // more properties here...

    return earthquakeJSON;
}
DecryptingElectrons commented 3 months ago

@dzlandis a plan to overhaul the fdsntext, geojson, and xml methods in a different PR as they are also used in the fdsnws-event module