]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7889: [mod_conference] move conference chat to use an event channel so messages...
authorMichael Jerris <mike@jerris.com>
Fri, 24 Jul 2015 00:09:24 +0000 (19:09 -0500)
committerMichael Jerris <mike@jerris.com>
Fri, 24 Jul 2015 00:09:24 +0000 (19:09 -0500)
html5/verto/js/src/jquery.verto.js
html5/verto/video_demo/js/verto-min.js
html5/verto/video_demo/verto.js
src/mod/applications/mod_conference/conference_event.c
src/mod/applications/mod_conference/mod_conference.c
src/mod/applications/mod_conference/mod_conference.h
src/mod/endpoints/mod_verto/mod_verto.c

index cbb7ef59f899af1e4708538b41b7a8b1d0665ca7..ce4bb0b4e01b874a60b4f19a08f09ab1a2cf1965 100644 (file)
 
         //$(".jsDataTable").width(confMan.params.hasVid ? "900px" : "800px");
 
+       verto.subscribe(confMan.params.laData.chatChannel, {
+           handler: function(v, e) {
+               if (typeof(confMan.params.chatCallback) === "function") {
+                   confMan.params.chatCallback(v,e);
+               }
+           }
+       });
+
         if (confMan.params.laData.role === "moderator") {
             atitle = "Action";
             awidth = 600;
             }
        });
     };
-                                   
+
+    $.verto.confMan.prototype.sendChat = function(message, type) {
+        var confMan = this;
+        confMan.verto.rpcClient.call("verto.broadcast", {
+            "eventChannel": confMan.params.laData.chatChannel,
+            "data": {
+               "action": "send",
+               "message": message,
+               "type": type
+            }
+       });
+    };
 
 
     $.verto.confMan.prototype.destroy = function() {
             confMan.lt.destroy();
         }
 
+        if (confMan.params.laData.chatChannel) {
+            confMan.verto.unsubscribe(confMan.params.laData.chatChannel);
+        }
+
         if (confMan.params.laData.modChannel) {
             confMan.verto.unsubscribe(confMan.params.laData.modChannel);
         }
index da37cb5967b850bde6e57fbe27b1cc4ce6f958d3..d2552ddc5cfea3096c46872642c2cf9cb660f707 100644 (file)
@@ -199,13 +199,14 @@ html+="<br>"+"<button class='ctlbtn' id='"+layer_set_id+"'>Set Layer</button>"+"
 jq.html(html);if(!jq.data("mouse")){$("#"+box_id).hide();}
 jq.mouseover(function(e){jq.data({"mouse":true});$("#"+box_id).show();});jq.mouseout(function(e){jq.data({"mouse":false});$("#"+box_id).hide();});$("#"+transfer_id).click(function(){var xten=prompt("Enter Extension");if(xten){confMan.modCommand("transfer",x,xten);}});$("#"+kick_id).click(function(){confMan.modCommand("kick",x);});$("#"+layer_set_id).click(function(){var cid=prompt("Please enter layer ID","");if(cid){confMan.modCommand("vid-layer",x,cid);}});$("#"+layer_next_id).click(function(){confMan.modCommand("vid-layer",x,"next");});$("#"+layer_prev_id).click(function(){confMan.modCommand("vid-layer",x,"prev");});$("#"+canvas_in_set_id).click(function(){var cid=prompt("Please enter canvas ID","");if(cid){confMan.modCommand("vid-canvas",x,cid);}});$("#"+canvas_out_set_id).click(function(){var cid=prompt("Please enter canvas ID","");if(cid){confMan.modCommand("vid-watching-canvas",x,cid);}});$("#"+canvas_in_next_id).click(function(){confMan.modCommand("vid-canvas",x,"next");});$("#"+canvas_in_prev_id).click(function(){confMan.modCommand("vid-canvas",x,"prev");});$("#"+canvas_out_next_id).click(function(){confMan.modCommand("vid-watching-canvas",x,"next");});$("#"+canvas_out_prev_id).click(function(){confMan.modCommand("vid-watching-canvas",x,"prev");});$("#"+tmute_id).click(function(){confMan.modCommand("tmute",x);});if(confMan.params.hasVid){$("#"+tvmute_id).click(function(){confMan.modCommand("tvmute",x);});$("#"+tvpresenter_id).click(function(){confMan.modCommand("vid-res-id",x,"presenter");});$("#"+tvfloor_id).click(function(){confMan.modCommand("vid-floor",x,"force");});$("#"+vbanner_id).click(function(){var text=prompt("Please enter text","");if(text){confMan.modCommand("vid-banner",x,escape(text));}});}
 $("#"+volup_id).click(function(){confMan.modCommand("volume_in",x,"up");});$("#"+voldn_id).click(function(){confMan.modCommand("volume_in",x,"down");});return html;}
