This repository has been archived on 2022-07-06. You can view files and clone it, but cannot push or open issues or pull requests.
websocket-webcam/node_modules/ws/test/WebSocket.integration.js

45 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var assert = require('assert')
, WebSocket = require('../')
, server = require('./testserver');
var port = 20000;
function getArrayBuffer(buf) {
var l = buf.length;
var arrayBuf = new ArrayBuffer(l);
var uint8View = new Uint8Array(arrayBuf);
for (var i = 0; i < l; i++) {
uint8View[i] = buf[i];
}
return uint8View.buffer;
}
function areArraysEqual(x, y) {
if (x.length != y.length) return false;
for (var i = 0, l = x.length; i < l; ++i) {
if (x[i] !== y[i]) return false;
}
return true;
}
describe('WebSocket', function() {
it('communicates successfully with echo service', function(done) {
var ws = new WebSocket('ws://echo.websocket.org/', {protocolVersion: 13, origin: 'http://websocket.org'});
var str = Date.now().toString();
var dataReceived = false;
ws.on('open', function() {
ws.send(str, {mask: true});
});
ws.on('close', function() {
assert.equal(true, dataReceived);
done();
});
ws.on('message', function(data, flags) {
assert.equal(str, data);
ws.terminate();
dataReceived = true;
});
});
});