It is currently 22 Jun 2017, 15:14

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

CasparCG Server, Client and development

Moderators: Macey, Jonas Hummelstrand, didikunz

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

Postby Sentropy » 18 May 2017, 14:52

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....?
Posts: 13
Joined: 16 Jun 2012, 12:39

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

Postby didikunz » 18 May 2017, 15:22

AMCP commands are the prefered way to send data to templates, at least in Flash. In HTML it depends on the design of the template (but I am still not fit at HTML templates, so I can not help you further).
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland
Problems? Guide to posting Bug reports & Feature requests
User avatar
Posts: 3477
Joined: 10 May 2010, 09:08
Location: Aarau, Switzerland

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

Postby mcdikki » 18 May 2017, 15:50

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
mcdikki - Wir teilen Begeisterung
User avatar
Posts: 1059
Joined: 11 Dec 2012, 15:48
Location: Germany

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

Postby vimlesh1975 » 19 May 2017, 13:57

We make a html template and define javascript function to update the variables(innerHTML) like below.
Code: Select all
function test1(str)
<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')
User avatar
Posts: 602
Joined: 29 Aug 2011, 11:42
Location: Doordarshan, Mumbai, India

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

Postby Sentropy » 23 May 2017, 19:51

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

..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?
Posts: 13
Joined: 16 Jun 2012, 12:39

Return to Tech and Development

Who is online

Users browsing this forum: Baidu [Spider] and 6 guests