Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser socket.io-stream #14

Closed
maeuca opened this issue Oct 8, 2013 · 5 comments
Closed

Browser socket.io-stream #14

maeuca opened this issue Oct 8, 2013 · 5 comments

Comments

@maeuca
Copy link

maeuca commented Oct 8, 2013

Hello, I'm trying to use socket.io-stream in a browser to upload a file. However, I keep getting this error, in the file change event.

"Uncaught ReferenceError: ss is not defined "

Am I missing something obvious? Please help.

Thanks in advance.

Here is the html source:

<script type="text/javascript" src="/socket.io/socket.io.js"></script> <script type="text/javascript" src="/js/socket.io-stream.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <script> $(function() { $('#file').change(function(e) { var file = e.target.files[0]; var stream = ss.createStream();
            // upload a file to the server.
            ss(socket).emit('file', stream, {size: file.size});
            ss.createBlobReadStream(file).pipe(stream);
        });
    });
    var socket = io.connect('http://lb1:8080');

</script>

@nkzawa
Copy link
Owner

nkzawa commented Oct 8, 2013

Could you give me your code?

@maeuca
Copy link
Author

maeuca commented Oct 8, 2013

There are 2 files attached to this message.

  1. upload.html
  2. ioserver.js

[ upload.html ]

START

 <script type="text/javascript" 

src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/js/socket.io-stream.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
$(function() {
$('#file').change(function(e) {
var file = e.target.files[0];
var stream = ss.createStream();

             // upload a file to the server.
             ss(socket).emit('file', stream, {size: file.size});
             ss.createBlobReadStream(file).pipe(stream);
         });
     });

     var socket = io.connect('http://localhost:8080');

     socket.on('connect', function(){
         console.log('socket ready!');
     });

 </script>

END

[ ioserver.js ]

START
var fs = require('fs');
var path = require('path');
var ss = require('socket.io-stream');

var startIOListener = function() {
var app = require('http').createServer(function (req, res) {
fs.readFile(__dirname + '/public/upload.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
})
, io = require('socket.io').listen(app)
, fs = require('fs')
app.listen(8080);

 io.sockets.on('connection', function (socket) {

     ss(socket).on('profile-image', function(stream, data) {
         var filename = path.basename(data.name);
         stream.pipe(fs.createWriteStream(filename));
     });

 });

}

startIOListener();
END
The error seems to be in upload.html, but I'm kinda stuck on why.

Thanks in advance.
Mark

------ Original Message ------
From: "nkzawa" notifications@github.com
To: "nkzawa/socket.io-stream" socket.io-stream@noreply.github.com
Cc: "maeuca" mark.e.cantrell@gmail.com
Sent: 10/8/2013 12:25:49 PM
Subject: Re: [socket.io-stream] Browser socket.io-stream (#14)

Could you give me your code?


Reply to this email directly or view it on GitHub.

@nkzawa
Copy link
Owner

nkzawa commented Oct 10, 2013

Sorry for the late reply.

Did you expose the file to a public directory like the following?

$ cp node_modules/socket.io-stream/socket.io-stream.js somewhere/public/

See: https://github.com/nkzawa/socket.io-stream#browser

@maeuca
Copy link
Author

maeuca commented Oct 10, 2013

my web server was not configured properly.

working fine now, thanks!

--- Original Message ---

From: "nkzawa" notifications@github.com
Sent: October 10, 2013 11:58 AM
To: "nkzawa/socket.io-stream" socket.io-stream@noreply.github.com
Cc: "maeuca" mark.e.cantrell@gmail.com
Subject: Re: [socket.io-stream] Browser socket.io-stream (#14)

Sorry for the late reply.

Did you expose the file to a public directory like the following?

$ cp node_modules/socket.io-stream/socket.io-stream.js somewhere/public/

See: https://github.com/nkzawa/socket.io-stream#browser


Reply to this email directly or view it on GitHub:
#14 (comment)

@nkzawa nkzawa closed this as completed Oct 10, 2013
@mukeshkanyal
Copy link

it showing browserify:command not found when i'm run this command in terminal browserify index.js -s ss > socket.io-stream.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants