Skip to content

Commit

Permalink
use 1 single file for the library
Browse files Browse the repository at this point in the history
splitting it in many files and build it is overkill
given its size.
Let's revisit if the file grows too much
  • Loading branch information
jmesnil committed Jan 26, 2010
1 parent ec15759 commit b3d562e
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 113 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,11 @@

The project is hosted on [GitHub](http://github.com/jmesnil/stomp-websocket).

## Build

To build the library, use Apache Ant from the root directory:

$ cd stomp-websocket
$ ant
Buildfile: build.xml

build:
[mkdir] Created dir: /Users/jmesnil/Git/stomp-websocket/dist
[echo] created dist/stomp.js

BUILD SUCCESSFUL
Total time: 0 seconds

The library file will be located in `dist/stomp.js`.
The library file will be located in `src/stomp.js`.
It does not require any dependency (except Web Socket support from the browser!)

## Test

* Build the library
* Open in your web browser the [test page](test/index.html)
* Check all tests pass

Expand Down
20 changes: 0 additions & 20 deletions build.xml

This file was deleted.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<link rel="stylesheet" href="stomp.css" />
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
<script src='../dist/stomp.js'></script>
<script src='../src/stomp.js'></script>
<script src='example.js'></script>
</head>
<body>
Expand Down
59 changes: 0 additions & 59 deletions src/frame.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/intro.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/outro.js

This file was deleted.

76 changes: 76 additions & 0 deletions src/client.js → src/stomp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
// client can implement the eventhandlers:
// * onconnect => to be notified when it is connected to the STOMP server
// * ondisconnect => to be notified when it is disconnected from the STOMP server
// * onreceive => to receive STOMP messages
// * onreceipt => to receive STOMP receipts
// * onerror => to receive STOMP errors
//
// client can also define a debug(str) handler to display debug infos

(function(window) {

var Stomp = {};

// TODO frame function should not be exposed once we can really talk to a Stomp server
Stomp.frame = function(command, headers, body) {
return {
command: command,
headers: headers,
body: body,
toString: function() {
var out = command + '\n';
if (headers) {
for (header in headers) {
if(headers.hasOwnProperty(header)) {
out = out + header + ': ' + headers[header] + '\n';
}
}
}
out = out + '\n';
if (body) {
out = out + body;
}
return out;
}
}
};

trim = function(str) {
return str.replace(/^\s+/g,'').replace(/\s+$/g,'');
}

Stomp.unmarshall = function(data) {
var command, headers, body;
var lines = data.split('\n');
command = lines[0];
headers = {};
var pos;
for (pos = 1; pos < lines.length ; pos++) {
if (lines[pos] === '') {
break;
}
var pair = lines[pos].split(':');
headers[trim(pair[0])] = trim(pair[1]);
}
pos++;
if(lines[pos] === '') {
// no body
} else {
body = "";
for (i = pos; i < lines.length; i++) {
if (i >= pos) {
pos += '\n'
}
body += lines[i];
}
}
return Stomp.frame(command, headers, body);
};

Stomp.marshall = function(command, headers, body) {
return Stomp.frame(command, headers, body).toString() + '\0';
};

Stomp.client = function (url){

var that, ws, login, passcode;
Expand Down Expand Up @@ -92,4 +165,7 @@

return that;
};

window.Stomp = Stomp;

})(window);
2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<link rel="stylesheet" href="qunit.css" media="screen" />
<script src="qunit.js"></script>

<script src="../dist/stomp.js"></script>
<script src="../src/stomp.js"></script>

<script src="unit/websocket.js"></script>
<script src="unit/frame.js"></script>
Expand Down

0 comments on commit b3d562e

Please sign in to comment.