63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
|
|
||
|
// Called on server initialization
|
||
|
function onInit() {
|
||
|
console.log("server started");
|
||
|
|
||
|
// Register RPC exposed methods
|
||
|
rpc.register("echo", echo);
|
||
|
rpc.register("throwErrorFromClient", throwError);
|
||
|
|
||
|
rpc.register("add", add);
|
||
|
rpc.register("reset", reset);
|
||
|
rpc.register("total", total);
|
||
|
}
|
||
|
|
||
|
// Called for each client message
|
||
|
function onClientMessage(ctx, data) {
|
||
|
var sessionId = context.get(ctx, context.SESSION_ID);
|
||
|
console.log("onClientMessage", sessionId, data.now);
|
||
|
net.send(ctx, { now: data.now });
|
||
|
}
|
||
|
|
||
|
// Called for each blob upload request
|
||
|
function onBlobUpload(ctx, blobId, blobInfo, metadata) {
|
||
|
console.log("onBlobUpload", blobId, blobInfo, metadata);
|
||
|
|
||
|
if (!blobInfo.contentType == "application/json") return { allow: false };
|
||
|
if (!blobInfo.filename == "blob") return { allow: false };
|
||
|
|
||
|
return { allow: true, bucket: "test-bucket" };
|
||
|
}
|
||
|
|
||
|
// Called for each blob download request
|
||
|
function onBlobDownload(ctx, bucket, blobId) {
|
||
|
console.log("onBlobDownload", bucket, blobId);
|
||
|
return { allow: true };
|
||
|
}
|
||
|
|
||
|
// RPC methods
|
||
|
|
||
|
function echo(ctx, params) {
|
||
|
console.log("echoing", params);
|
||
|
return params;
|
||
|
}
|
||
|
|
||
|
function throwError(ctx, params) {
|
||
|
throw new Error("oh no !");
|
||
|
}
|
||
|
|
||
|
var count = 0;
|
||
|
|
||
|
function add(ctx, params) {
|
||
|
console.log("add", params);
|
||
|
count += params.value;
|
||
|
return count;
|
||
|
}
|
||
|
|
||
|
function reset(ctx, params) {
|
||
|
count = 0;
|
||
|
}
|
||
|
|
||
|
function total(ctx, params) {
|
||
|
return count;
|
||
|
}
|