-var atitle="";var awidth=0;if(confMan.params.laData.role==="moderator"){atitle="Action";awidth=600;if(confMan.params.mainModID){genMainMod($(confMan.params.mainModID));$(confMan.params.displayID).html("Moderator Controls Ready<br><br>");}else{$(confMan.params.mainModID).html("");}
+var atitle="";var awidth=0;verto.subscribe(confMan.params.laData.chatChannel,{handler:function(v,e){if(typeof(confMan.params.chatCallback)==="function"){confMan.params.chatCallback(v,e);}}});if(confMan.params.laData.role==="moderator"){atitle="Action";awidth=600;if(confMan.params.mainModID){genMainMod($(confMan.params.mainModID));$(confMan.params.displayID).html("Moderator Controls Ready<br><br>");}else{$(confMan.params.mainModID).html("");}
 verto.subscribe(confMan.params.laData.modChannel,{handler:function(v,e){if(confMan.params.onBroadcast){confMan.params.onBroadcast(verto,confMan,e.data);}
 if(e.data["conf-command"]==="list-videoLayouts"){for(var j=0;j<confMan.canvasCount;j++){var vlselect_id="#confman_vl_select_"+j+"_"+confMan.serno;var vlayout_id="#confman_vid_layout_"+j+"_"+confMan.serno;var x=0;var options;$(vlselect_id).selectmenu({});$(vlselect_id).selectmenu("enable");$(vlselect_id).empty();$(vlselect_id).append(new Option("Choose a Layout","none"));if(e.data.responseData){options=e.data.responseData.sort();for(var i in options){$(vlselect_id).append(new Option(options[i],options[i]));x++;}}
 if(x){$(vlselect_id).selectmenu('refresh',true);}else{$(vlayout_id).hide();}}}else{if(!confMan.destroyed&&confMan.params.displayID){$(confMan.params.displayID).html(e.data.response+"<br><br>");if(confMan.lastTimeout){clearTimeout(confMan.lastTimeout);confMan.lastTimeout=0;}
 confMan.lastTimeout=setTimeout(function(){$(confMan.params.displayID).html(confMan.destroyed?"":"Moderator Controls Ready<br><br>");},4000);}}}});if(confMan.params.hasVid){confMan.modCommand("list-videoLayouts",null,null);}}
 var row_callback=null;if(confMan.params.laData.role==="moderator"){row_callback=function(nRow,aData,iDisplayIndex,iDisplayIndexFull){if(!aData[5]){var $row=$('td:eq(5)',nRow);genControls($row,aData);if(confMan.params.onLaRow){confMan.params.onLaRow(verto,confMan,$row,aData);}}};}
-confMan.lt=new $.verto.liveTable(verto,confMan.params.laData.laChannel,confMan.params.laData.laName,$(confMan.params.tableID),{subParams:{callID:confMan.params.dialog?confMan.params.dialog.callID:null},"onChange":function(obj,args){$(confMan.params.statusID).text("Conference Members: "+" ("+obj.arrayLen()+" Total)");if(confMan.params.onLaChange){confMan.params.onLaChange(verto,confMan,$.verto.enum.confEvent.laChange,obj,args);}},"aaData":[],"aoColumns":[{"sTitle":"ID","sWidth":"50"},{"sTitle":"Number","sWidth":"250"},{"sTitle":"Name","sWidth":"250"},{"sTitle":"Codec","sWidth":"100"},{"sTitle":"Status","sWidth":confMan.params.hasVid?"200px":"150px"},{"sTitle":atitle,"sWidth":awidth,}],"bAutoWidth":true,"bDestroy":true,"bSort":false,"bInfo":false,"bFilter":false,"bLengthChange":false,"bPaginate":false,"iDisplayLength":1400,"oLanguage":{"sEmptyTable":"The Conference is Empty....."},"fnRowCallback":row_callback});};$.verto.confMan.prototype.modCommand=function(cmd,id,value){var confMan=this;confMan.verto.rpcClient.call("verto.broadcast",{"eventChannel":confMan.params.laData.modChannel,"data":{"application":"conf-control","command":cmd,"id":id,"value":value}});};$.verto.confMan.prototype.destroy=function(){var confMan=this;confMan.destroyed=true;if(confMan.lt){confMan.lt.destroy();}
+confMan.lt=new $.verto.liveTable(verto,confMan.params.laData.laChannel,confMan.params.laData.laName,$(confMan.params.tableID),{subParams:{callID:confMan.params.dialog?confMan.params.dialog.callID:null},"onChange":function(obj,args){$(confMan.params.statusID).text("Conference Members: "+" ("+obj.arrayLen()+" Total)");if(confMan.params.onLaChange){confMan.params.onLaChange(verto,confMan,$.verto.enum.confEvent.laChange,obj,args);}},"aaData":[],"aoColumns":[{"sTitle":"ID","sWidth":"50"},{"sTitle":"Number","sWidth":"250"},{"sTitle":"Name","sWidth":"250"},{"sTitle":"Codec","sWidth":"100"},{"sTitle":"Status","sWidth":confMan.params.hasVid?"200px":"150px"},{"sTitle":atitle,"sWidth":awidth,}],"bAutoWidth":true,"bDestroy":true,"bSort":false,"bInfo":false,"bFilter":false,"bLengthChange":false,"bPaginate":false,"iDisplayLength":1400,"oLanguage":{"sEmptyTable":"The Conference is Empty....."},"fnRowCallback":row_callback});};$.verto.confMan.prototype.modCommand=function(cmd,id,value){var confMan=this;confMan.verto.rpcClient.call("verto.broadcast",{"eventChannel":confMan.params.laData.modChannel,"data":{"application":"conf-control","command":cmd,"id":id,"value":value}});};$.verto.confMan.prototype.sendChat=function(message,type){var confMan=this;confMan.verto.rpcClient.call("verto.broadcast",{"eventChannel":confMan.params.laData.chatChannel,"data":{"action":"send","message":message,"type":type}});};$.verto.confMan.prototype.destroy=function(){var confMan=this;confMan.destroyed=true;if(confMan.lt){confMan.lt.destroy();}
+if(confMan.params.laData.chatChannel){confMan.verto.unsubscribe(confMan.params.laData.chatChannel);}
 if(confMan.params.laData.modChannel){confMan.verto.unsubscribe(confMan.params.laData.modChannel);}
 if(confMan.params.mainModID){$(confMan.params.mainModID).html("");}};$.verto.dialog=function(direction,verto,params){var dialog=this;dialog.params=$.extend({useVideo:verto.options.useVideo,useStereo:verto.options.useStereo,screenShare:false,useCamera:"any",useMic:"any",useSpeak:"any",tag:verto.options.tag,localTag:verto.options.localTag,login:verto.options.login,videoParams:verto.options.videoParams},params);dialog.useCamera=verto.options.deviceParams.useCamera;dialog.useMic=verto.options.deviceParams.useMic;dialog.useSpeak=verto.options.deviceParams.useSpeak;dialog.verto=verto;dialog.direction=direction;dialog.lastState=null;dialog.state=dialog.lastState=$.verto.enum.state.new;dialog.callbacks=verto.callbacks;dialog.answered=false;dialog.attach=params.attach||false;dialog.screenShare=params.screenShare||false;dialog.useCamera=params.useCamera;dialog.useMic=params.useMic;dialog.useSpeak=params.useSpeak;if(dialog.params.callID){dialog.callID=dialog.params.callID;}else{dialog.callID=dialog.params.callID=generateGUID();}
 if(dialog.params.tag){dialog.audioStream=document.getElementById(dialog.params.tag);if(dialog.params.useVideo){dialog.videoStream=dialog.audioStream;}}
index 638be186a4de9655d112b531727f8b179ab752cd..bd37b16c4e066dbb7a903052d84a74db2b19f78f 100644 (file)
@@ -70,15 +70,11 @@ function setupChat() {
     $("#chatwin").html("");
 
     $("#chatsend").click(function() {
-       if (!cur_call && chatting_with) {
+       if (!cur_call || !chatting_with || !confMan) {
            return;
        }
 
-       cur_call.message({to: chatting_with, 
-                         body: $("#chatmsg").val(), 
-                         from_msg_name: cur_call.params.caller_id_name, 
-                         from_msg_number: cur_call.params.caller_id_number
-                        });  
+       confMan.sendChat($("#chatmsg").val(), "message");
        $("#chatmsg").val("");
     });
 
@@ -307,7 +303,19 @@ var callbacks = {
                            displayID: "#conf_display",
                            dialog: dialog,
                            hasVid: check_vid(),
-                           laData: data.pvtData
+                           laData: data.pvtData,
+                           chatCallback: function(v, e) {
+                               console.log(e);
+                               var from = e.data.fromDisplay || e.data.from || "Unknown";
+                               var message = e.data.message || "";
+
+                               $('#chatwin')
+                                   .append($('<span class="chatuid" />').text(from + ':'))
+                                   .append($('<br />'))
+                                   .append(messageTextToJQ(message))
+                                   .append($('<br />'));
+                               $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast");
+                           }
                        });
 
                        if (!data.pvtData.canvasCount) {
@@ -366,7 +374,7 @@ var callbacks = {
                            $("#message").show();
                        }
 
-                       chatting_with = data.pvtData.chatID;
+                       chatting_with = data.pvtData.chatChannel;
                    }
 
                     break;
index 5494f9531a341c8c6ee07d0da7c0980876fb4e7a..009b380b7b14503f14e14c0bff329dbd16837193 100644 (file)
@@ -212,6 +212,68 @@ void conference_event_mod_channel_handler(const char *event_channel, cJSON *json
 
 }
 
+void conference_event_chat_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
+{
+       cJSON *data;
+       cJSON *jid = 0;
+       const char *type = NULL;
+       const char *action = NULL;
+       cJSON *msg;
+       char *conference_name = strdup(event_channel + 15);
+       char *message = NULL;
+       cJSON *jdata;
+       char *p;
+       const char *uid = NULL;
+       const char *display = NULL;
+
+       if (conference_name && (p = strchr(conference_name, '@'))) {
+               *p = '\0';
+       }
+
+       uid = cJSON_GetObjectCstr(json, "userid");
+       display = cJSON_GetObjectCstr(json, "fromDisplay");
+
+       if ((data = cJSON_GetObjectItem(json, "data"))) {
+               type = cJSON_GetObjectCstr(data, "type");
+               action = cJSON_GetObjectCstr(data, "action");
+               if ((jid = cJSON_GetObjectItem(data, "message"))) {
+                       if (!zstr(jid->valuestring)) {
+                               message = jid->valuestring;
+                       }
+               }
+       }
+
+       if (action && !strcasecmp(action, "send")) {
+               msg = cJSON_CreateObject();
+               jdata = json_add_child_obj(msg, "data", NULL);
+
+               cJSON_AddItemToObject(msg, "eventChannel", cJSON_CreateString(event_channel));
+               cJSON_AddItemToObject(jdata, "direction", cJSON_CreateString("outbound"));
+
+               if (message) {
+                       cJSON_AddItemToObject(jdata, "message", cJSON_CreateString(message));
+               }
+
+               if (display) {
+                       cJSON_AddItemToObject(jdata, "fromDisplay", cJSON_CreateString(display));
+               }
+
+               if (uid) {
+                       cJSON_AddItemToObject(jdata, "from", cJSON_CreateString(uid));
+               }
+
+               if (type) {
+                       cJSON_AddItemToObject(jdata, "type", cJSON_CreateString(type));
+               } else {
+                       cJSON_AddItemToObject(jdata, "type", cJSON_CreateString("message"));
+               }
+
+               switch_event_channel_broadcast(event_channel, &msg, __FILE__, conference_globals.event_channel_id);
+       }
+
+       switch_safe_free(conference_name);
+}
+
 void conference_event_la_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id)
 {
        switch_live_array_parse_json(json, conference_globals.event_channel_id);
@@ -347,6 +409,8 @@ void conference_event_adv_la(conference_obj_t *conference, conference_member_t *
                        cJSON_AddItemToObject(data, "modChannel", cJSON_CreateString(conference->mod_event_channel));
                }
 
+               cJSON_AddItemToObject(data, "chatChannel", cJSON_CreateString(conference->chat_event_channel));
+
                switch_core_get_variables(&variables);
                for (hp = variables->headers; hp; hp = hp->next) {
                        if (!strncasecmp(hp->name, "conference_verto_", 11)) {
@@ -363,6 +427,7 @@ void conference_event_adv_la(conference_obj_t *conference, conference_member_t *
                if (cookie) {
                        switch_event_channel_permission_modify(cookie, conference->la_event_channel, join);
                        switch_event_channel_permission_modify(cookie, conference->mod_event_channel, join);
+                       switch_event_channel_permission_modify(cookie, conference->chat_event_channel, join);
                }
        }
 }
index 4d5e3f3e4b95795c1e1475b554a3dd550416994c..a9f2b46e4692962b3b0681a4c85646e261d7f515 100644 (file)
@@ -242,9 +242,11 @@ void *SWITCH_THREAD_FUNC conference_thread_run(switch_thread_t *thread, void *ob
 
                if (strchr(conference->name, '@')) {
                        conference->la_event_channel = switch_core_sprintf(conference->pool, "conference-liveArray.%s", conference->name);
+                       conference->chat_event_channel = switch_core_sprintf(conference->pool, "conference-chat.%s", conference->name);
                        conference->mod_event_channel = switch_core_sprintf(conference->pool, "conference-mod.%s", conference->name);
                } else {
                        conference->la_event_channel = switch_core_sprintf(conference->pool, "conference-liveArray.%s@%s", conference->name, conference->domain);
+                       conference->chat_event_channel = switch_core_sprintf(conference->pool, "conference-chat.%s@%s", conference->name, conference->domain);
                        conference->mod_event_channel = switch_core_sprintf(conference->pool, "conference-mod.%s@%s", conference->name, conference->domain);
                }
 
@@ -3303,6 +3305,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_conference_load)
        switch_event_channel_bind("conference", conference_event_channel_handler, &conference_globals.event_channel_id);
        switch_event_channel_bind("conference-liveArray", conference_event_la_channel_handler, &conference_globals.event_channel_id);
        switch_event_channel_bind("conference-mod", conference_event_mod_channel_handler, &conference_globals.event_channel_id);
+       switch_event_channel_bind("conference-chat", conference_event_chat_channel_handler, &conference_globals.event_channel_id);
 
        if ( conference_api_sub_syntax(&api_syntax) != SWITCH_STATUS_SUCCESS) {
                return SWITCH_STATUS_TERM;
@@ -3358,6 +3361,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_conference_shutdown)
 
                switch_event_channel_unbind(NULL, conference_event_channel_handler);
                switch_event_channel_unbind(NULL, conference_event_la_channel_handler);
+               switch_event_channel_unbind(NULL, conference_event_mod_channel_handler);
+               switch_event_channel_unbind(NULL, conference_event_chat_channel_handler);
 
                switch_console_del_complete_func("::conference::conference_list_conferences");
 
index 9b1797c4e3b13c65979905f235264e8cd7445bef..d0e93569098a69e9f06e7110055924dcb84d7f9a 100644 (file)
@@ -515,6 +515,7 @@ typedef struct conference_obj {
        char *name;
        char *la_name;
        char *la_event_channel;
+       char *chat_event_channel;
        char *mod_event_channel;
        char *desc;
        char *timer_name;
@@ -1002,7 +1003,7 @@ void conference_cdr_render(conference_obj_t *conference);
 void conference_event_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
 void conference_event_la_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
 void conference_event_mod_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
-
+void conference_event_chat_channel_handler(const char *event_channel, cJSON *json, const char *key, switch_event_channel_id_t id);
 
 void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, uint8_t non_mod, conference_api_member_cmd_t pfncallback, void *data);
 
index 8cb668fc95a0687d144085dce244f53a0ad8c76b..dad87ba279a8f43e1a0b0d62924909ed4fb11fb8 100644 (file)
@@ -3386,8 +3386,10 @@ static switch_bool_t verto__invite_func(const char *method, cJSON *params, jsock
                if ((var = switch_event_get_header(jsock->params, "caller-id-name"))) {
                        caller_id_name = var;
                }
+       } else if (caller_id_name) {
+               switch_event_add_header_string(jsock->params, SWITCH_STACK_BOTTOM, "caller-id-name", caller_id_name);
        }
-       
+
        if (zstr(caller_id_number)) {
                if ((var = switch_event_get_header(jsock->params, "caller-id-number"))) {
                        caller_id_number = var;
@@ -3647,6 +3649,7 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
        switch_bool_t r = SWITCH_FALSE;
        const char *event_channel = cJSON_GetObjectCstr(params, "eventChannel");
        cJSON *jevent;
+       const char *display = NULL;
 
        *response = cJSON_CreateObject();
 
@@ -3666,6 +3669,11 @@ static switch_bool_t verto__broadcast_func(const char *method, cJSON *params, js
 
        cJSON_AddItemToObject(params, "userid", cJSON_CreateString(jsock->uid)); 
 
+       display = switch_event_get_header(jsock->params, "caller-id-name");
+       if (display) {
+               cJSON_AddItemToObject(params, "fromDisplay", cJSON_CreateString(display));
+       }
+
        jevent = cJSON_Duplicate(params, 1);
        switch_event_channel_broadcast(event_channel, &jevent, modname, globals.event_channel_id);