Skip to content

Commit

Permalink
Rename 'data' as 'terminal-data'.
Browse files Browse the repository at this point in the history
If you want to use the socket connection for transporting anything other
than terminal data, then the name 'data' is probably too generic. If we
make it more descriptive, then the sources and destinations are clearer.

Use case: I want to have a terminal window editing a file, but also the
full file contents below. And, to transmit those contents, I want to
re-use the socket connection. It would be helpful if the naming of the
terminal data were descriptive.

App.js also now exports the the socket (io).
  • Loading branch information
smblott-github committed Dec 22, 2015
1 parent c8cd50a commit ba27ea0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var buffer = new ScreenBuffer()
// when a client is connected, it is initialized with an empty buffer.
// we patch its buffer to our current state
io.sockets.on('connection', function(sock) {
sock.emit('data', ScreenBuffer.diff(new ScreenBuffer(), buffer))
sock.emit('terminal-data', ScreenBuffer.diff(new ScreenBuffer(), buffer))
})

// when the terminal's screen buffer is changed,
Expand All @@ -84,11 +84,11 @@ term.on('change', function() {

function broadcast() {
timeout = null

var operations = ScreenBuffer.diff(buffer, term.displayBuffer)
if (operations.length === 0) return

io.sockets.emit('data', operations)
io.sockets.emit('terminal-data', operations)
ScreenBuffer.patch(buffer, operations)
}

Expand All @@ -99,3 +99,5 @@ server.listen(Number(process.env.PORT) || 13377, function() {
console.log('ttycast listening on %s port %s', address.address, address.port)
})

// export the socket so that it can be re-used by other apps
module.exports.io = io
2 changes: 1 addition & 1 deletion static/ttycast.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ window.onload = function() {
, buf = new DisplayBuffer(el)

var socket = io.connect()
socket.on('data', function(operations) {
socket.on('terminal-data', function(operations) {
ScreenBuffer.patch(buf, operations)
})

Expand Down

0 comments on commit ba27ea0

Please sign in to comment.