rabchev / web-terminal

Web-Terminal is a terminal server that provides remote CLI via standard web browser and HTTP protocol.
MIT License
443 stars 138 forks source link

exec function for client-side javascript #17

Closed rjcorwin closed 9 years ago

rjcorwin commented 9 years ago

AKA Expose an exec function so other web apps can use web-terminal to run commands

Hi there - I'm building an Web App that exposes a form based GUI that runs commands via web-terminal. Much like exec in other languages, here's a client side implementation of exec that utilizes web-terminal.

Example:

exec('ls -l', function(stdout) { console.log(stdout) })

To allow isolating of the web-terminal program and a web app (web app might not want jquery mobile library), I also added the ability to run this exec function from the a parent to a web-terminal iframe. There are some restrictions to this such as needing to be on the same domain, but you can be at different ports which works for my purposes where there is an app running at domain localhost on port 80 while web-terminal is running on localhost:8080.

I also added an example. It could be cleaned up if there is a desire to accept this pull request. screen shot 2015-04-13 at 9 26 47 pm

rabchev commented 9 years ago

Thanks R.J.

rabchev commented 9 years ago

It would be nice if you update the readme file and explain the new feature.

Thanks again.

rjcorwin commented 9 years ago

Hi Boyan. Thank you for accepting the pull request. It could definitely use some documentation, some linting (do you have one you prefer?), and there is a potential performance implication. I think the event listener here needs to be cleaned up on exit. I'll get you a second pull request sometime this week.

On Tuesday, April 14, 2015, Boyan Rabchev notifications@github.com wrote:

It would be nice if you update the readme file and explain the new feature.

Thanks again.

— Reply to this email directly or view it on GitHub https://github.com/rabchev/web-terminal/pull/17#issuecomment-92871995.

rj@rjsteinert.com http://rjsteinert.com http://twitter.com/rjsteinert http://github.com/rjsteinert

rjcorwin commented 9 years ago

To make this cross-domain compatible, this could be refactored to use the postMessage API. https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage