Skip to content

Commit 86cdd86

Browse files
committed
Broadcast to all sockets instead of the last one
1 parent 93e46e2 commit 86cdd86

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

instant-markdown-d

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var md = new MarkdownIt({
3737
}
3838
});
3939

40-
function writeMarkdown(input, output) {
40+
function writeMarkdown(input) {
4141
var body = '';
4242
input.on('data', function(data) {
4343
body += data;
@@ -46,7 +46,7 @@ function writeMarkdown(input, output) {
4646
}
4747
});
4848
input.on('end', function() {
49-
output.emit('newContent', md.render(body));
49+
io.sockets.emit('newContent', md.render(body));
5050
});
5151
}
5252

@@ -103,7 +103,7 @@ function httpHandler(req, res) {
103103
break;
104104

105105
case 'PUT':
106-
writeMarkdown(req, socket);
106+
writeMarkdown(req);
107107
res.writeHead(200);
108108
res.end();
109109
break;
@@ -113,9 +113,8 @@ function httpHandler(req, res) {
113113
}
114114

115115
io.sockets.on('connection', function(sock){
116-
socket = sock;
117116
process.stdout.write('connection established!');
118-
writeMarkdown(process.stdin, socket);
117+
writeMarkdown(process.stdin);
119118
process.stdin.resume();
120119
});
121120

0 commit comments

Comments
 (0)