Last active
December 24, 2015 06:09
-
-
Save pk11/6755555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var avatar = require("org/glassfish/avatar"); | |
var getTime = function() { | |
var result = new Date(); | |
return { | |
time: result.toISOString(), | |
h: result.getHours(), | |
m: result.getMinutes(), | |
s: result.getSeconds(), | |
d: result.getDate(), | |
M: result.getMonth()+1,//getMonth() returns 0-11 | |
y: result.getFullYear()}; | |
}; | |
avatar.registerRestService({ | |
url: "data/name", | |
methods: ["GET", "PUT"]}, | |
function() { | |
this.$onGet = function(request, response) { | |
console.log("incoming data:"+JSON.stringify(avatar)) ; | |
return response.$send({name:"defaultABCXYYW"}); | |
}; | |
this.$onPut = function(request, response) { | |
var name = request.data.name; | |
return response.$send({name:name.toLowerCase()}); | |
}; | |
} | |
); | |
avatar.registerPushService({ | |
url: "push/time"}, | |
function() { | |
this.$onOpen = this.$onTimeout = function(context) { | |
context.$setTimeout(1000); | |
return context.$sendMessage(getTime()); | |
}; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment