@@ -38,112 +38,137 @@ export class QiSession {
38
38
) {
39
39
this . connected = connected ;
40
40
this . disconnected = disconnected ;
41
+ console . log ( 'REMOVE: isConnected ' , this . isConnected ( ) ) ;
41
42
console . log ( 'DBG Emile qim about to connect w/17' ) ;
42
43
this . _socket = io . connect ( 'nao:nao@' + ipAddress + ':' + port , {
43
44
resource : 'libs/qimessaging/2/socket.io' ,
44
45
'force new connection' : true ,
45
46
} ) ;
47
+ console . log ( 'REMOVE: isConnected ' , this . isConnected ( ) , this . _socket . socket ) ;
46
48
console . log ( 'DBG Emile qim connecting..' ) ;
47
49
this . _dfd = [ ] ;
48
50
this . _sigs = [ ] ;
49
51
this . _idm = 0 ;
50
52
51
- this . _socket . on ( 'reply' , ( data : any ) => {
52
- console . log ( 'DBG Emile qim reply' ) ;
53
-
54
- const idm = data [ 'idm' ] ;
55
- if (
56
- data [ 'result' ] !== undefined &&
57
- data [ 'result' ] [ 'metaobject' ] !== undefined
58
- ) {
59
- const replyObject : replyType = {
60
- __MetaObject : data [ 'result' ] [ 'metaobject' ] ,
61
- } ;
62
-
63
- const pyobj = data [ 'result' ] [ 'pyobject' ] ;
64
- this . _sigs [ pyobj ] = [ ] ;
65
- const methods = replyObject . __MetaObject [ 'methods' ] ;
66
-
67
- for ( const i in methods ) {
68
- const methodName = methods [ i ] [ 'name' ] ;
69
- replyObject [ methodName ] = this . createMetaCall (
70
- pyobj ,
71
- methodName ,
72
- 'data'
73
- ) ;
74
- }
75
-
76
- const signals = replyObject . __MetaObject [ 'signals' ] ;
77
- for ( const i in signals ) {
78
- const signalName = signals [ i ] [ 'name' ] ;
79
- replyObject [ signalName ] = this . createMetaSignal (
80
- pyobj ,
81
- signalName ,
82
- false
83
- ) ;
84
- }
85
-
86
- const properties = replyObject . __MetaObject [ 'properties' ] ;
87
- for ( const i in properties ) {
88
- const propertyName = properties [ i ] [ 'name' ] ;
89
- replyObject [ propertyName ] = this . createMetaSignal (
90
- pyobj ,
91
- propertyName ,
92
- true
93
- ) ;
94
- }
95
-
96
- this . _dfd [ idm ] . resolve ( replyObject ) ;
97
- } else {
98
- if ( this . _dfd [ idm ] . __cbi !== undefined ) {
99
- const cbi = this . _dfd [ idm ] . __cbi ;
100
- this . _sigs [ cbi [ 'obj' ] ] [ cbi [ 'signal' ] ] [ data [ 'result' ] ] = cbi [ 'cb' ] ;
101
- }
102
- this . _dfd [ idm ] . resolve ( data [ 'result' ] ) ;
103
- }
104
- delete this . _dfd [ idm ] ;
105
- } ) ;
53
+ this . _socket . on ( 'reply' , ( data : any ) => { this . onReply ( data ) } ) ;
54
+
55
+ this . _socket . on ( 'error' , ( data : any ) => { this . onError ( data ) } ) ;
56
+
57
+ this . _socket . on ( 'signal' , ( data : any ) => { this . onSignal ( data ) } ) ;
58
+
59
+ this . _socket . on ( 'disconnect' , this . onDisconnect ) ;
60
+
61
+ this . _socket . on ( 'connect' , this . onConnect ) ;
62
+
63
+ this . service = this . createMetaCall ( 'ServiceDirectory' , 'service' , 'data' ) ;
106
64
107
- this . _socket . on ( 'error' , ( data : any ) => {
108
- console . log ( 'DBG Emile qim error' ) ;
109
- if ( data [ 'idm' ] !== undefined ) {
110
- this . _dfd [ data [ 'idm' ] ] . reject ( data [ 'result' ] ) ;
111
- delete this . _dfd [ data [ 'idm' ] ] ;
65
+ console . log ( 'REMOVE: isConnected ' , this . isConnected ( ) , this . _socket . socket ) ;
66
+ console . log ( 'DBG Emile qim done with init' ) ;
67
+ }
68
+
69
+ isConnected ( ) {
70
+ const connected : boolean =
71
+ ( this . _socket !== undefined ) ?
72
+ this . _socket . socket . connected : false ;
73
+ return connected ;
74
+ }
75
+
76
+ onReply ( data : any ) {
77
+ console . log ( 'DBG Emile qim reply' ) ;
78
+
79
+ const idm = data [ 'idm' ] ;
80
+ if (
81
+ data [ 'result' ] !== undefined &&
82
+ data [ 'result' ] [ 'metaobject' ] !== undefined
83
+ ) {
84
+ const replyObject : replyType = {
85
+ __MetaObject : data [ 'result' ] [ 'metaobject' ] ,
86
+ } ;
87
+
88
+ const pyIndex = data [ 'result' ] [ 'pyobject' ] ;
89
+ this . _sigs [ pyIndex ] = [ ] ;
90
+ const methods = replyObject . __MetaObject [ 'methods' ] ;
91
+
92
+ for ( const i in methods ) {
93
+ const methodName = methods [ i ] [ 'name' ] ;
94
+ replyObject [ methodName ] = this . createMetaCall (
95
+ pyIndex ,
96
+ methodName ,
97
+ 'data'
98
+ ) ;
112
99
}
113
- } ) ;
114
100
115
- this . _socket . on ( 'signal' , ( data : any ) => {
116
- console . log ( 'DBG Emile qim signal' ) ;
117
- const result = data [ 'result' ] ;
118
- const callback =
119
- this . _sigs [ result [ 'obj' ] ] [ result [ 'signal' ] ] [ result [ 'link' ] ] ;
120
- if ( callback !== undefined ) {
121
- callback . apply ( this , result [ 'data' ] ) ;
101
+ const signals = replyObject . __MetaObject [ 'signals' ] ;
102
+ for ( const i in signals ) {
103
+ const signalName = signals [ i ] [ 'name' ] ;
104
+ replyObject [ signalName ] = this . createMetaSignal (
105
+ pyIndex ,
106
+ signalName ,
107
+ false
108
+ ) ;
122
109
}
123
- } ) ;
124
110
125
- this . _socket . on ( 'disconnect' , ( data : any ) => {
126
- console . log ( 'DBG Emile qim disconnect' ) ;
127
- for ( const idm in this . _dfd ) {
128
- this . _dfd [ idm ] . reject ( 'Call ' + idm + ' canceled: disconnected' ) ;
129
- delete this . _dfd [ idm ] ;
111
+ const properties = replyObject . __MetaObject [ 'properties' ] ;
112
+ for ( const i in properties ) {
113
+ const propertyName = properties [ i ] [ 'name' ] ;
114
+ replyObject [ propertyName ] = this . createMetaSignal (
115
+ pyIndex ,
116
+ propertyName ,
117
+ true
118
+ ) ;
130
119
}
131
120
132
- if ( this . disconnected ) {
133
- this . disconnected ( ) ;
121
+ this . _dfd [ idm ] . resolve ( replyObject ) ;
122
+ } else {
123
+ if ( this . _dfd [ idm ] . __cbi !== undefined ) {
124
+ const cbi = this . _dfd [ idm ] . __cbi ;
125
+ this . _sigs [ cbi [ 'obj' ] ] [ cbi [ 'signal' ] ] [ data [ 'result' ] ] = cbi [ 'cb' ] ;
134
126
}
135
- } ) ;
127
+ this . _dfd [ idm ] . resolve ( data [ 'result' ] ) ;
128
+ }
129
+ delete this . _dfd [ idm ] ;
130
+ }
136
131
137
- this . service = this . createMetaCall ( 'ServiceDirectory' , 'service' , 'data' ) ;
132
+ onError ( data : any ) {
133
+ console . log ( 'DBG Emile qim error' ) ;
134
+ if ( data [ 'idm' ] !== undefined ) {
135
+ this . _dfd [ data [ 'idm' ] ] . reject ( data [ 'result' ] ) ;
136
+ delete this . _dfd [ data [ 'idm' ] ] ;
137
+ }
138
+ }
138
139
139
- this . _socket . on ( 'connect' , ( ) => {
140
- console . log ( 'DBG Emile qim connect' ) ;
141
- if ( this . connected ) {
142
- this . connected ( this ) ;
143
- }
144
- } ) ;
140
+ onSignal ( data : any ) {
141
+ console . log ( 'DBG Emile qim signal' ) ;
142
+ const result = data [ 'result' ] ;
143
+ const callback =
144
+ this . _sigs [ result [ 'obj' ] ] [ result [ 'signal' ] ] [ result [ 'link' ] ] ;
145
+ if ( callback !== undefined ) {
146
+ callback . apply ( this , result [ 'data' ] ) ;
147
+ }
148
+ }
145
149
146
- console . log ( 'DBG Emile qim done with init' ) ;
150
+ onConnect ( ) {
151
+ console . log ( 'DBG Emile qim connect' ) ;
152
+ if ( this . connected ) {
153
+ this . connected ( this ) ;
154
+ }
155
+ const connected : boolean =
156
+ ( this . _socket !== undefined ) ?
157
+ this . _socket . socket . connected : false ;
158
+ console . log ( 'REMOVE: isConnected in on connect ' , connected ) ;
159
+
160
+ }
161
+
162
+ onDisconnect ( _data : any ) {
163
+ console . log ( 'DBG Emile qim disconnect' ) ;
164
+ for ( const idm in this . _dfd ) {
165
+ this . _dfd [ idm ] . reject ( 'Call ' + idm + ' canceled: disconnected' ) ;
166
+ delete this . _dfd [ idm ] ;
167
+ }
168
+
169
+ if ( this . disconnected ) {
170
+ this . disconnected ( ) ;
171
+ }
147
172
}
148
173
149
174
createMetaCall ( obj : any , member : any , data : any ) {
@@ -154,6 +179,8 @@ export class QiSession {
154
179
this . _dfd [ this . _idm ] = { resolve : resolve , reject : reject } ;
155
180
} ) ;
156
181
if ( serviceArgs [ 0 ] === 'connect' ) {
182
+ this . isConnected = this . _socket . socket . connected ;
183
+ console . log ( 'REMOVE: isConnected in MetaCall ' , this . isConnected ( ) , this . _socket ) ;
157
184
this . _dfd [ this . _idm ] . __cbi = data ;
158
185
}
159
186
this . _socket . emit ( 'call' , {
@@ -197,4 +224,5 @@ export class QiSession {
197
224
198
225
return signalObject ;
199
226
}
227
+
200
228
}
0 commit comments