Update HTML template from C#(.NET) client?

#1
Hi,
long time didn't play with CasparCG, just want to try HTML producer, but I cant understand how I update
data from my C#(.NET) application? I create HTML template and I can see it in Caspar Client, so do I need to make
some kind of web server inside template to receive data over some port or does my application need to change HTML files ( template )? What do I send from application? Do I need to connect to Caspar Server and then send AMCP command to Caspar server ( like..., for example:

Code: Select all

CG 1-20 ADD 1 "TEST" 1 "<templateData><componentData........ etc"
Or there is another better way....?

Re: Update HTML template from C#(.NET) client?

#3
The way to update your template depends on the template, the kind of data and your control workflow.

If you have frequent updates (like automatically generated statistics etc), it's a good idea to use something like websockets or so for the update.
If you haven't much updates to the template or want to control them manually, I would go with the amcp commands. Thats somehow the normal way as the whole template system is base on it and it is a good idea to use it in order stay compliant. This also allows you to use other clients for ccg and your template.
But don't start opening own tcp/udp connections from inside a template. This is a bad idea. It has some serious security impacts and is somehow hard to develop and debug. The implementation of the HTML producer may also just drop the needed functionality in the future etc.
If you come to a situation where you need to handle tcp/udp traffic, use a middle ware that connects to the template via amcp or websockets.

Hope this helps for your decision
cheers
mcdikki
sublan.tv - Wir teilen Begeisterung

Re: Update HTML template from C#(.NET) client?

#4
We make a html template and define javascript function to update the variables(innerHTML) like below.

Code: Select all

<script>
function test1(str)
{document.getElementById("demo").innerHTML=str;}
</script>
<div id="demo" style=" font-size :40; color :Red ;">Original Text</div>
Then play a html template by command

Code: Select all

play 1-91 [HTML] "file:///C:/casparcg/mydata/html/test.html"
Then Update the value by command. We call the function test1 defined in html file and pass new value.

Code: Select all

call 1-91 test1('Updated Text')

Re: Update HTML template from C#(.NET) client?

#5
Thank you Vimlesh ( and others ) for answer. In the mean time, I already found the way to call JS function
( and update template with jquery ). So last question is, I call my function like this ( for update ):

Code: Select all

CG 1-10 INVOKE 1 "myFunction ('XML data..')"
I Encode64 XML before sending ( from client ), so I don't have problem with funny char...( is this ok?).
You use CALL 1-10...whats the difference, and what is better?

I load template not with PLAY like you suggest, but with:

Code: Select all

CG 1-10 ADD 1 TEMPLATE 1
..and then just call INVOKE to call my function. Is this the wrong way? Do you suggest that is better use of XML
on JS side or convert it to JSON and then extract data? Is there faster and simpler way?