mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
fixed spacing on test and updated build
This commit is contained in:
@@ -7301,7 +7301,7 @@ exports.decode = function(obj) {
|
||||
if ('string' == typeof obj) {
|
||||
return decodeString(obj);
|
||||
}
|
||||
else if (Buffer.isBuffer(obj) ||
|
||||
else if ((global.Buffer && Buffer.isBuffer(obj)) ||
|
||||
(global.ArrayBuffer && obj instanceof ArrayBuffer) ||
|
||||
(global.Blob && obj instanceof Blob)) {
|
||||
return decodeBuffer(obj);
|
||||
|
||||
@@ -53,94 +53,94 @@ describe('connection', function() {
|
||||
});
|
||||
|
||||
if (!global.Blob && !global.ArrayBuffer) {
|
||||
it('should get base64 data as a last resort', function(done) {
|
||||
socket.on('takebin', function(a) {
|
||||
expect(a.base64).to.be(true);
|
||||
var bytes = b64.toByteArray(a.data);
|
||||
var dataString = String.fromCharCode.apply(String, bytes);
|
||||
expect(dataString).to.eql('asdfasdf');
|
||||
done();
|
||||
});
|
||||
socket.emit('getbin');
|
||||
it('should get base64 data as a last resort', function(done) {
|
||||
socket.on('takebin', function(a) {
|
||||
expect(a.base64).to.be(true);
|
||||
var bytes = b64.toByteArray(a.data);
|
||||
var dataString = String.fromCharCode.apply(String, bytes);
|
||||
expect(dataString).to.eql('asdfasdf');
|
||||
done();
|
||||
});
|
||||
socket.emit('getbin');
|
||||
});
|
||||
}
|
||||
|
||||
if (global.ArrayBuffer) {
|
||||
var base64 = require('base64-arraybuffer');
|
||||
var base64 = require('base64-arraybuffer');
|
||||
|
||||
it('should get binary data (as an ArrayBuffer)', function(done){
|
||||
socket.emit('doge');
|
||||
socket.on('doge', function(buffer){
|
||||
expect(buffer instanceof ArrayBuffer).to.be(true);
|
||||
done();
|
||||
});
|
||||
it('should get binary data (as an ArrayBuffer)', function(done){
|
||||
socket.emit('doge');
|
||||
socket.on('doge', function(buffer){
|
||||
expect(buffer instanceof ArrayBuffer).to.be(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send binary data (as an ArrayBuffer)', function(done){
|
||||
socket.on('buffack', function(){
|
||||
done();
|
||||
});
|
||||
var buf = base64.decode("asdfasdf");
|
||||
socket.emit('buffa', buf);
|
||||
it('should send binary data (as an ArrayBuffer)', function(done){
|
||||
socket.on('buffack', function(){
|
||||
done();
|
||||
});
|
||||
var buf = base64.decode("asdfasdf");
|
||||
socket.emit('buffa', buf);
|
||||
});
|
||||
|
||||
it('should send binary data (as an ArrayBuffer) mixed with json', function(done) {
|
||||
socket.on('jsonbuff-ack', function() {
|
||||
done();
|
||||
});
|
||||
var buf = base64.decode("howdy");
|
||||
socket.emit('jsonbuff', {hello: 'lol', message: buf, goodbye: 'gotcha'});
|
||||
it('should send binary data (as an ArrayBuffer) mixed with json', function(done) {
|
||||
socket.on('jsonbuff-ack', function() {
|
||||
done();
|
||||
});
|
||||
var buf = base64.decode("howdy");
|
||||
socket.emit('jsonbuff', {hello: 'lol', message: buf, goodbye: 'gotcha'});
|
||||
});
|
||||
|
||||
it('should send events with ArrayBuffers in the correct order', function(done) {
|
||||
socket.on('abuff2-ack', function() {
|
||||
done();
|
||||
});
|
||||
var buf = base64.decode("abuff1");
|
||||
socket.emit('abuff1', buf);
|
||||
socket.emit('abuff2', 'please arrive second');
|
||||
it('should send events with ArrayBuffers in the correct order', function(done) {
|
||||
socket.on('abuff2-ack', function() {
|
||||
done();
|
||||
});
|
||||
var buf = base64.decode("abuff1");
|
||||
socket.emit('abuff1', buf);
|
||||
socket.emit('abuff2', 'please arrive second');
|
||||
});
|
||||
}
|
||||
|
||||
if (global.Blob && null != getTextBlob('xxx')) {
|
||||
it('should send binary data (as a Blob)', function(done){
|
||||
socket.on('back', function(){
|
||||
done();
|
||||
});
|
||||
var blob = getTextBlob('hello world');
|
||||
socket.emit('blob', blob);
|
||||
});
|
||||
|
||||
it('should send binary data (as a Blob) mixed with json', function(done) {
|
||||
socket.on('jsonblob-ack', function() {
|
||||
done();
|
||||
});
|
||||
var blob = getTextBlob('EEEEEEEEE');
|
||||
socket.emit('jsonblob', {hello: 'lol', message: blob, goodbye: 'gotcha'});
|
||||
});
|
||||
|
||||
it('should send events with Blobs in the correct order', function(done) {
|
||||
socket.on('blob3-ack', function() {
|
||||
done();
|
||||
});
|
||||
var blob = getTextBlob('BLOBBLOB');
|
||||
socket.emit('blob1', blob);
|
||||
socket.emit('blob2', 'second');
|
||||
socket.emit('blob3', blob);
|
||||
});
|
||||
|
||||
it('should clear its packet buffer in case of disconnect', function(done) {
|
||||
var blob = getTextBlob('BLOBBLOB');
|
||||
for (var i=0; i < 10; i++) { // fill the buffer
|
||||
socket.emit('asdf', blob);
|
||||
}
|
||||
expect(socket.io.packetBuffer.length).to.not.be(0);
|
||||
expect(socket.io.encoding).to.be(true);
|
||||
socket.io.disconnect();
|
||||
expect(socket.io.packetBuffer.length).to.be(0);
|
||||
expect(socket.io.encoding).to.be(false);
|
||||
it('should send binary data (as a Blob)', function(done){
|
||||
socket.on('back', function(){
|
||||
done();
|
||||
});
|
||||
var blob = getTextBlob('hello world');
|
||||
socket.emit('blob', blob);
|
||||
});
|
||||
|
||||
it('should send binary data (as a Blob) mixed with json', function(done) {
|
||||
socket.on('jsonblob-ack', function() {
|
||||
done();
|
||||
});
|
||||
var blob = getTextBlob('EEEEEEEEE');
|
||||
socket.emit('jsonblob', {hello: 'lol', message: blob, goodbye: 'gotcha'});
|
||||
});
|
||||
|
||||
it('should send events with Blobs in the correct order', function(done) {
|
||||
socket.on('blob3-ack', function() {
|
||||
done();
|
||||
});
|
||||
var blob = getTextBlob('BLOBBLOB');
|
||||
socket.emit('blob1', blob);
|
||||
socket.emit('blob2', 'second');
|
||||
socket.emit('blob3', blob);
|
||||
});
|
||||
|
||||
it('should clear its packet buffer in case of disconnect', function(done) {
|
||||
var blob = getTextBlob('BLOBBLOB');
|
||||
for (var i=0; i < 10; i++) { // fill the buffer
|
||||
socket.emit('asdf', blob);
|
||||
}
|
||||
expect(socket.io.packetBuffer.length).to.not.be(0);
|
||||
expect(socket.io.encoding).to.be(true);
|
||||
socket.io.disconnect();
|
||||
expect(socket.io.packetBuffer.length).to.be(0);
|
||||
expect(socket.io.encoding).to.be(false);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user