use of im.actor.runtime.js.http.JsHttpRequest in project actor-platform by actorapp.
the class JsHttpProvider method putMethod.
@Override
public Promise<HTTPResponse> putMethod(String url, byte[] contents) {
return new Promise<>(resolver -> {
JsHttpRequest request = JsHttpRequest.create();
request.open("PUT", url);
request.setRequestHeader("Content-Type", "application/octet-stream");
request.setOnLoadHandler(request1 -> {
if (request1.getReadyState() == 4) {
if (request1.getStatus() >= 200 && request1.getStatus() < 300) {
resolver.result(new HTTPResponse(request1.getStatus(), null));
} else {
resolver.error(new HTTPError(request1.getStatus()));
}
}
});
Uint8Array push = TypedArrays.createUint8Array(contents.length);
for (int i = 0; i < contents.length; i++) {
push.set(i, contents[i]);
}
request.send(push.buffer());
});
}
use of im.actor.runtime.js.http.JsHttpRequest in project actor-platform by actorapp.
the class JsSmallAvatarFileCache method onAvatarUrlLoaded.
private void onAvatarUrlLoaded(final long id, String url) {
JsHttpRequest request = JsHttpRequest.create();
request.open("GET", url);
request.setOnLoadHandler(new JsHttpRequestHandler() {
@Override
public void onStateChanged(JsHttpRequest request) {
if (request.getReadyState() == 4) {
if (request.getStatus() == 200) {
JsBlob blob = request.getResponseBlob();
onAvatarDownloaded(id, blob);
} else {
// TODO: Implement better
cachedImages.put(id, null);
}
}
}
});
request.send();
}
Aggregations