Sending commands to CasparCG Server using websockify

Hello! I’m building a simple web app that can send preset commands to a CasparCG server via WebSocket and a websockify server to bridge the WebSocket/TCP gap. I have it up and running and am able to send text to a TCP echo server on the same machine, but for some reason, the Caspar server doesn’t see the messages. The server sees the open connection but doesn’t receive messages.

[2020-07-05 17:11:31.459] [23300] [info]    ############################################################################
[2020-07-05 17:11:31.459] [23300] [info]    CasparCG Server is distributed by the Swedish Broadcasting Corporation (SVT)
[2020-07-05 17:11:31.459] [23300] [info]    under the GNU General Public License GPLv3 or higher.
[2020-07-05 17:11:31.460] [23300] [info]    Please see LICENSE.TXT for details.
[2020-07-05 17:11:31.460] [23300] [info]    http://www.casparcg.com/
[2020-07-05 17:11:31.460] [23300] [info]    ############################################################################
[2020-07-05 17:11:31.460] [23300] [info]    Starting CasparCG Video and Graphics Playout Server 2.0.7.e9fc25a Stable
[2020-07-05 17:11:31.460] [23300] [info]    on Windows 10 Home 
[2020-07-05 17:11:31.460] [23300] [info]    Intel(R) Core(TM) i7-4770K CPU @ 3.50GHz Physical Threads: 8
[2020-07-05 17:11:31.460] [23300] [info]    Z87X-D3H
[2020-07-05 17:11:31.465] [23300] [info]    Decklink Not found
[2020-07-05 17:11:31.468] [23300] [info]    Bluefish Not found
[2020-07-05 17:11:31.468] [23300] [info]    FreeImage 3.15.4
[2020-07-05 17:11:31.469] [23300] [info]    FFMPEG-avcodec 55.52.102
[2020-07-05 17:11:31.469] [23300] [info]    FFMPEG-avformat 55.33.100
[2020-07-05 17:11:31.469] [23300] [info]    FFMPEG-avfilter 4.2.100
[2020-07-05 17:11:31.469] [23300] [info]    FFMPEG-avutil 52.66.100
[2020-07-05 17:11:31.469] [23300] [info]    FFMPEG-swscale 2.5.102
[2020-07-05 17:11:31.469] [23300] [info]    Flash 32.0.0.387
[2020-07-05 17:11:31.470] [23300] [info]    flash[cg20.fth.pal|0] Initialized.
[2020-07-05 17:11:31.470] [23300] [info]    flash[cg20.fth.pal|0] Invoking info-command: <invoke name="GetInfo" returntype="xml"><arguments></arguments></invoke>
[2020-07-05 17:11:31.593] [9148]  [debug]   flash-player[cg20.fth.pal|1024x576] [command]      <invoke name="OnCommand" returntype="xml"><arguments><string>Command recieved @GetInfo@?@</string></arguments></invoke>
[2020-07-05 17:11:31.662] [9148]  [info]    flash-player[cg20.fth.pal|1024x576] Initialized.
[2020-07-05 17:11:31.663] [9148]  [debug]   flash-player[cg20.fth.pal|1024x576] [command]      <invoke name="OnCommand" returntype="xml"><arguments><string>Command recieved @GetInfo@?@</string></arguments></invoke>
[2020-07-05 17:11:31.741] [23300] [trace]   Template-Host 2.0.4.3803 RC
[2020-07-05 17:11:31.765] [23300] [debug]   Loaded C:\Users\cmdch\OneDrive\Documents\CasparCG Server\Server\Processing.AirSend.x86.dll
[2020-07-05 17:11:31.765] [23300] [debug]   NewTek iVGA available
[2020-07-05 17:11:31.766] [23300] [info]    casparcg.config:
-----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<configuration>
   <paths>
      <media-path>media\</media-path>
      <log-path>log\</log-path>
      <data-path>data\</data-path>
      <template-path>C:\Users\cmdch\Documents\AudienceCGs</template-path>
      <thumbnails-path>thumbnails\</thumbnails-path>
   </paths>
   <channels>
      <channel>
         <video-mode>1080p5994</video-mode>
         <consumers>
            <newtek-ivga/>
            <system-audio/>
         </consumers>
      </channel>
   </channels>
   <controllers>
      <tcp>
         <port>5250</port>
         <protocol>AMCP</protocol>
      </tcp>
   </controllers>
