bitfocus / companion-module-casparcg-server

MIT License
1 stars 7 forks source link

Template / CG not able to send JSON #1

Closed themusicnerd closed 4 years ago

themusicnerd commented 5 years ago

Hi there, Sorry I am still very slow at working out how to code things. I noticed that when selecting the Template/CG option, that I cannot send the data as JSON like I can in the CasparCG Client, I have made a number of HTML5 templates that use JSON as the data source, and would love to move over to companion for this function. Let me know if you need any more detail, or if I should put this in another place. Kindest Regards, Adrian

peschuster commented 4 years ago

This should be already possible: If you enter {"hello":1} into the value field in the official Caspar CG client, the server receives {"hello":1}. The same can be entered into the template variables field in Companion: f0="{"hello":1}" and results in the same command at the server as with the official client.

themusicnerd commented 4 years ago

Hi again, Thanks so much for your reply. This did not work for me.

The correct command for JSON formatted data that is sent from the official CasparCG client when "Send as JSON" is selected is: CG 1-100 ADD 1 "LOWERTHIRD/LOWERTHIRD-LEFT" 1 " {\"f0\":\"hello\",\"f1\":\"world\"}"\r\n

The command that is sent from the official CasparCG client when I enter above as suggested is: CG 1-100 ADD 1 "LOWERTHIRD/LOWERTHIRD-LEFT" 1 "<templateData><componentData id=\"f0\"><data id=\"text\" value=\"{&quot;hello&quot;:1}\"/></componentData></templateData>"\r\n

Similarly the command that is sent from companion as per your suggestion is: CG 1-100 ADD 1 LOWERTHIRD\\LOWERTHIRD-LEFT 1 "<templateData><componentData id=\"f0\"><data id=\"text\" value=\"{&quot;hello&quot;:1}\" /></componentData></templateData>"\r\n

The incorrect data does not work as it is encaptulated with : <templateData><componentData id=\"f0\"><data id=\"text\" value=\"{ and }\" /></componentData></templateData> which is all not required.

I need to send the following: {\"f0\":\"hello\"}

themusicnerd commented 4 years ago

I think I may have worked it out - I can send a manual AMCP command....

Yup Confirmed - I can send a manual AMCP command as : CG 1-100 ADD 1 "LOWERTHIRD/LOWERTHIRD-LEFT" 1 " {\"f0\":\"hello\",\"f1\":\"world\"}"\r\n

peschuster commented 4 years ago

Ah, ok. Thanks for the clarrification. I misunderstood your questiona and thought you wanted to send JSON formatted data inside the value field. I think we could add an option to the "CG" commands to switch between xml and json formatted data. I might be able to have a look at this in the next days.

haakonnessjoen commented 4 years ago

Fixed by peschuster, will merge to companion master when I am by a computer.