summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/invoker/miles
diff options
context:
space:
mode:
authorAutobuilder at buildslave-ubuntu-12-32 <magnus@alkit.se>2013-11-06 17:05:37 (GMT)
committerAutobuilder at buildslave-ubuntu-12-32 <magnus@alkit.se>2013-11-06 17:05:37 (GMT)
commitc3238c9a5c627491d26ad527f99a08ccfd218c29 (patch)
treeddcdf102e83bbf175a37d9dea3322faebab6a3c4 /src/uscxml/plugins/invoker/miles
parent0a8628a436dd98ca8cff1c1325298bf04328e997 (diff)
downloaduscxml-c3238c9a5c627491d26ad527f99a08ccfd218c29.zip
uscxml-c3238c9a5c627491d26ad527f99a08ccfd218c29.tar.gz
uscxml-c3238c9a5c627491d26ad527f99a08ccfd218c29.tar.bz2
text messaging
Diffstat (limited to 'src/uscxml/plugins/invoker/miles')
-rw-r--r--src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp66
-rw-r--r--src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h3
2 files changed, 67 insertions, 2 deletions
diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp
index 8343758..b45a324 100644
--- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp
+++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp
@@ -75,6 +75,8 @@ void MilesSessionInvoker::init_media_buffers() {
encoded_out_audio = NULL;
audio_read_buf = NULL;
video_data = (char *)malloc(1000000);
+ text_msg_buf = (char *)malloc(1000);
+ text_msg_available = 0;
}
void MilesSessionInvoker::free_media_buffers() {
@@ -103,6 +105,35 @@ void MilesSessionInvoker::free_media_buffers() {
if(audio_read_buf)
free(audio_read_buf);
audio_read_buf = NULL;
+ if(text_msg_buf)
+ free(text_msg_buf);
+ text_msg_buf = NULL;
+ text_msg_available = 0;
+}
+
+// Yes, sort of ugly...
+char confero_text_msg_buf[1000];
+int confero_text_msg_available = 0;
+
+int receive_text_message_callback(u_int32_t ssrc, char *pkt, int length) {
+ char cname[100];
+ int i=0, j;
+
+ while(pkt[i]) {
+ cname[i] = pkt[i];
+ i++;
+ }
+ cname[i++] = 0;
+ j = i;
+ while(pkt[j] && j<length) {
+ if(pkt[j]=='<' || pkt[j]=='>' || pkt[j]=='\r' || pkt[j]=='\n')
+ pkt[j] = ' ';
+ j++;
+ }
+ memcpy(confero_text_msg_buf, pkt+i, length-i);
+ //printf("RTCP app depacketizer called, cname = %s, msg = %s\n", cname, confero_text_msg_buf);
+ confero_text_msg_available = 1;
+ return length;
}
void MilesSessionInvoker::send(const SendRequest& req) {
@@ -229,7 +260,6 @@ void MilesSessionInvoker::processEventStart(const std::string& origin, const std
video_rtp_out_socket = video_rtp_in_socket;
audio_rtp_out_socket = audio_rtp_in_socket;
- LOG(ERROR) << "rtp sockets set up";
/* Set up audio and video RTCP sockets */
video_rtcp_in_socket = miles_net_setup_udp_socket((char*)reflector.c_str(), video_port+1, video_port+1, 10, 16000);
@@ -273,6 +303,13 @@ void MilesSessionInvoker::processEventStart(const std::string& origin, const std
out_rtcp_audio_stream = miles_rtp_setup_outgoing_rtcp_stream(audio_session->rtcp_session, audio_rtcp_out_socket, out_rtp_audio_stream->ssrc);
}
+ /* Register RTCP APP handler for text messages */
+ rv = miles_rtp_register_rtcp_app_handler("text", NULL, receive_text_message_callback, 0);
+ if(rv==0) {
+ LOG(ERROR) << "Error registering text message callback";
+ }
+ memset(confero_text_msg_buf, 0, 1000);
+
_isRunning = true;
_reflector = reflector;
_userId = userid;
@@ -340,7 +377,6 @@ void MilesSessionInvoker::processEventThumbnail(const std::string& origin, const
returnEvent(ev);
return;
}
- LOG(ERROR) << "processEventThumbnail";
URL imageURL("emptyface.jpg");
imageURL.toAbsolute(_interpreter->getBaseURI());
std::stringstream ssImage;
@@ -433,11 +469,26 @@ void MilesSessionInvoker::processEventSendAudioOff(const std::string& origin) {
sendaudio_enabled = 0;
}
void MilesSessionInvoker::processEventPostText(const std::string& origin, const std::string& userid, const std::string& message) {
+ char msgbuf[1000];
+ char pkt[1000];
+ char *cname = "user@all"; // for now
+ int n, length;
Event ev;
+
ev.name = "posttext.reply";
ev.data.compound["origin"] = origin;
returnEvent(ev);
+ if(out_rtcp_video_stream==NULL)
+ return;
+ //printf("sending message %s\n", message.c_str());
+ memcpy(msgbuf, cname, strlen(cname)+1);
+ sprintf(msgbuf+strlen(cname)+1, "<%s>: %s", userid.c_str(), message.c_str());
+ n = strlen(cname)+1 + userid.length() + 4 + message.length();
+ length = miles_rtp_make_rtcp_app(pkt, out_rtcp_video_stream->ssrc, "text", n, msgbuf);
+ if(length>0 && out_rtcp_video_stream)
+ out_rtcp_video_stream->send_packet(out_rtcp_video_stream->socket, pkt, length, 0);
}
+
void MilesSessionInvoker::processEventGetText(const std::string& origin) {
Event ev;
ev.data.compound["origin"] = origin;
@@ -449,10 +500,21 @@ void MilesSessionInvoker::processEventGetText(const std::string& origin) {
}
ev.name = "gettext.reply";
+#if 0
if (rand() % 5 == 0) { // return some mocked up chat message
ev.data.compound["message"] = Data(".. and then she was all like: aren't we supposed to discuss work related stuff?", Data::VERBATIM);
ev.data.compound["user"] = Data("username1", Data::VERBATIM);
}
+#else
+ if(confero_text_msg_available) {
+ strcpy(text_msg_buf, confero_text_msg_buf);
+ ev.data.compound["message"] = Data(text_msg_buf, Data::VERBATIM);
+ //ev.data.compound["message"] = Data(base64_encode(text_msg_buf, strlen(text_msg_buf)), Data::VERBATIM);
+ ev.data.compound["user"] = Data("username1", Data::VERBATIM);
+ memset(confero_text_msg_buf, 0, 1000);
+ confero_text_msg_available = 0;
+ }
+#endif
returnEvent(ev);
}
diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h
index efa3ba2..eeb6e7c 100644
--- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h
+++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h
@@ -120,6 +120,9 @@ protected:
struct miles_list *thumb_list;
int save_image;
+ char *text_msg_buf;
+ int text_msg_available;
+
struct miles_audio_device *audio_dev_playback;
int audio_dev_playback_id;
int audio_available;