</configuration>
-----------------------------------------
[2020-07-05 17:11:31.766] [23300] [info]    Initialized html module.
[2020-07-05 17:11:31.766] [23300] [info]    Initializing OpenGL Device.
[2020-07-05 17:11:31.835] [23196] [info]    OpenGL 4.6.0 NVIDIA 391.35 NVIDIA Corporation
[2020-07-05 17:11:31.835] [23196] [info]    Successfully initialized OpenGL Device.
[2020-07-05 17:11:31.839] [23300] [info]    Initialized ffmpeg module.
[2020-07-05 17:11:31.841] [23300] [info]    Initialized bluefish module.
[2020-07-05 17:11:31.842] [23300] [info]    Initialized decklink module.
[2020-07-05 17:11:31.842] [23300] [info]    Initialized oal module.
[2020-07-05 17:11:31.842] [23300] [info]    Initialized newtek module.
[2020-07-05 17:11:31.842] [23300] [info]    Initialized ogl module.
[2020-07-05 17:11:31.842] [23300] [info]    Initialized flash module.
[2020-07-05 17:11:31.842] [23300] [info]    Initialized image module.
[2020-07-05 17:11:31.847] [23196] [info]    [shader] Blend-modes are disabled.
[2020-07-05 17:11:31.848] [23300] [info]    video_channel[1|1080p5994] Successfully Initialized.
[2020-07-05 17:11:31.860] [23300] [info]    newtek-ivga[not connected] Successfully Initialized.
[2020-07-05 17:11:31.863] [9148]  [info]    flash-player[cg20.fth.pal|1024x576] Uninitialized.
[2020-07-05 17:11:31.864] [5396]  [info]    flash[cg20.fth.pal|5000] Uninitialized.
[2020-07-05 17:11:31.868] [14924] [info]    output[1] newtek-ivga[not connected] Added.
[2020-07-05 17:11:31.964] [23300] [info]    oal[1|1080p5994] Sucessfully Initialized.
[2020-07-05 17:11:31.980] [14924] [info]    output[1] oal[1|1080p5994] Added.
[2020-07-05 17:11:31.980] [23300] [info]    Initialized channels.
[2020-07-05 17:11:31.981] [23300] [info]    Initialized thumbnail generator.
[2020-07-05 17:11:31.982] [23300] [info]    WinSock2 Initialized.
[2020-07-05 17:11:31.982] [23300] [info]    Listener successfully initialized
[2020-07-05 17:11:31.982] [23300] [info]    Initialized controllers.
[2020-07-05 17:11:31.982] [23300] [info]    Initialized osc.
[2020-07-05 17:11:31.982] [23300] [info]    Started initial media information retrieval.
[2020-07-05 17:11:32.360] [840]   [info]    Initial media information retrieval finished.
[2020-07-05 17:12:19.489] [10744] [info]    Accepted connection from 127.0.0.1 2
[2020-07-05 17:12:39.718] [10744] [info]    Client 127.0.0.1 was disconnected

I’m kind of at a loss here-- WebSocket is set to text and it’s supposed to deliver UTF-8 encoded text. When I open a raw PuTTY connection everything works just fine.

Does anyone have any experience with this?

Here’s a StackOverflow post I made about it with more details.

Make sure you ending each command with a newline (\n). From a quick skim of the code on stackoverflow it looks like you might not be doing that.

I tested it with that condition after I made that post, still no luck.

You are getting JS errors so should go over your code or test using “wscat” or similar tool. Nothing to do with CCG.

Sorry, including the StackOverflow post kind of muddied the problem a little bit. I was getting JS errors trying to implement something I thought might fix it, but am no longer going down that road.

The problem I’m having now is an error in the TCP connection between my websockify server and the CasparCG server. The latest is that I’m running a TCP watch on my system to see the packets sent between the WS server and CasparCG because I thought the packets might be experiencing loss. Every time I run my JS code, it sends a packet to the server. From what I can tell, the CasparCG server is receiving the packets I’m sending, but they’re not showing up in the console. They’re not even throwing up errors like they would if the commands were wrong.

Does that mean the packets are somehow encoded wrong? I’m not sure what Caspar’s behavior would be in that situation.

EDIT: The websockify server is running in node

Imgur
Imgur

It might need to be \r\n actually, I dont quite remember.

Your problem sounds exactly like what I would expect if the line ending is missing, as it buffers data until a line ending then tries to parse that chunk. Because TCP doesnt have true packet separation, it gets left to the protocol to do the splitting.

It should be “\n\n”.

I tried it with both \r\n and \n\n and it’s still not getting a response. I made a video showing the problem

(I realized after I recorded it was sending with forward slashes rather than backslashes. I changed that and tried it again, and it’s still not receiving the commands. I really thought that would be it lol)

I managed to get it working a while ago with these lines:

caspar = new WebSocket("ws://127.0.0.1:7250", ['binary']);

and then:

caspar.send("PLAY 1-"+bgLayer+" \""+bgFile+"\" MIX 50 EaseInOutQuad RIGHT LOOP\r\n");

Interesting, so you sent the data as a binary blob? Just tried that, didn’t work for me either. And the bgLayer and bgFile are your JS variables, I assume. Why did you backslash out the quotemarks there and not the backslashes meant to stay in the string at the end of the message? It seems like that would generate a weird string that might mess with WebSocket.

That was a lazy test to play a background specified in the client. You could just send a "INFO\r\n" command to test

Hmm. I tried to connect to the websockify server with

var sock = new WebSocket('ws://' + casparserver, ['binary']);

then send the info command with

sock.send('info\\r\\n');

but I’m still not getting anything on the Caspar server. Works fine on the TCP echo server though.

Have you tried sniffing with wireshark when you send commands to caspar?

Also, why are you using version 2.0.7? I would switch to 2.3.

I just followed this guide and got it working again with the commands I shared above.
Started the proxy with the command:
node C:\SERVER\ws\websockify.js 127.0.0.1:7250 127.0.0.1:5250

Weird. That was the guide I followed originally and it was working great until I had to have Caspar talk to the server. I updated to 2.3 and the problem is persisting. I have wireshark but to be honest I’m not that familar with it and I’m not really sure what to look for.

This is local traffic on 5260
Imgur

and this is local traffic on 5250
Imgur

I’m gonna set this up on another machine to see if that changes anything.

I can only put 2 links in a post but the traffic was generated with [this tool](Both captured using this tool I built that sends a Caspar info command) that sends a Caspar info command to a specified server

I noticed there are two backslashes in \r\n. it’s supposed to have the actual return characters. You are sending them as a string.

1 Like

AHHHHH THAT’S IT!

Thank you! Headache over. For some reason I was thinking Caspar had to see \r\n in text.

1 Like

This method is only valid for flash? Or should it work the same way for html templates?

Thanks!

It’s the other way around.
Flash always had server connection.
HTML can’t open regular TCP sockets so this is the workaround.

Privacy Policy   Terms of Service