casparcg-connection
casparcg-connection copied to clipboard
cgInvoke data parsing add or check for " around data string
When passing a string with the cgInvoke command, the string will be ignored by CasparCG unless it is surrounded by a " So this won´t work:
ccgConnection.cgInvoke(1, 19, 1, "mainStrap(true, 'foo', 'bar')")
To parse the data to AMCP one needs to add a " on both sides of the string:
ccgConnection.cgInvoke(1, 19, 1, '"' + "mainStrap(true, 'foo', 'bar')" + '"');
Best solution would be that the modules formats the AMCP command with the " added. Otherwise a string checker should be added, and return an error if string is not correct formatted?
It should be simple to add surrounding ", but that needs to escape the inner ones too.
From my trying this mornings, it seems that for CasparCG to accept it, the inner ones has to be ‘ And the outer ones has to be “
Escaping " and ' is not a simple task I have found. It is definitely possible to use " inside the string, as I often pass in JSON which needs those. But I think it comes down to needing a annoyingly large or weird number of slashes before each one.
As the inner ones has to be ' and the outer ones has to be " then there should be no need for escaping. Just a checker for the inners to be ' and a checker for the outers to be " and adding the outers if not present.
As the inner ones has to be ' and the outer ones has to be " then there should be no need for escaping.
You say that but you can't guarantee that will work for every use case.
An appropriate AMCP command (escaped) looks like this: CALL 1-20 INVOKE "test({\"f0\":\"an example of \\\"my test's\\\" subject\"})"\r\n
Note here how the json "
are escaped, and the inner texts "
have to escape the escape as well
Also note how assuming the inner quotes will always be '
doesn't work in this case simply because that is not valid JSON.
Yeah, I see, you´re right, I was a little quick concluding that. Anyway, I just try to find a way to help the next one with this, as I did spend the most of the morning trying to figure out why it wasn't´t doing as expected. It was the first time I used invoke so I was assuming a lot of things. So maybe we just should add a comment (for the docs) Something like:
/*
** The method string needs to start and end with a "-sign, otherwise CasparCG will ignore the method.
*/