xref: /unit/test/node/loader/es_modules_websocket/app.mjs (revision 1876:f85b85094541)
1*1876So.canty@f5.comimport http from "http"
2*1876So.canty@f5.comimport websocket from "websocket"
3*1876So.canty@f5.com
4*1876So.canty@f5.comlet server = http.createServer(function() {});
5*1876So.canty@f5.comlet webSocketServer = websocket.server;
6*1876So.canty@f5.com
7*1876So.canty@f5.comserver.listen(7080, function() {});
8*1876So.canty@f5.com
9*1876So.canty@f5.comvar wsServer = new webSocketServer({
10*1876So.canty@f5.com    maxReceivedMessageSize: 0x1000000000,
11*1876So.canty@f5.com    maxReceivedFrameSize: 0x1000000000,
12*1876So.canty@f5.com    fragmentOutgoingMessages: false,
13*1876So.canty@f5.com    fragmentationThreshold: 0x1000000000,
14*1876So.canty@f5.com    httpServer: server,
15*1876So.canty@f5.com});
16*1876So.canty@f5.com
17*1876So.canty@f5.comwsServer.on('request', function(request) {
18*1876So.canty@f5.com    var connection = request.accept(null);
19*1876So.canty@f5.com
20*1876So.canty@f5.com    connection.on('message', function(message) {
21*1876So.canty@f5.com        if (message.type === 'utf8') {
22*1876So.canty@f5.com            connection.send(message.utf8Data);
23*1876So.canty@f5.com        } else if (message.type === 'binary') {
24*1876So.canty@f5.com            connection.send(message.binaryData);
25*1876So.canty@f5.com        }
26*1876So.canty@f5.com
27*1876So.canty@f5.com  });
28*1876So.canty@f5.com
29*1876So.canty@f5.com  connection.on('close', function(r) {});
30*1876So.canty@f5.com});
31