Skip to content

Commit 26aa367

Browse files
author
Owen Barnes
committed
0.3 RC2 release
1 parent ef297a9 commit 26aa367

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+246
-192
lines changed

HISTORY.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
0.3 RC2 / 2012-05-04
2+
====================
3+
4+
* New: Multiple Websocket Transports now fully supported. Switch between Socket.IO (bundled by default) and [SockJS](https://github.com/socketstream/ss-sockjs) (first alpha release) without changing any of your application code
5+
* New: Socket.IO client library can now be configured (see updated example in README)
6+
* Live Reload: Working on fixing issues whilst renaming files in VIM (see #227, thanks madscoaducom), fixed issue saving CSS + normal files together
7+
* Errors in formatting templates (e.g. bad `.jade`) now caught properly
8+
* Any missing sessions are now automatically recreated (useful when developing without using Redis)
9+
* New project example code now uses [Nib](http://visionmedia.github.com/nib) instead of custom Stylus helpers
10+
* Minor refactoring
11+
* Updated README with video link
12+
13+
Note: SocketStream 0.3.0 will be officially launched later in May, along with example apps, screencasts, more documentation and improvements to [www.socketstream.org](http://www.socketstream.org). Read announcement [here](https://groups.google.com/forum/?fromgroups#!topic/socketstream/Y6OIOrJRX7w).
14+
15+
116
0.3 RC1 / 2012-04-22
217
====================
318

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ build:
66
rm -fr lib; node_modules/coffee-script/bin/coffee --bare -o lib -c src; cp src/*.js lib; cp src/utils/*.js lib/utils; cp src/websocket/transports/socketio/*.js lib/websocket/transports/socketio; mkdir lib/client/system/libs; cp -R src/client/system/libs/*.js lib/client/system/libs/; cp -R src/client/system/modules/*.js lib/client/system/modules/;
77

88
# Ignore files and directories prepended with 'testdata_'
9+
TEST_FILES=`find test/* | grep -v '^test/testdata_*'`
910
test:
10-
TEST_FILES=`find test/* | grep -v '^test/testdata_*'`
1111
./node_modules/.bin/mocha --require should --require coffee-script $(TEST_FILES)
1212

1313
.PHONY: test

README.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# SocketStream
44

5-
Latest release: 0.3.0 RC1 ([view changelog](https://github.com/socketstream/socketstream/blob/master/HISTORY.md))
5+
Latest release: 0.3.0 RC2 ([view changelog](https://github.com/socketstream/socketstream/blob/master/HISTORY.md))
6+
67
[![build status](https://secure.travis-ci.org/socketstream/socketstream.png)](http://travis-ci.org/socketstream/socketstream)
78

89
Twitter: [@socketstream](http://twitter.com/#!/socketstream)
@@ -11,6 +12,8 @@ IRC channel: [#socketstream](http://webchat.freenode.net/?channels=socketstream)
1112

1213
Take a tour of all the new features at http://www.socketstream.org/tour
1314

15+
**NEW** [Watch the introductory presentation](http://2011.krtconf.com/videos/owen_barnes) I gave at [KrtConf](http://krtconf.com) last November. Although the first half refers to the previous version (SocketStream 0.2), all the upcoming features I speak about (mid-way through) are now available in SocketStream 0.3.
16+
1417

1518
### Introduction
1619

@@ -24,6 +27,8 @@ Whilst we have chosen not to support models or reactive templating in the core,
2427

2528
SocketStream apps can easily be deployed to [Nodejitsu](http://nodejitsu.com), [EC2 servers](http://aws.amazon.com/ec2) or any other hosting platform supporting websockets (sadly that excludes [Heroku](http://www.heroku.com) for the moment).
2629

30+
While it is still early days, our end goal is to ensure SocketStream can be used to power large-scale 'serious' web apps where scalability, flexibility and high availability are key.
31+
2732

2833
#### Quick Facts
2934

@@ -46,7 +51,7 @@ SocketStream 0.3.0 will be officially launched in May, along with example apps,
4651
#### Client Side
4752

4853
* Works great with Chrome, Safari, Firefox 6 (and above) using native websockets
49-
* Compatible with older versions of Firefox and IE thanks to configurable fallback transports provided by Socket.IO
54+
* Compatible with older versions of Firefox and IE thanks to configurable fallback transports
5055
* Use `require()` and `exports` in your client-side code as you would on the server
5156
* Define multiple single-page clients by choosing the CSS, JS and client-side templates you wish to serve
5257
* Integrated asset manager - automatically packages and [minifies](https://github.com/mishoo/UglifyJS) all client-side assets
@@ -62,7 +67,8 @@ SocketStream 0.3.0 will be officially launched in May, along with example apps,
6267

6368
#### Server Side
6469

65-
* True bi-directional communication using websockets (or [Socket.IO 0.9](http://socket.io) fallbacks). No more slow, messy AJAX!
70+
* True bi-directional communication using websockets (or websocket fallbacks). No more slow, messy AJAX!
71+
* Modular Websocket Transports - switch between [Socket.IO](http://socket.io) (bundled by default) or [SockJS](https://github.com/socketstream/ss-sockjs) without changing your app code
6672
* Easily share code between the client and server. Ideal for business logic and model validation (see Questions below)
6773
* Request Middleware - enabling session access, authentication, logging, distributed requests and more
6874
* Effortless, scalable, pub/sub baked right in - including Private Channels
@@ -73,6 +79,7 @@ SocketStream 0.3.0 will be officially launched in May, along with example apps,
7379

7480
#### Optional Modules (officially maintained and supported)
7581

82+
* **[ss-sockjs](https://github.com/socketstream/ss-sockjs)** Use [SockJS](https://github.com/sockjs/sockjs-client) as the websocket transport instead of Socket.IO
7683
* **[ss-console](https://github.com/socketstream/ss-console)** Connect to a live server and call RPC actions or publish events over the REPL / terminal
7784
* Code Formatters: **[ss-coffee](https://github.com/socketstream/ss-coffee)** (CoffeeScript), **[ss-jade](https://github.com/socketstream/ss-jade)** Jade (for HTML), **[ss-stylus](https://github.com/socketstream/ss-stylus)** Stylus (for CSS), **[ss-less](https://github.com/socketstream/ss-less)** Less (for CSS)
7885
* Client-side Template Engines: **[ss-hogan](https://github.com/socketstream/ss-hogan)** Hogan/Mustache, **[ss-coffeekup](https://github.com/socketstream/ss-coffeekup)** CoffeeKup
@@ -83,7 +90,7 @@ SocketStream 0.3.0 will be officially launched in May, along with example apps,
8390

8491
SocketStream automatically compresses and minifies the static HTML, CSS and client-side code your app needs and sends this through the first time a user visits your site.
8592

86-
From then on all application data is sent and received via the websocket (or Socket.IO fallbacks), instantly established when the client connects and automatically re-established if broken. Normally this will be in [JSON RPC](https://github.com/socketstream/socketstream/blob/master/doc/guide/en/rpc_responder.md) format, but SocketStream 0.3 allows you to use different Request Responders depending upon the task at hand.
93+
From then on all application data is sent and received via the websocket (or websocket fallbacks), instantly established when the client connects and automatically re-established if broken. Normally this will be in [JSON RPC](https://github.com/socketstream/socketstream/blob/master/doc/guide/en/rpc_responder.md) format, but SocketStream 0.3 allows you to use different Request Responders depending upon the task at hand.
8794

8895
All this means no more connection latency, HTTP header overhead, polling, or clunky AJAX. Just true bi-directional, asynchronous, 'streaming' communication between client and server.
8996

@@ -225,18 +232,28 @@ Install the excellent 'nodemon' module with `sudo npm install -g nodemon` then s
225232

226233
##### How can I configure Socket.IO?
227234

228-
Like so:
235+
You may fully configure the Socket.IO server and client libraries like so:
229236

230237
```javascript
231-
ss.ws.transport.use('socketio', {io: function(io){
232-
io.set('log level', 4)
233-
}});
238+
ss.ws.transport.use('socketio', {
239+
client: {
240+
transports: ['websocket', 'htmlfile', 'xhr-polling', 'jsonp-polling']
241+
},
242+
server: function(io){
243+
io.set('log level', 4)
244+
}
245+
});
234246
```
235247

248+
236249
##### Where can I deploy my apps to?
237250

238251
SocketStream works great with [Nodejitsu.com](http://www.nodejitsu.com), as well as custom EC2 / cloud servers. Sadly [Heroku.com](http://www.heroku.com) does not currently support websockets.
239252

253+
Tip: If you're deploying to Nodejitsu add the following dependency to your `package.json`:
254+
255+
"socketstream": "git://github.com/socketstream/socketstream.git#master"
256+
240257

241258
##### Will it run on Windows?
242259

doc/guide/en/authentication.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ And you'll see the following output:
8787

8888
SocketStream integrates well with popular authentication libraries such as [Everyauth](https://github.com/bnoguchi/everyauth).
8989

90-
Here's an example of a full app which authenticates against Twitter's OAuth service:
90+
Tip: Don't be tempted to follow the docs on the Everyauth website too closely - they are mainly geared at multi-page apps and/or specific to Express.
91+
92+
Here's an example of a full app which authenticates against Twitter's OAuth service.
93+
94+
To get started, register your new app at https://dev.twitter.com/apps/new
95+
96+
When testing your app supply `http://127.0.0.1:3000` as the Callback URL. Change this to the real URL when your app goes into production.
97+
9198

9299
```javascript
93100
// app.js

lib/cli/generate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ exports.generate = function(program) {
8585
}
8686
appjs += "\n// Start SocketStream\nss.start(server);";
8787
write('/app.js', appjs);
88-
pacakgejs = "{\n \"name\": \"" + name + "\",\n \"description\": \"An awesome real time application\",\n \"version\": \"0.0.1\",\n \"author\": \"Me <[email protected]>\",\n \"private\": true,\n \"engines\": { \"node\": \">= 0.6.0\" },\n \"dependencies\": {\n \"socketstream\": \"git://github.com/socketstream/socketstream.git#master\",\n";
88+
pacakgejs = "{\n \"name\": \"" + name + "\",\n \"description\": \"An awesome real time application\",\n \"version\": \"0.0.1\",\n \"author\": \"Me <[email protected]>\",\n \"private\": true,\n \"engines\": { \"node\": \">= 0.6.0\" },\n \"dependencies\": {\n";
8989
mods = selectedFormatters.concat(['hogan']);
9090
if (program.repl) mods.push('console');
9191
mods.forEach(function(name, i) {

lib/client/asset.js

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var formatKb, formatters, fs, loadFile, log, minifyJS, minifyJSFile, pathlib, uglifyjs, wrapCode, wrapModule,
1+
var formatKb, formatters, fs, jsp, loadFile, log, minifyJSFile, pathlib, pro, uglifyjs, wrap, wrapCode,
22
__indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
33

44
log = console.log;
@@ -11,10 +11,16 @@ uglifyjs = require('uglify-js');
1111

1212
formatters = require('./formatters');
1313

14-
exports.init = function(root, options) {
14+
wrap = require('./wrap');
15+
16+
jsp = uglifyjs.parser;
17+
18+
pro = uglifyjs.uglify;
19+
20+
module.exports = function(ss, options) {
1521
return {
1622
js: function(path, opts, cb) {
17-
return loadFile(root, options.dirs.code, path, 'js', opts, function(output) {
23+
return loadFile(ss.root, options.dirs.code, path, 'js', opts, function(output) {
1824
output = wrapCode(output, path, opts.pathPrefix);
1925
if (opts.compress && !path.indexOf('.min') >= 0) {
2026
output = minifyJSFile(output, path);
@@ -23,24 +29,20 @@ exports.init = function(root, options) {
2329
});
2430
},
2531
worker: function(path, opts, cb) {
26-
return loadFile(root, options.dirs.workers, path, 'js', opts, function(output) {
32+
return loadFile(ss.root, options.dirs.workers, path, 'js', opts, function(output) {
2733
if (opts.compress) output = minifyJSFile(output, path);
2834
return cb(output);
2935
});
3036
},
3137
css: function(path, opts, cb) {
32-
return loadFile(root, options.dirs.css, path, 'css', opts, cb);
38+
return loadFile(ss.root, options.dirs.css, path, 'css', opts, cb);
3339
},
3440
html: function(path, opts, cb) {
35-
return loadFile(root, options.dirs.views, path, 'html', opts, cb);
41+
return loadFile(ss.root, options.dirs.views, path, 'html', opts, cb);
3642
}
3743
};
3844
};
3945

40-
exports.wrapModule = wrapModule = function(modPath, code) {
41-
return "require.define(\"" + modPath + "\", function (require, module, exports, __dirname, __filename){\n" + code + "\n});";
42-
};
43-
4446
loadFile = function(root, dir, fileName, type, options, cb) {
4547
var extension, formatter, path;
4648
dir = pathlib.join(root, dir);
@@ -65,20 +67,13 @@ formatKb = function(size) {
6567
};
6668

6769
minifyJSFile = function(originalCode, fileName) {
68-
var minifiedCode;
69-
minifiedCode = minifyJS(originalCode);
70-
log((" Minified " + fileName + " from " + (formatKb(originalCode.length)) + " to " + (formatKb(minifiedCode.length))).grey);
71-
return minifiedCode;
72-
};
73-
74-
minifyJS = function(originalCode) {
75-
var ast, jsp, pro;
76-
jsp = uglifyjs.parser;
77-
pro = uglifyjs.uglify;
70+
var ast, minifiedCode;
7871
ast = jsp.parse(originalCode);
7972
ast = pro.ast_mangle(ast);
8073
ast = pro.ast_squeeze(ast);
81-
return pro.gen_code(ast);
74+
minifiedCode = pro.gen_code(ast);
75+
log((" Minified " + fileName + " from " + (formatKb(originalCode.length)) + " to " + (formatKb(minifiedCode.length))).grey);
76+
return minifiedCode;
8277
};
8378

8479
wrapCode = function(code, path, pathPrefix) {
@@ -87,7 +82,7 @@ wrapCode = function(code, path, pathPrefix) {
8782
if (__indexOf.call(pathAry, 'libs') >= 0) return code;
8883
if (__indexOf.call(pathAry, 'system') >= 0) {
8984
modPath = pathAry[pathAry.length - 1];
90-
return wrapModule(modPath, code);
85+
return wrap.module(modPath, code);
9186
} else {
9287
modPath = pathAry.slice(1).join('/');
9388
if (pathPrefix) {
@@ -98,6 +93,6 @@ wrapCode = function(code, path, pathPrefix) {
9893
}
9994
modPath = path.substr(pathPrefix.length + 1);
10095
}
101-
return wrapModule('/' + modPath, code);
96+
return wrap.module('/' + modPath, code);
10297
}
10398
};

lib/client/http.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cache = {};
1212

1313
res = http.ServerResponse.prototype;
1414

15-
module.exports = function(root, clients, options) {
15+
module.exports = function(ss, clients, options) {
1616
res.serveClient = function(name) {
1717
var client, fileName, self, sendHTML;
1818
self = this;
@@ -29,12 +29,12 @@ module.exports = function(root, clients, options) {
2929
}
3030
if (client.pack) {
3131
if (!cache[name]) {
32-
fileName = pathlib.join(root, options.dirs.assets, client.name, client.id + '.html');
32+
fileName = pathlib.join(ss.root, options.dirs.assets, client.name, client.id + '.html');
3333
cache[name] = fs.readFileSync(fileName, 'utf8');
3434
}
3535
return sendHTML(cache[name]);
3636
} else {
37-
return view(root, client, options, sendHTML);
37+
return view(ss, client, options, sendHTML);
3838
}
3939
};
4040
return res.serve = res.serveClient;

lib/client/index.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ clients = {};
2828

2929
module.exports = function(ss, router) {
3030
var http;
31-
http = require('./http')(ss.root, clients, options);
31+
http = require('./http')(ss, clients, options);
3232
systemAssets.load();
33-
ss.client = {
34-
send: systemAssets.send
35-
};
3633
return {
3734
formatters: formatters.init(ss.root),
3835
templateEngine: templateEngine.init(ss, options),
@@ -92,18 +89,18 @@ module.exports = function(ss, router) {
9289
load: function(ss) {
9390
var client, name, pack;
9491
formatters.load();
95-
systemAssets.send('code', 'init', "require('/entry'); require('socketstream').connect();");
92+
systemAssets.send('code', 'init', "require('/entry');");
9693
if (packAssets) {
9794
pack = require('./pack');
9895
for (name in clients) {
9996
client = clients[name];
100-
pack(ss.root, client, options);
97+
pack(ss, client, options);
10198
}
10299
} else {
103-
require('./serve/dev')(ss.root, router, options);
104-
if (options.liveReload) require('./live_reload')(ss.root, options, ss);
100+
require('./serve/dev')(ss, router, options);
101+
if (options.liveReload) require('./live_reload')(ss, options);
105102
}
106-
return require('./serve/ondemand')(ss.root, router, options);
103+
return require('./serve/ondemand')(ss, router, options);
107104
}
108105
};
109106
};

lib/client/live_reload.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ consoleMessage = {
2020
reload: 'Client files changed. Reloading browser...'
2121
};
2222

23-
module.exports = function(root, options, ss) {
23+
module.exports = function(ss, options) {
2424
var allPaths, assetsToWatch, detectNewFiles, handleFileChange, watch;
2525
handleFileChange = function(action) {
2626
if ((Date.now() - lastRun[action]) > 1000) {
@@ -37,7 +37,7 @@ module.exports = function(root, options, ss) {
3737
};
3838
options.liveReload.forEach(function(dir) {
3939
var path, result;
40-
path = pathlib.join(root, options.dirs[dir]);
40+
path = pathlib.join(ss.root, options.dirs[dir]);
4141
result = fileUtils.readDirSync(path);
4242
output.files = output.files.concat(result.files);
4343
return output.dirs = output.dirs.concat(result.dirs);
@@ -53,15 +53,9 @@ module.exports = function(root, options, ss) {
5353
var changeAction, extension, watcher;
5454
extension = file.split('.')[file.split('.').length - 1];
5555
changeAction = cssExtensions.indexOf(extension) >= 0 && 'updateCSS' || 'reload';
56-
return watcher = fs.watch(file, function(event, filename) {
56+
return watcher = fs.watch(file, function(event) {
5757
handleFileChange(changeAction);
58-
if (event === "rename") {
59-
watcher.close();
60-
return watch({
61-
files: [file],
62-
dirs: []
63-
});
64-
}
58+
if (event === "rename") return watcher.close();
6559
});
6660
});
6761
};

lib/client/pack.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ magicPath = require('./magic_path');
1616

1717
view = require('./view');
1818

19-
module.exports = function(root, client, options) {
19+
module.exports = function(ss, client, options) {
2020
var asset, clientDir, containerDir, packAssetSet;
21-
asset = require('./asset').init(root, options);
21+
asset = require('./asset')(ss, options);
2222
client.pack = true;
23-
containerDir = pathlib.join(root, options.dirs.assets);
23+
containerDir = pathlib.join(ss.root, options.dirs.assets);
2424
clientDir = pathlib.join(containerDir, client.name);
2525
packAssetSet = function(assetType, paths, dir, postProcess) {
2626
var filePaths, prefix, processFiles, writeFile;
2727
writeFile = function(fileContents) {
2828
var fileName;
2929
fileName = clientDir + '/' + client.id + '.' + assetType;
3030
fs.writeFileSync(fileName, postProcess(fileContents));
31-
return log('✓'.green, 'Packed ' + filePaths.length + ' files into ' + fileName.substr(root.length));
31+
return log('✓'.green, 'Packed ' + filePaths.length + ' files into ' + fileName.substr(ss.root.length));
3232
};
3333
processFiles = function(fileContents, i) {
3434
var file, path, _ref;
@@ -49,7 +49,7 @@ module.exports = function(root, client, options) {
4949
};
5050
if (paths && paths.length > 0) {
5151
filePaths = [];
52-
prefix = pathlib.join(root, dir);
52+
prefix = pathlib.join(ss.root, dir);
5353
paths.forEach(function(path) {
5454
return magicPath.files(prefix, path).forEach(function(file) {
5555
return filePaths.push({
@@ -81,11 +81,11 @@ module.exports = function(root, client, options) {
8181
compress: true
8282
}) + files.join(';') + ';' + system.serve.initCode();
8383
});
84-
return view(root, client, options, function(html) {
84+
return view(ss, client, options, function(html) {
8585
var fileName;
8686
fileName = pathlib.join(clientDir, client.id + '.html');
8787
fs.writeFileSync(fileName, html);
88-
return log('✓'.green, 'Created and cached HTML file ' + fileName.substr(root.length));
88+
return log('✓'.green, 'Created and cached HTML file ' + fileName.substr(ss.root.length));
8989
});
9090
};
9191

0 commit comments

Comments
 (0)