Posted Tuesday, March 12, 2013 in Old JamesCMS Posts
JamesCMS uses Fleck, a WebSocket server implementation. There are two uses of WebSockets in JamesCMS, a log watcher and a file previewer. Here's a preview of what the log watcher looks like:
When called the log watcher will call the FileTail class with a specific log to start tracking. FileTail initializes a FileSystemWatcher that tracks file changes. The file is then read and each file change event triggered will cause the file to be read again starting from the last position. This is similar to other log watchers where the tail of the log is tracked so that incomming changes appear immediately. The WebSocket server is managed through the WebSocketFileTail class which uses the FileTail class events to send messages to the client.
Prettify is used to perform highlighting. I wrote a simple prettify highligher to perform entire line highlighting according to the presence of a few key words.
The same file watcher to WebSocket to browser method is used to perform file previews of markdown files. JamesCMS has a SQL to file source control system that allows me to push and pull text files from a directory into the SQL database. So when I'm editing a file it's nice to have a preview of it on the website: