FS-7509: add userVariables parser to initial connection all variables set in this obj will be set on every inbound call
This commit is contained in:
parent
d3a5605ab6
commit
5ab557fd51
|
@ -65,14 +65,15 @@
|
||||||
$.JsonRpcClient = function(options) {
|
$.JsonRpcClient = function(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.options = $.extend({
|
this.options = $.extend({
|
||||||
ajaxUrl : null,
|
ajaxUrl : null,
|
||||||
socketUrl : null, ///< The ws-url for default getSocket.
|
socketUrl : null, ///< The ws-url for default getSocket.
|
||||||
onmessage : null, ///< Other onmessage-handler.
|
onmessage : null, ///< Other onmessage-handler.
|
||||||
login : null, /// auth login
|
login : null, /// auth login
|
||||||
passwd : null, /// auth passwd
|
passwd : null, /// auth passwd
|
||||||
sessid : null,
|
sessid : null,
|
||||||
loginParams : null,
|
loginParams : null,
|
||||||
getSocket : function(onmessage_cb) { return self._getSocket(onmessage_cb); }
|
userVariables : null,
|
||||||
|
getSocket : function(onmessage_cb) { return self._getSocket(onmessage_cb); }
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
self.ws_cnt = 0;
|
self.ws_cnt = 0;
|
||||||
|
@ -263,6 +264,7 @@
|
||||||
self.options.login = params.login;
|
self.options.login = params.login;
|
||||||
self.options.passwd = params.passwd;
|
self.options.passwd = params.passwd;
|
||||||
self.options.loginParams = params.loginParams;
|
self.options.loginParams = params.loginParams;
|
||||||
|
self.options.userVariables = params.userVariables;
|
||||||
};
|
};
|
||||||
|
|
||||||
$.JsonRpcClient.prototype.connectSocket = function(onmessage_cb) {
|
$.JsonRpcClient.prototype.connectSocket = function(onmessage_cb) {
|
||||||
|
@ -422,7 +424,8 @@
|
||||||
if (!self.authing && response.error.code == -32000 && self.options.login && self.options.passwd) {
|
if (!self.authing && response.error.code == -32000 && self.options.login && self.options.passwd) {
|
||||||
self.authing = true;
|
self.authing = true;
|
||||||
|
|
||||||
this.call("login", { login: self.options.login, passwd: self.options.passwd, loginParams: self.options.loginParams},
|
this.call("login", { login: self.options.login, passwd: self.options.passwd, loginParams: self.options.loginParams,
|
||||||
|
userVariables: self.options.userVariables},
|
||||||
this._ws_callbacks[response.id].request_obj.method == "login" ?
|
this._ws_callbacks[response.id].request_obj.method == "login" ?
|
||||||
function(e) {
|
function(e) {
|
||||||
self.authing = false;
|
self.authing = false;
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
videoParams: {},
|
videoParams: {},
|
||||||
audioParams: {},
|
audioParams: {},
|
||||||
loginParams: {},
|
loginParams: {},
|
||||||
|
userVariables: {},
|
||||||
iceServers: false,
|
iceServers: false,
|
||||||
ringSleep: 6000
|
ringSleep: 6000
|
||||||
}, options);
|
}, options);
|
||||||
|
@ -94,6 +95,7 @@
|
||||||
passwd: verto.options.passwd,
|
passwd: verto.options.passwd,
|
||||||
socketUrl: verto.options.socketUrl,
|
socketUrl: verto.options.socketUrl,
|
||||||
loginParams: verto.options.loginParams,
|
loginParams: verto.options.loginParams,
|
||||||
|
userVariables: verto.options.userVariables,
|
||||||
sessid: verto.sessid,
|
sessid: verto.sessid,
|
||||||
onmessage: function(e) {
|
onmessage: function(e) {
|
||||||
return verto.handleMessage(e.eventData);
|
return verto.handleMessage(e.eventData);
|
||||||
|
|
|
@ -885,7 +885,7 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
|
||||||
switch_bool_t r = SWITCH_FALSE;
|
switch_bool_t r = SWITCH_FALSE;
|
||||||
const char *passwd = NULL;
|
const char *passwd = NULL;
|
||||||
const char *login = NULL;
|
const char *login = NULL;
|
||||||
cJSON *login_params = NULL;
|
cJSON *json_ptr = NULL;
|
||||||
|
|
||||||
if (!params) {
|
if (!params) {
|
||||||
*code = CODE_AUTH_FAILED;
|
*code = CODE_AUTH_FAILED;
|
||||||
|
@ -945,10 +945,10 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
|
||||||
switch_event_create(&req_params, SWITCH_EVENT_REQUEST_PARAMS);
|
switch_event_create(&req_params, SWITCH_EVENT_REQUEST_PARAMS);
|
||||||
switch_assert(req_params);
|
switch_assert(req_params);
|
||||||
|
|
||||||
if ((login_params = cJSON_GetObjectItem(params, "loginParams"))) {
|
if ((json_ptr = cJSON_GetObjectItem(params, "loginParams"))) {
|
||||||
cJSON * i;
|
cJSON * i;
|
||||||
|
|
||||||
for(i = login_params->child; i; i = i->next) {
|
for(i = json_ptr->child; i; i = i->next) {
|
||||||
if (i->type == cJSON_True) {
|
if (i->type == cJSON_True) {
|
||||||
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "true");
|
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, i->string, "true");
|
||||||
} else if (i->type == cJSON_False) {
|
} else if (i->type == cJSON_False) {
|
||||||
|
@ -959,6 +959,21 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ((json_ptr = cJSON_GetObjectItem(params, "userVariables"))) {
|
||||||
|
cJSON * i;
|
||||||
|
|
||||||
|
for(i = json_ptr->child; i; i = i->next) {
|
||||||
|
if (i->type == cJSON_True) {
|
||||||
|
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "true");
|
||||||
|
} else if (i->type == cJSON_False) {
|
||||||
|
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, "false");
|
||||||
|
} else if (!zstr(i->string) && !zstr(i->valuestring)) {
|
||||||
|
switch_event_add_header_string(jsock->user_vars, SWITCH_STACK_BOTTOM, i->string, i->valuestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, "action", "jsonrpc-authenticate");
|
switch_event_add_header_string(req_params, SWITCH_STACK_BOTTOM, "action", "jsonrpc-authenticate");
|
||||||
|
|
||||||
if (switch_xml_locate_user_merged("id", id, domain, NULL, &x_user, req_params) != SWITCH_STATUS_SUCCESS && !jsock->profile->blind_reg) {
|
if (switch_xml_locate_user_merged("id", id, domain, NULL, &x_user, req_params) != SWITCH_STATUS_SUCCESS && !jsock->profile->blind_reg) {
|
||||||
|
@ -1884,6 +1899,7 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj
|
||||||
|
|
||||||
switch_event_create(&jsock->params, SWITCH_EVENT_CHANNEL_DATA);
|
switch_event_create(&jsock->params, SWITCH_EVENT_CHANNEL_DATA);
|
||||||
switch_event_create(&jsock->vars, SWITCH_EVENT_CHANNEL_DATA);
|
switch_event_create(&jsock->vars, SWITCH_EVENT_CHANNEL_DATA);
|
||||||
|
switch_event_create(&jsock->user_vars, SWITCH_EVENT_CHANNEL_DATA);
|
||||||
|
|
||||||
|
|
||||||
add_jsock(jsock);
|
add_jsock(jsock);
|
||||||
|
@ -1902,6 +1918,7 @@ static void *SWITCH_THREAD_FUNC client_thread(switch_thread_t *thread, void *obj
|
||||||
|
|
||||||
switch_event_destroy(&jsock->params);
|
switch_event_destroy(&jsock->params);
|
||||||
switch_event_destroy(&jsock->vars);
|
switch_event_destroy(&jsock->vars);
|
||||||
|
switch_event_destroy(&jsock->user_vars);
|
||||||
|
|
||||||
if (jsock->client_socket > -1) {
|
if (jsock->client_socket > -1) {
|
||||||
close_socket(&jsock->client_socket);
|
close_socket(&jsock->client_socket);
|
||||||
|
@ -2062,14 +2079,19 @@ static switch_status_t verto_connect(switch_core_session_t *session, const char
|
||||||
cJSON *msg = NULL;
|
cJSON *msg = NULL;
|
||||||
const char *var = NULL;
|
const char *var = NULL;
|
||||||
switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(tech_pvt->channel);
|
switch_caller_profile_t *caller_profile = switch_channel_get_caller_profile(tech_pvt->channel);
|
||||||
|
switch_event_header_t *hp;
|
||||||
|
|
||||||
DUMP_EVENT(jsock->params);
|
//DUMP_EVENT(jsock->params);
|
||||||
|
|
||||||
switch_channel_set_variable(tech_pvt->channel, "verto_user", jsock->uid);
|
switch_channel_set_variable(tech_pvt->channel, "verto_user", jsock->uid);
|
||||||
switch_channel_set_variable(tech_pvt->channel, "presence_id", jsock->uid);
|
switch_channel_set_variable(tech_pvt->channel, "presence_id", jsock->uid);
|
||||||
switch_channel_set_variable(tech_pvt->channel, "chat_proto", VERTO_CHAT_PROTO);
|
switch_channel_set_variable(tech_pvt->channel, "chat_proto", VERTO_CHAT_PROTO);
|
||||||
switch_channel_set_variable(tech_pvt->channel, "verto_host", jsock->domain);
|
switch_channel_set_variable(tech_pvt->channel, "verto_host", jsock->domain);
|
||||||
|
|
||||||
|
for (hp = jsock->user_vars->headers; hp; hp = hp->next) {
|
||||||
|
switch_channel_set_variable(tech_pvt->channel, hp->name, hp->value);
|
||||||
|
}
|
||||||
|
|
||||||
if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) {
|
if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) {
|
||||||
caller_profile->callee_id_name = switch_core_strdup(caller_profile->pool, var);
|
caller_profile->callee_id_name = switch_core_strdup(caller_profile->pool, var);
|
||||||
}
|
}
|
||||||
|
@ -3235,6 +3257,7 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
|
||||||
char name[512];
|
char name[512];
|
||||||
const char *var, *destination_number, *call_id = NULL, *sdp = NULL, *bandwidth = NULL,
|
const char *var, *destination_number, *call_id = NULL, *sdp = NULL, *bandwidth = NULL,
|
||||||
*caller_id_name = NULL, *caller_id_number = NULL, *remote_caller_id_name = NULL, *remote_caller_id_number = NULL,*context = NULL;
|
*caller_id_name = NULL, *caller_id_number = NULL, *remote_caller_id_name = NULL, *remote_caller_id_number = NULL,*context = NULL;
|
||||||
|
switch_event_header_t *hp;
|
||||||
|
|
||||||
*response = obj;
|
*response = obj;
|
||||||
|
|
||||||
|
@ -3365,6 +3388,12 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (hp = jsock->user_vars->headers; hp; hp = hp->next) {
|
||||||
|
switch_channel_set_variable(channel, hp->name, hp->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch_channel_set_profile_var(channel, "callee_id_name", remote_caller_id_name);
|
switch_channel_set_profile_var(channel, "callee_id_name", remote_caller_id_name);
|
||||||
switch_channel_set_profile_var(channel, "callee_id_number", remote_caller_id_number);
|
switch_channel_set_profile_var(channel, "callee_id_number", remote_caller_id_number);
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,8 @@ struct jsock_s {
|
||||||
switch_event_t *params;
|
switch_event_t *params;
|
||||||
switch_event_t *vars;
|
switch_event_t *vars;
|
||||||
|
|
||||||
|
switch_event_t *user_vars;
|
||||||
|
|
||||||
switch_queue_t *event_queue;
|
switch_queue_t *event_queue;
|
||||||
int lost_events;
|
int lost_events;
|
||||||
int ready;
|
int ready;
|
||||||
|
|
Loading…
Reference in New Issue