@@ -70,10 +70,35 @@ module ClientWebSocket {
7070 /**
7171 * A class that can be used to instantiate a WebSocket instance.
7272 */
73- class SocketClass extends API :: Node {
73+ deprecated class SocketClass extends DataFlow :: SourceNode {
7474 LibraryName library ; // the name of the WebSocket library. Can be one of the libraries defined in `LibraryNames`.
7575
7676 SocketClass ( ) {
77+ this = DataFlow:: globalVarRef ( "WebSocket" ) and library = websocket ( )
78+ or
79+ this = DataFlow:: moduleImport ( "ws" ) and library = ws ( )
80+ or
81+ // the sockjs-client library:https://www.npmjs.com/package/sockjs-client
82+ library = sockjs ( ) and
83+ (
84+ this = DataFlow:: moduleImport ( "sockjs-client" ) or
85+ this = DataFlow:: globalVarRef ( "SockJS" )
86+ )
87+ }
88+
89+ /**
90+ * Gets the WebSocket library name.
91+ */
92+ LibraryName getLibrary ( ) { result = library }
93+ }
94+
95+ /**
96+ * A class that can be used to instantiate a WebSocket instance.
97+ */
98+ class WebSocketClass extends API:: Node {
99+ LibraryName library ; // the name of the WebSocket library. Can be one of the libraries defined in `LibraryNames`.
100+
101+ WebSocketClass ( ) {
77102 this = any ( WebSocketEntryPoint e ) .getANode ( ) and library = websocket ( )
78103 or
79104 this = API:: moduleImport ( "ws" ) and library = ws ( )
@@ -96,7 +121,7 @@ module ClientWebSocket {
96121 * A client WebSocket instance.
97122 */
98123 class ClientSocket extends EventEmitter:: Range , API:: NewNode , ClientRequest:: Range {
99- SocketClass socketClass ;
124+ WebSocketClass socketClass ;
100125
101126 ClientSocket ( ) { this = socketClass .getAnInvocation ( ) }
102127
@@ -212,7 +237,18 @@ module ServerWebSocket {
212237 /**
213238 * Gets a server created by a library named `library`.
214239 */
215- API:: InvokeNode getAServer ( LibraryName library ) {
240+ deprecated DataFlow:: SourceNode getAServer ( LibraryName library ) {
241+ library = ws ( ) and
242+ result = DataFlow:: moduleImport ( "ws" ) .getAConstructorInvocation ( "Server" )
243+ or
244+ library = sockjs ( ) and
245+ result = DataFlow:: moduleImport ( "sockjs" ) .getAMemberCall ( "createServer" )
246+ }
247+
248+ /**
249+ * Gets a server created by a library named `library`.
250+ */
251+ API:: InvokeNode getAServerInvocation ( LibraryName library ) {
216252 library = ws ( ) and
217253 result = API:: moduleImport ( "ws" ) .getMember ( "Server" ) .getAnInvocation ( )
218254 or
@@ -224,7 +260,7 @@ module ServerWebSocket {
224260 * Gets a `socket.on("connection", (msg, req) => {})` call.
225261 */
226262 private DataFlow:: CallNode getAConnectionCall ( LibraryName library ) {
227- result = getAServer ( library ) .getReturn ( ) .getMember ( EventEmitter:: on ( ) ) .getACall ( ) and
263+ result = getAServerInvocation ( library ) .getReturn ( ) .getMember ( EventEmitter:: on ( ) ) .getACall ( ) and
228264 result .getArgument ( 0 ) .mayHaveStringValue ( "connection" )
229265 }
230266
0 commit comments