theturtle32/AS3WebSocket

AIR for mobile problem

Closed this issue · 3 comments

Hi,

Im having a problem trying to stream microphone input using webSockets.
In my my micSampleDataHandler I'm converting the input and sending it through websocket.sendBytes(bytes) method.

While testing in emulator on desktop everything seems to work fine, but once i start testing on Android device websocket.sendBytes(bytes); seems to block the micSampleDataHandler. its looks like it stops the thread.
It does execute, but it takes much longer time. sending1 trace gets executed, but it takes a while to execute sending2 trace.

Do you maybe know what could be the cause of this? Shouldn't this be async?

This is my mic handler:

function micSampleDataHandler(event:SampleDataEvent):void
{

    var bytes:ByteArray = new ByteArray();
    while(event.data.bytesAvailable)
    {
        var sample:Number = event.data.readFloat();
        var integer:int;
        sample = sample * 32768 ;
        if( sample > 32767 ) sample = 32767;
        if( sample < -32768 ) sample = -32768;
        integer = int(sample);
        bytes.writeShort(integer);

    }

    trace("sending1");
    bytes.position = 0;
    websocket.sendBytes(bytes);
    trace("sending2");
}

You might be running into an optimization issue when the library is applying the XOR masking required for client-to-server communications by the WebSocket spec.

Try setting useNullMask to true and see if that helps:

websocket.useNullMask = true;

Be advised, however, that your client will technically no longer be compliant with the WebSocket specification, and certain WebSocket server implementations may notice this and decide to terminate the connection. (Most, however, will ignore this and work just fine.)