You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.8 KiB
61 lines
1.8 KiB
"use strict"; |
|
|
|
Cortex.createTwisterRPC = function () { |
|
var createCommand = function (methodName, parameters) { |
|
var command = new Object(); |
|
command.jsonrpc = "2.0"; |
|
command.method = methodName; |
|
command.params = parameters; |
|
return command; |
|
} |
|
|
|
var sendCommand = function (command) { |
|
return $.ajax({ |
|
type: 'POST', |
|
contentType: 'application/json', |
|
url: "/", |
|
cache: false, |
|
async: true, |
|
data: JSON.stringify(command), |
|
//crossDomain: true, |
|
//beforeSend: function (xhr) { |
|
// xhr.withCredentials = true; |
|
// xhr.setRequestHeader('Authorization', TwisterClient.CreateBasicAuthHeader(TwisterClient.RpcUser, TwisterClient.RpcPassword)); |
|
//} |
|
}); |
|
} |
|
|
|
var getLastHave = function (user) { |
|
var command = createCommand("getlasthave", [user]); |
|
return sendCommand(command); |
|
} |
|
|
|
var newPostMsg = function (user, k, message, replyTo) { |
|
var parameters = [user, k, message]; |
|
|
|
if (replyTo !== undefined) { |
|
parameters.push(replyTo.user); |
|
parameters.push(replyTo.k); |
|
} |
|
|
|
var command = createCommand("newpostmsg", parameters); |
|
return sendCommand(command); |
|
} |
|
|
|
var newRTMsg = function (user, k, rt) { |
|
var command = createCommand("newrtmsg", [user, k, rt]); |
|
return sendCommand(command); |
|
} |
|
|
|
var getPosts = function (count, ranges) { |
|
var command = createCommand("getposts", [count, ranges]); |
|
return sendCommand(command); |
|
} |
|
|
|
return { |
|
getLastHave: getLastHave, |
|
newPostMsg: newPostMsg, |
|
newRTMsg: newRTMsg, |
|
getPosts: getPosts |
|
}; |
|
};
|
|
|