@@ -11,39 +11,153 @@ const grpcClient = require('./grpc_client')
11
11
12
12
var protobuf = require ( "protobufjs" ) ;
13
13
14
-
15
14
wss . on ( 'connection' , ( ws ) => {
16
15
console . log ( "A new client connected" )
16
+
17
17
18
18
ws . on ( 'message' , function incoming ( message ) {
19
19
20
- ws . binaryType = 'arraybuffer'
20
+ // ws.binaryType = 'arraybuffer'
21
21
22
- // console.log("Receved: %s", message)
23
- console . log ( "Message received" )
22
+ console . log ( "Receved: %s" , message )
23
+ // console.log("Message received")
24
24
25
- console . log ( message . byteLength )
25
+ //console.log(message.byteLength)
26
+ /*
27
+ protobuf.load("protobufs/messages/PacientsAndEmotionsInferenceReply.proto", function(err, root) {
28
+ if (err)
29
+ throw err;
30
+
31
+ var reply = root.lookupType("pacientsAndEmotionsInferenceReply.PacientsAndEmotionsInferenceReply");
32
+
33
+ var payload = { nome : ["dsad", "dsa"] }
34
+ var errMsg = reply.verify(payload)
35
+ if (errMsg)
36
+ throw Error(errMsg)
37
+
38
+ var message = reply.create(payload)
39
+ ws.binaryType = 'arraybuffer'
40
+ console.log('2 Message:', message);
41
+ var buf = reply.encode(message).finish()
42
+ console.log("Check: ", typeof(buf))
43
+ var decoded = reply.decode(buf);
44
+ var what =buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length)
45
+ console.log("Check: ", typeof(what))
46
+ ws.send(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length))
47
+ ws.send("test")
48
+ console.log('Test:', decoded);
49
+ console.log("----")
50
+ console.log("----")
51
+ console.log("----")
52
+ console.log("----")
53
+
54
+ })
55
+
56
+ */
57
+ //ws.binaryType = 'arraybuffer'
58
+
59
+
60
+
26
61
27
62
const client = new grpcClient . imageInference . ImageInferenceService (
28
- '5 .tcp.eu.ngrok.io:17400 ' ,
63
+ '7 .tcp.eu.ngrok.io:12401 ' ,
29
64
30
65
grpc . credentials . createInsecure ( )
31
66
) ;
32
-
67
+
68
+ var inferenceResult
69
+ var request
33
70
protobuf . load ( "protobufs/messages/ImageInferenceRequest.proto" , function ( err , root ) {
34
- var request = root . lookupType ( "imageInferenceRequest.ImageInferenceRequest" ) ;
71
+ request = root . lookupType ( "imageInferenceRequest.ImageInferenceRequest" ) ;
72
+
73
+ console . log ( "So it begins..." )
35
74
36
- var decoded = request . decode ( message ) ;
75
+ var decoded = request . decode ( new Uint8Array ( message ) ) ;
37
76
38
- client . Inference ( { image : decoded [ 'Test' ] } , function ( err , response ) {
39
- console . log ( 'Message:' , response . pred ) ;
40
- ws . send ( response . pred )
77
+ client . PacientsAndEmotionsInference ( { image : decoded [ 'image' ] } , function ( err , response ) {
78
+ console . log ( '0 Message:' , response . detections ) ;
79
+ console . log ( 'R Message:' , response ) ;
80
+ console . log ( 'Response in JSON:' , JSON . stringify ( response ) )
81
+ inferenceResult = response . detections
82
+ console . log ( "----" )
83
+ console . log ( response . detections . length )
84
+ if ( response . detections . length > 0 ) {
85
+ console . log ( response . detections [ 0 ] [ 'emotionsDetected' ] [ 'continuous' ] )
86
+ console . log ( response . detections [ 0 ] [ 'emotionsDetected' ] [ 'categorical' ] )
87
+
88
+ /*
89
+ protobuf.load("protobufs/messages/PacientsAndEmotionsInferenceReply.proto", function(err, root) {
90
+ var reply = root.lookupType("pacientsAndEmotionsInferenceReply.PacientsAndEmotionsInferenceReply");
91
+ console.log('1 Message:', inferenceResult);
92
+ var message = reply.create({ detections : [
93
+ {
94
+ uuid: 'test',
95
+ bodyCenter: { x: 894, y: 407 },
96
+ faceRect: { x1: 0, y1: 0, x2: 0, y2: 0 },
97
+ emotionsDetected: {
98
+ categorical: [],
99
+ continuous: {
100
+ "Valence": 0.0,
101
+ "Arousal": 0.0,
102
+ "Dominance": 0.0
103
+ }
104
+ }
105
+ }
106
+ ] })
107
+ console.log('2 Message:', message);
108
+ var buf = reply.encode(message).finish()
109
+ console.log("Check: ", typeof(buf))
110
+ var decoded = reply.decode(buf);
111
+ console.log('Mine:', decoded);
112
+ console.log('Test 0:', decoded.detections[0])
113
+ console.log("----")
114
+ ws.send(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length))
115
+ console.log("----")
116
+ console.log("And now it ends")
117
+ console.log("----")
118
+ })*/
119
+
120
+ protobuf . load ( "protobufs/messages/PacientsAndEmotionsInferenceReply.proto" , function ( err , root ) {
121
+ var reply = root . lookupType ( "pacientsAndEmotionsInferenceReply.PacientsAndEmotionsInferenceReply" ) ;
122
+ console . log ( '1 Message:' , inferenceResult ) ;
123
+ var message = reply . create ( { detections : [
124
+ {
125
+ uuid : 'test' ,
126
+ bodyCenter : { x : 894 , y : 407 } ,
127
+ faceRect : { x1 : 23 , y1 : 0 , x2 : 0 , y2 : 0 } ,
128
+ emotionsDetected : {
129
+ categorical : [ "Oidasdasd" ] ,
130
+ continuous : {
131
+ "Valence" : 2.4 ,
132
+ "Arousal" : 0.0 ,
133
+ "Dominance" : 0.0
134
+ }
135
+ }
136
+ }
137
+ ] } )
138
+ console . log ( '2 Message:' , message ) ;
139
+ var buf = reply . encode ( message ) . finish ( )
140
+ console . log ( "Check: " , typeof ( buf ) )
141
+ var decoded = reply . decode ( buf ) ;
142
+ console . log ( 'Mine:' , decoded ) ;
143
+ console . log ( 'Test 0:' , decoded . detections [ 0 ] )
144
+ console . log ( JSON . stringify ( decoded ) )
145
+ console . log ( "----" )
146
+ ws . send ( JSON . stringify ( response ) )
147
+ console . log ( "----" )
148
+ console . log ( "And now it ends" )
149
+ console . log ( "----" )
150
+ } )
151
+
152
+ }
153
+
41
154
} ) ;
42
155
156
+
43
157
} )
44
158
159
+
45
160
46
- ws . send ( message . buffer )
47
161
} )
48
162
49
163
} )
0 commit comments