Using Websocket API to 3rd party applications

Answered

Comments

8 comments

  • Avatar
    Andrey Terentyev

    Hello Reeve Hsu ,

    Please elaborate a bit what kind of alarms are you expecting to receive?

    Each server in the system has rule engine.

    You can configure an event rule triggering "Do HTTP request" action which would send your desired request to your desired external 3rd party application. See a screenshot. For more details on rules consult built in manual in Nx Desktop.

    0
    Comment actions Permalink
  • Avatar
    Reeve Hsu

    Hi Andrey Terentyev,

    The main idea is to forward the Camera Analytic alarm to a 3rd party platform with Variable parameters and Value. Instead of pushing to the 3rd party platform, I am thinking to use WebSocket to connect both NX and 3rd party platform as 'always ON' event trigger place, once NX get a new event, 3rd party platform should find it directly without GET or POST command by time interval.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Thanks. We are going to prepare a code example for you. Please, allow us some time.

    0
    Comment actions Permalink
  • Avatar
    Artem Zaytsev

    Hi Reeve Hsu.

    Unfortunately, I will not provide you a code example because there is no way to broadcast camera events without side-effects.

    The general rule is you must have some Desktop VMS client-related action to see an event broadcasted through WS API. To use it with your custom web application you have to dedicate some VMS client event action. This configuration is obscure and hard to support.

    0
    Comment actions Permalink
  • Avatar
    Reeve Hsu

    Artem Zaytsev thanks for your reply. What is purpose of this this web socket api in the real case, if we can't make 3rd party application to listen events from it?

    0
    Comment actions Permalink
  • Avatar
    Evgeny Balashov

    Looks like there are three options to move forward

    1. Making HTTP requests from the system like Andrey explained before. This is what we recommend.

    2. Pulling events from the server by making periodical HTTP requests to retrieve events log. As you mentioned, this is a suboptimal solution. To make this work event needs to trigger any action in the event rules dialog. Events that do not trigger any actions are ignored by the server

    3. Using WebSocket. To make it work, the event must trigger some desktop client action, such as show notifications, or text overlay. Only then the event will be delivered through WebSocket API. The side effect of this approach is that desktop client action. So if you do not want those events to be visible in the client application, you won't be able to use WebSocket API.

     

    Based on the three options I describe, what do you think works for you?

    Also, can you please explain the scenario in a bit more detail? What will the 3rd party platform do with the events? Is it ok for you if every such event is visible in the client application?

    0
    Comment actions Permalink
  • Avatar
    Reeve Hsu

    Thanks for your input,Evgeny Balashov   > 

    I am looking forward to the point 3 which using websocket method. Once the events are triggered, I can do the filtering to looking for all required inform from database, instead of do all different event setting. The 3rd party application supports Websocket and able to show the events from WS, however, the description from the API returns nothing with error, do you have sample code for it?

    0
    Comment actions Permalink
  • Avatar
    Artem Zaytsev

    Hi Reeve Hsu.

    Please see a Python 3 script that subscribes to the WS and prints all the messages. https://pastebin.com/LKQqqBev

    On camera event you will see something like the JSON below.

    {
    "tran": {
    "command": "broadcastAction",
    "historyAttributes": {
    "author": "{bc292159-2be9-4e84-a242-bc6122b315e4}"
    },
    "params": {
    "actionType": "showPopupAction",
    "aggregationCount": 2,
    "params": "eyJhY3Rpb25JZCI6Ins5NGUzMGQ3YS1lNjk1LTQ4YjMtOWNhMS1hODA2MzM4MTJlZWJ9IiwiYWxsVXNlcnMiOnRydWUsImF1dGhUeXBlIjoiYXV0aEJhc2ljQW5kRGlnZXN0IiwiZHVyYXRpb25NcyI6NTAwMCwiZm9yY2VkIjp0cnVlLCJmcHMiOjEwLCJuZWVkQ29uZmlybWF0aW9uIjpmYWxzZSwicGxheVRvQ2xpZW50Ijp0cnVlLCJyZWNvcmRBZnRlciI6MCwicmVjb3JkQmVmb3JlTXMiOjEwMDAsInJlcXVlc3RUeXBlIjoiIiwic3RyZWFtUXVhbGl0eSI6ImhpZ2hlc3QiLCJ1c2VTb3VyY2UiOmZhbHNlfQ==",
    "receivedFromRemoteHost": false,
    "resourceIds": [],
    "ruleId": "{d7f7cedd-fd74-2f86-98fa-55dc96aca736}",
    "runtimeParams": "eyJldmVudFJlc291cmNlSWQiOiJ7OGEzMzgxOGQtOTFiNy02ZWNhLWEwNzAtNDFhYzRjYTJlZDZjfSIsImV2ZW50VGltZXN0YW1wVXNlYyI6IjE1OTMxMTU2Mjg5OTkwMDAiLCJldmVudFR5cGUiOiJuZXR3b3JrSXNzdWVFdmVudCIsIm1ldGFkYXRhIjp7ImFsbFVzZXJzIjpmYWxzZSwibGV2ZWwiOiIwIn0sIm9taXREYkxvZ2dpbmciOmZhbHNlLCJyZWFzb25Db2RlIjoibmV0d29ya1J0cFBhY2tldExvc3MiLCJzb3VyY2VTZXJ2ZXJJZCI6Ins0NzUzOTAxYy05YTM5LWNlYWYtMTQwMy04MDg0NzRjZWU1ZWV9In0=",
    "toggleState": "Undefined"
    },
    "peerID": "{4753901c-9a39-ceaf-1403-808474cee5ee}",
    "persistentInfo": {
    "dbID": "{00000000-0000-0000-0000-000000000000}",
    "sequence": 0,
    "timestamp": {
    "sequence": "0",
    "ticks": "0"
    }
    },
    "transactionType": "Regular"
    }
    }

    params and runtimeParams are also base64-encoded JSONs with quite transparent structure.

    Please let us know whether it is helpful.

    0
    Comment actions Permalink

Please sign in to leave a comment.