Facility Control

 View Only
  • 1.  Websocket via Javascript?

    Posted 15 days ago

    I am trying to build a panel that has a websocket control to trigger settings change on a Red camera. Does the JavaScript built into the Dashboard system have the ability to do the websocket functions? Here is the code I have but I can't seem to get it to trigger inside of OGscript or the APl tag. Not sure what I am missing? Would there be a way to somehow trigger Python? Is there anyway to do a websocket connection/command?

    const websocketUri = "ws://10.60.230.98:9998"; // Update IP and port as necessary
    
    async function setProjectFrameRateAndSDIFrequency() {
        try {
            console.log(`Connecting to ${websocketUri}...`);
            
            const websocket = new WebSocket(websocketUri);
    
            // Handle connection opening
            websocket.onopen = () => {
                console.log("Connection established.");
                
                // Step 1: Send rcp_config command
                const rcpConfig = {
                    type: "rcp_config",
                    strings_decoded: 0,
                    json_minified: 1,
                    include_cacheable_flags: 0,
                    encoding_type: "legacy",
                    client: {
                        name: "My Awesome Control App", // You can name your app here
                        version: "1.42"
                    }
                };
                console.log(`Sending rcp_config: ${JSON.stringify(rcpConfig)}`);
                websocket.send(JSON.stringify(rcpConfig));
            };
    
            // Handle incoming messages
            websocket.onmessage = async (event) => {
                console.log("Response from server:", event.data);
    
                const parsedResponse = JSON.parse(event.data);
    
                if (parsedResponse.type === "rcp_config_response") {
                    // Step 2: Send rcp_set command to set the project frame rate to 24000
                    const rcpSetFrameRate = {
                        type: "rcp_set",
                        id: "RCP_PARAM_PROJECT_FRAME_RATE",
                        value: 60000 // Set the project frame rate to 24 fps (24000)
                    };
                    console.log(`Sending rcp_set to change project frame rate to 24000: ${JSON.stringify(rcpSetFrameRate)}`);
                    websocket.send(JSON.stringify(rcpSetFrameRate));
                } else if (parsedResponse.id === "RCP_PARAM_PROJECT_FRAME_RATE") {
                    // Step 3: Send rcp_set command to set the SDI frequency to 60000 (60 Hz)
                    const rcpSetSDI = {
                        type: "rcp_set",
                        id: "RCP_PARAM_MONITOR_FREQUENCY_SDI",
                        value: 60000 // Set the frequency to 60 Hz (60000)
                    };
                    console.log(`Sending rcp_set to change SDI frequency to 60000: ${JSON.stringify(rcpSetSDI)}`);
                    websocket.send(JSON.stringify(rcpSetSDI));
                } else if (parsedResponse.id === "RCP_PARAM_MONITOR_FREQUENCY_SDI") {
                    console.log("SDI frequency set successfully.");
                    websocket.close();
                }
            };
    
            // Handle errors
            websocket.onerror = (error) => {
                console.error("WebSocket error:", error);
            };
    
            // Handle connection close
            websocket.onclose = () => {
                console.log("WebSocket connection closed.");
            };
        } catch (error) {
            console.error("An unexpected error occurred:", error);
        }
    }
    
    // Run the WebSocket client
    setProjectFrameRateAndSDIFrequency();


    ------------------------------
    Seth Haberman
    ------------------------------


  • 2.  RE: Websocket via Javascript?

    Posted 12 days ago

    Hi Seth,

    Unfortunately, OgScript does not support WebSockets at the moment.
    There is a way to send and receive TCP IP messages using "rosstalk", but it also does not support adding headers to request to mimic WebSockets. As I understand you are trying to communicate with a WebSocket based Server, it would require certain WebSocket related headers to be added to the request.

    However, if you take a look at "rosstalk" custom panel examples, may be, you can find another way to communicate with the server.



    ------------------------------
    Kashif Mushtaq
    Senior Software Developer
    Ross Video
    Ottawa Canada
    ------------------------------

    Attachment(s)



  • 3.  RE: Websocket via Javascript?

    Posted 12 days ago

    Thank you for the info!

    are you aware of what that function might look like within the Ross talk? Do you imagine that if you could get the headers correct on the TCP command with a string you could do a socket command?

    The last dashboard documentation I looked at, I couldn't find the breakdown of how the TCP messages completely worked or what extras they supported.



    ------------------------------
    Seth Haberman
    Associate Director of Live Broadcast Video
    Gateway Church
    United States
    ------------------------------



  • 4.  RE: Websocket via Javascript?

    Posted 12 days ago

    Hi Seth,

    Please check the "Communication.zip" I attached to my previous message. It has communication examples.



    ------------------------------
    Kashif Mushtaq
    Senior Software Developer
    Ross Video
    Ottawa Canada
    ------------------------------



  • 5.  RE: Websocket via Javascript?

    Posted 9 days ago

    is it possible to import a JavaScript library to achieve the socket connection using the Meta or API tag?

    I've been syncing a lot of time into trying to make this connection.

    I'm not totally sure how the implementation of JavaScript works within this environment. Are there certain sets of functions that work within the OG script tags and then a broader set that works inside the Meta and API tags?



    ------------------------------
    Seth Haberman
    Associate Director of Live Broadcast Video
    Gateway Church
    United States
    ------------------------------



  • 6.  RE: Websocket via Javascript?

    Posted 9 days ago
      |   view attached

    Hi Seth,
    I looked at the available options in Custom Panel Development Guide, one option you can use is http (used to make REST API calls). You can create your own REST API Server as proxy server (using NodeJS) which can make use of WebSockets to send commands to your device. This way you can control and get status feedback etc using REST API. You have to code your own NodeJS server or may use any other programming language to quickly create a REST API Server to fulfil your needs.


    As far as I know, External API is again OgScript. I am not sure, that it can have anything beyond OgScript available commands.

    http
    Used to fetch content from a web server or call restful API.
    Syntax
    ogscript.http(URL, method, requestContentType, dataObject, includeResponse);
    Parameters
    212 ogScript Reference DashBoard CustomPanel Development Guide

    Parameter Type Description
    URL String Yes http URL
    Method String Yes The method for the URL request, one of:
    GET POST HEAD OPTIONS PUT DELETE
    TRACE are legal, subject to protocol
    restrictions.
    Request Content
    Type
    String Yes The content type of the request.
    Data Object Object Yes Data can be a string, byte array, XML, or
    JSON object
    Include Response Boolean Yes True to include response; otherwise false.

    Required

    Returns
    Returns either string data or a JSON object. 



    ------------------------------
    Kashif Mushtaq
    Senior Software Developer
    Ross Video
    Ottawa Canada
    ------------------------------



  • 7.  RE: Websocket via Javascript?

    Posted 8 days ago

    This is very helpful thank you!

    my last lack of understanding is how I would set up a server in terms of usage of tags?

    Would I set up an HTML tag within a custom panel and remotely load the node.JS libraries that would then run on the local custom panel? I've got some programming experience, but I am having a hard time understanding how the touch panel is able to run things on itself and pull in /host various libraries.

    with that web server have to have a UI or could it run in the background.

    Thanks for the help!



    ------------------------------
    Seth Haberman
    Associate Director of Live Broadcast Video
    Gateway Church
    United States
    ------------------------------



  • 8.  RE: Websocket via Javascript?

    Posted 8 days ago

    Hi Seth, 

    The <listener/> tag is the best way to create a persistent connection. It has the function to send and receive messages depending on the configuration. It can be run as a script but best to begin with the Dashboard inbuilt tag button and go from there.

    I've included an example; it shows a listener configured for HTTP. There is a send button on the same panel that will show you how the messages to the listener are configured. This panel doesn't send back via the socket however, I've included another example of a VLC player TCP listener for this. It shows a listener but for TCP strings rather than HTTP but it also has the send via the same connection in the <api/> tag. It is a bit trickier to get working, follow the readmes, but both can demonstrate how a connection can be made and managed.

    Best regards,

    Richard



    ------------------------------
    Richard Crutwell
    Ross Video UK
    ------------------------------

    Attachment(s)

    txt
    HTTPListener.txt   5 KB 1 version
    zip
    vlc-panel.zip   6 KB 1 version


  • 9.  RE: Websocket via Javascript?

    Posted 3 days ago

    Thanks for this code!

    Am I understanding that the VLC listener does Websocket then but gets responses over TCP?



    ------------------------------
    Seth Haberman
    Associate Director of Live Broadcast Video
    Gateway Church
    United States
    ------------------------------



  • 10.  RE: Websocket via Javascript?

    Posted 3 days ago

    Yes, the VLC example is a TCP socket, but the HTTP POST works with this listener tag also in effect creating a websocket.



    ------------------------------
    Richard Crutwell
    Ross Video UK
    ------------------------------