File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
javascript/ql/src/experimental/SockJS Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Provides classes for working with [SockJS](http://sockjs.org).
3+ */
4+
5+ import javascript
6+
7+ /**
8+ * A model of the `SockJS` websocket data handler (https://sockjs.org).
9+ */
10+ module SockJS {
11+ /**
12+ * Access to user-controlled data object received from websocket
13+ * For example:
14+ * ```
15+ * server.on('connection', function(conn) {
16+ * conn.on('data', function(message) {
17+ * ...
18+ * });
19+ * });
20+ * ```
21+ */
22+ class SourceFromSocketJS extends RemoteFlowSource {
23+ SourceFromSocketJS ( ) {
24+ exists (
25+ DataFlow:: CallNode createServer , DataFlow:: CallNode connNode ,
26+ DataFlow:: CallNode dataHandlerNode
27+ |
28+ createServer = appCreation ( ) and
29+ connNode = createServer .getAMethodCall ( "on" ) and
30+ connNode .getArgument ( 0 ) .getStringValue ( ) = "connection" and
31+ dataHandlerNode = connNode .getCallback ( 1 ) .getParameter ( 0 ) .getAMethodCall ( "on" ) and
32+ dataHandlerNode .getArgument ( 0 ) .getStringValue ( ) = "data" and
33+ this = dataHandlerNode .getCallback ( 1 ) .getParameter ( 0 )
34+ )
35+ }
36+
37+ override string getSourceType ( ) { result = "input from SockJS WebSocket" }
38+ }
39+
40+ /**
41+ * Gets a new SockJS server.
42+ */
43+ private DataFlow:: CallNode appCreation ( ) {
44+ result = DataFlow:: moduleImport ( "sockjs" ) .getAMemberCall ( "createServer" )
45+ }
46+ }
Original file line number Diff line number Diff line change 1+ const express = require ( 'express' ) ;
2+ const http = require ( 'http' ) ;
3+ const sockjs = require ( 'sockjs' ) ;
4+
5+ const app = express ( ) ;
6+ const server = http . createServer ( app ) ;
7+ const sockjs_echo = sockjs . createServer ( { } ) ;
8+ sockjs_echo . on ( 'connection' , function ( conn ) {
9+ conn . on ( 'data' , function ( message ) {
10+ var data = JSON . parse ( message ) ;
11+ conn . write ( JSON . stringify ( eval ( data . test ) ) ) ;
12+ } ) ;
13+ } ) ;
14+
15+ sockjs_echo . installHandlers ( server , { prefix :'/echo' } ) ;
16+ server . listen ( 9090 , '127.0.0.1' ) ;
You can’t perform that action at this time.
0 commit comments