1
1
var sys = require ( 'sys' ) ;
2
2
3
3
function Frame ( ) {
4
- this . connected = false ;
5
- this . sock = '' ;
6
- this . command = '' ;
7
- this . headers = '' ;
8
- this . body = '' ;
9
-
10
- this . stomp_connect = function ( sock ) {
11
- this . sock = sock ;
12
- this . connected = true ;
4
+ var connected = false ,
5
+ sock = '' ,
6
+ command = '' ,
7
+ headers = '' ,
8
+ body = '' ;
9
+
10
+ this . stomp_connect = function ( client ) {
11
+ connected = true ;
12
+ sock = client ;
13
13
var args = Array ( ) ;
14
14
var headers = Array ( ) ;
15
15
@@ -22,21 +22,18 @@ function Frame() {
22
22
} ;
23
23
24
24
this . build_frame = function ( args , want_receipt ) {
25
- this . command = args [ 'command' ] ;
26
- this . headers = args [ 'headers' ] ;
27
- this . body = args [ 'body' ] ;
25
+ command = args [ 'command' ] ;
26
+ headers = args [ 'headers' ] ;
27
+ body = args [ 'body' ] ;
28
28
if ( want_receipt ) {
29
29
receipt_stamp = Math . floor ( Math . random ( ) * 10000000 + 1 ) ;
30
- this . headers [ 'receipt' ] = "-"
30
+ this . headers [ 'receipt' ] = "-"
31
31
console . log ( want_receipt ) ;
32
32
}
33
33
return this ;
34
34
} ;
35
35
36
36
this . as_string = function ( ) {
37
- command = this . command ;
38
- headers = this . headers ;
39
- body = this . body ;
40
37
header_strs = Array ( ) ;
41
38
42
39
for ( var header in headers ) {
@@ -49,8 +46,29 @@ function Frame() {
49
46
} ;
50
47
51
48
this . send_frame = function ( frame ) {
52
- this . sock . write ( frame . as_string ( ) ) ;
49
+ console . dir ( sock ) ;
50
+ sock . write ( frame . as_string ( ) ) ;
51
+ } ;
52
+
53
+ this . parse_frame = function ( data ) {
54
+ args = Array ( ) ;
55
+ headers = Array ( ) ;
56
+ headers_str = '' ;
57
+ body = '' ;
58
+
59
+ command = this . parse_command ( data ) ;
60
+ data = data . slice ( command . len + 1 )
61
+ headers_str , body = data . split ( "\n\n" ) ;
62
+ headers = this . parse_headers ( headers_str ) ;
63
+
64
+ args [ 'command' ] = command ;
65
+ args [ 'headers' ] = headers ;
66
+ args [ 'body' ] = body ;
67
+
68
+ this_frame = Frame ( sock ) ;
69
+ this_frame . build_frame ( args ) ;
53
70
} ;
71
+
54
72
} ;
55
73
56
74
module . exports = Frame ;
0 commit comments