Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adding node socket.io listener to change location of the page remotely.
- Loading branch information
1 parent
769f708
commit 136b407
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Ignore these things # | ||
####################### | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "switchist" | ||
, "version": "0.0.1" | ||
, "private": true | ||
, "dependencies": { | ||
"socket.io": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Switcher: Remote</title> | ||
<meta name="description" content=""> | ||
<meta name="author" content=""> | ||
|
||
<!-- Le HTML5 shim, for IE6-8 support of HTML elements --> | ||
<!--[if lt IE 9]> | ||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | ||
<![endif]--> | ||
|
||
<!-- Le styles --> | ||
<link href="./bootstrap/bootstrap.css" rel="stylesheet"> | ||
<link rel="stylesheet" href="stylesheets/switcher.css" type="text/css" media="screen" title="no title" charset="utf-8"> | ||
|
||
<script src="javascripts/lib/head.min.js" type="text/javascript" charset="utf-8"></script> | ||
<script src="http://localhost:3030/socket.io/socket.io.js" type="text/javascript" charset="utf-8"></script> | ||
|
||
<style type="text/css"> | ||
body { | ||
padding-top: 60px; | ||
} | ||
</style> | ||
|
||
<!-- Le fav and touch icons --> | ||
<link rel="shortcut icon" href="images/favicon.ico"> | ||
<link rel="apple-touch-icon" href="images/apple-touch-icon.png"> | ||
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png"> | ||
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png"> | ||
</head> | ||
|
||
<body> | ||
|
||
<div class="topbar"> | ||
<div class="fill"> | ||
<div class="container"> | ||
<a class="brand" href="#">Switcher: Remote: <span id='site_title'></span></a> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="container"> | ||
|
||
<!-- Example row of columns --> | ||
<div class="row"> | ||
<div class="span-one-third"> | ||
<h2>Instructions</h2> | ||
<p>Enter the URL to change the display to.</p> | ||
</div> | ||
<div class="span-two-thirds"> | ||
<form id='change_form' action="remote_submit" method="get" accept-charset="utf-8"> | ||
<fieldset> | ||
<div class="clearfix"> | ||
<label for="url_change">URL</label> | ||
<div class="input"> | ||
<input class="xlarge" id="url_change" name="url_change" size="100" type="text"> | ||
<input type="submit" value="Go →"> | ||
</div> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
<footer> | ||
|
||
</footer> | ||
|
||
</div> | ||
<!-- /container --> | ||
<script type="text/javascript" charset="utf-8"> | ||
head.ready('application', function(){ | ||
var socket = io.connect('http://localhost:3030'); | ||
|
||
$('#change_form').submit(function(e){ | ||
e.preventDefault(); | ||
socket.emit('change location', {url: $('#url_change').val()}) | ||
}); | ||
|
||
}); | ||
|
||
head.js( | ||
{jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'}, | ||
{application: 'javascripts/src/application.js'} | ||
); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var app = require('http').createServer(handler) | ||
, io = require('socket.io').listen(app) | ||
, fs = require('fs') | ||
|
||
app.listen(3030); | ||
|
||
function handler (req, res) { | ||
fs.readFile(__dirname + '/index.html', | ||
function (err, data) { | ||
if (err) { | ||
res.writeHead(500); | ||
return res.end('Error loading index.html'); | ||
} | ||
|
||
res.writeHead(200); | ||
res.end(data); | ||
}); | ||
} | ||
|
||
io.sockets.on('connection', function (socket) { | ||
socket.on('change location', function (data) { | ||
console.log('got changelocation'); | ||
socket.emit('window location', data); | ||
}); | ||
}); |