Search in sources :

Example 6 with Uint8Array

use of com.google.gwt.typedarrays.shared.Uint8Array in project playn by threerings.

the class HtmlWebSocket method send.

@Override
public void send(ByteBuffer data) {
    int len = data.limit();
    // TODO(haustein) Sending the view directly does not work for some reason.
    // May be a chrome issue...?
    //  Object trick = data;
    // ArrayBufferView ta = ((HasArrayBufferView) trick).getTypedArray();
    // Int8Array view = Int8Array.create(ta.getBuffer(), ta.getByteOffset(), len)
    // ws.send(view);
    ArrayBuffer buf = TypedArrays.createArrayBuffer(len);
    Uint8Array view = TypedArrays.createUint8Array(buf);
    for (int i = 0; i < len; i++) {
        view.set(i, data.get(i));
    }
    ws.send(buf);
}
Also used : ArrayBuffer(com.google.gwt.typedarrays.shared.ArrayBuffer) Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array)

Example 7 with Uint8Array

use of com.google.gwt.typedarrays.shared.Uint8Array in project actor-platform by actorapp.

the class WebSocketConnection method doSend.

@Override
public void doSend(byte[] data) {
    // Log.d(TAG, "doSend");
    if (isClosed) {
        return;
    }
    Uint8Array push = TypedArrays.createUint8Array(data.length);
    for (int i = 0; i < data.length; i++) {
        push.set(i, data[i]);
    }
    send(push);
}
Also used : Uint8Array(com.google.gwt.typedarrays.shared.Uint8Array) ConnectionEndpoint(im.actor.runtime.mtproto.ConnectionEndpoint)

Aggregations

Uint8Array (com.google.gwt.typedarrays.shared.Uint8Array)7 Promise (im.actor.runtime.promise.Promise)2 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)1 ArrayBuffer (com.google.gwt.typedarrays.shared.ArrayBuffer)1 Float32Array (com.google.gwt.typedarrays.shared.Float32Array)1 Int32Array (com.google.gwt.typedarrays.shared.Int32Array)1 Uint16Array (com.google.gwt.typedarrays.shared.Uint16Array)1 FilePart (im.actor.runtime.files.FilePart)1 HTTPError (im.actor.runtime.http.HTTPError)1 HTTPResponse (im.actor.runtime.http.HTTPResponse)1 JsHttpRequest (im.actor.runtime.js.http.JsHttpRequest)1 ConnectionEndpoint (im.actor.runtime.mtproto.ConnectionEndpoint)1 ByteBuffer (java.nio.ByteBuffer)1 HasArrayBufferView (java.nio.HasArrayBufferView)1