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
res.end( | |
'<html>'+ | |
'<head>'+ | |
'<script type="text/javascript" src="/nowjs/now.js"></script>'+ | |
'<script type="text/javascript">'+ | |
'now.ready(function() {'+ | |
' alert("Hi, this is a now.js test.");'+ | |
' var files = {};'+ | |
' now.startFileReceival = function(id, fileName, bytesExpected, cb) {'+ |
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
var button = $('<button type="button" id="playFriendFile' + index + '" value="[play]">[play]</button>')[0]; | |
var row = $('<li>' + files[index].name + '</li>')[0]; | |
$(row).append(button); |
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
var util = require('util'), | |
fs = require('fs'); | |
module.exports = function(server, everyone) { | |
server.get('/streamFriendFile', function(req, res) { | |
util.debug('CLIENT REQUESTED STREAM FRIEND FILE'); | |
util.debug('request headers: ' + util.inspect(req.headers)); | |
util.debug('request params: ' + util.inspect(req.params)); | |
//set headers |
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
var util = require('util'), | |
fs = require('fs'); | |
module.exports = function(server, everyone) { | |
server.get('/streamFriendFile', function(req, res) { | |
util.debug('CLIENT REQUESTED STREAM FRIEND FILE'); | |
util.debug('request headers: ' + util.inspect(req.headers)); | |
util.debug('request params: ' + util.inspect(req.params)); | |
//set headers |
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
//button has been clicked, create new audio player and play | |
var audioElement = $('<audio>', { | |
id : 'audioPlayer' + index, | |
src : '/streamFriendFile', | |
width : '0', | |
height : '0', | |
autoplay : 'autoplay', | |
loop : 'loop', | |
preload : 'auto' | |
})[0]; |
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
var util = require('util'), | |
fs = require('fs'); | |
module.exports = function(server, everyone) { | |
server.get('/streamFriendFile', function(req, res) { | |
util.debug('Client requested: STREAM FRIEND FILE'); | |
util.debug('Client headers: ' + util.inspect(req.headers)); | |
//set headers | |
res.writeHead(200, { |
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
GET /streamFriendFile HTTP/1.1 | |
Host: localhost:3000 | |
Connection: keep-alive | |
Referer: http://localhost:3000/ | |
Accept: */* |
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
//create audio player | |
var audioPlayerElement = $('<div></div>', {id : 'audioPlayerElement'}).appendTo('body')[0]; | |
var jPlayerOptions = { | |
ready : function() { //executed when jplayer is ready for use | |
audioPlayer = $(this); | |
console.log('audio player is ready: %o', audioPlayer); | |
//bind to events | |
audioPlayer.bind($.jPlayer.event.error, function(event) { | |
console.log('jplayer error: %o', event); |
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
//create audio player | |
var audioPlayerElement = $('<div></div>', {id : 'audioPlayerElement'}).appendTo('body')[0]; | |
var jPlayerOptions = { | |
ready : function() { //executed when jplayer is ready for use | |
audioPlayer = $(this); | |
console.log('audio player is ready: %o', audioPlayer); | |
//bind to events | |
audioPlayer.bind($.jPlayer.event.error, function(event) { | |
console.log('jplayer error: %o', event); |
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
part | |
.on('data', function(chunk) { | |
form.pause(); | |
if (friendClient.writeStream.write(chunk)) { | |
form.resume(); | |
} | |
else { | |
friendClient.writeStream.once('drain', function() { | |
form.resume(); | |
}); |