mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 09:35:48 +00:00
be4afdde37
Summary: This PR updates #6851 from srikanthkh, fixing coding conventions and javadoc, and adding a test plan. Added testing functions into the WebSocketExample page of the UIExplorer, including a tiny http server to set a cookie on demand. Instructions included in the UIExplorer app. Closes https://github.com/facebook/react-native/pull/9114 Differential Revision: D4140534 Pulled By: lacker fbshipit-source-id: e020ad0c6d1d3ea09c0c3564c1795b4e1bc4517d
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
* evaluation purposes only.
|
|
*
|
|
* Facebook reserves all rights not expressly granted.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* @flow
|
|
*/
|
|
'use strict';
|
|
|
|
/* eslint-env node */
|
|
|
|
const WebSocket = require('ws');
|
|
|
|
console.log(`\
|
|
Test server for WebSocketExample
|
|
|
|
This will send each incoming message right back to the other side.
|
|
Restart with the '--binary' command line flag to have it respond with an
|
|
ArrayBuffer instead of a string.
|
|
`);
|
|
|
|
const respondWithBinary = process.argv.indexOf('--binary') !== -1;
|
|
const server = new WebSocket.Server({port: 5555});
|
|
server.on('connection', (ws) => {
|
|
ws.on('message', (message) => {
|
|
console.log('Received message:', message);
|
|
console.log('Cookie:', ws.upgradeReq.headers.cookie);
|
|
if (respondWithBinary) {
|
|
message = new Buffer(message);
|
|
}
|
|
ws.send(message);
|
|
});
|
|
|
|
console.log('Incoming connection!');
|
|
ws.send('Why hello there!');
|
|
});
|