From 8d466ce1171b78cd234d6e63d09d058888a17e2d Mon Sep 17 00:00:00 2001 From: Autobuilder at buildslave-ubuntu-12-32 Date: Mon, 4 Nov 2013 15:48:42 +0100 Subject: added miles/stop --- apps/samples/miles/miles.js | 29 +++++++++++---- apps/samples/miles/miles.scxml | 15 ++++++-- .../invoker/miles/.MilesSessionInvoker.cpp.swp | Bin 0 -> 16384 bytes .../plugins/invoker/miles/MilesSessionInvoker.cpp | 40 +++++++++++++++++---- 4 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 src/uscxml/plugins/invoker/miles/.MilesSessionInvoker.cpp.swp diff --git a/apps/samples/miles/miles.js b/apps/samples/miles/miles.js index a340e07..1ef1c68 100644 --- a/apps/samples/miles/miles.js +++ b/apps/samples/miles/miles.js @@ -18,9 +18,11 @@ function Miles(element, params) { // private attributes var scxmlURL = "localhost:8080" var reflectorIp = "88.131.107.12" - var email = "user@smartvortex.eu"; + //var email = "user@smartvortex.eu"; + var email = "mathias"; var problemName = "webconfero"; - var remoteEmail = "other@smartvortex.eu"; + //var remoteEmail = "other@smartvortex.eu"; + var remoteEmail = "stefan"; var participants = []; // empty array var videoCompressions = [ @@ -92,10 +94,25 @@ function Miles(element, params) { } this.disconnect = function() { - self.connected = false; - hideChat(); - self.controlDropDown.dropDown.onCancel(true); - self.controlElem.replaceChild(self.connectDropDown.domNode, self.controlDropDown.domNode); + var query = ""; + query += "?reflector=" + encodeURIComponent(reflectorIp); + query += "&userid=" + encodeURIComponent(email); + query += "&session=" + encodeURIComponent(problemName); + + self.xhr.get({ + // The URL to request + url: "http://" + scxmlURL + "/miles/stop" + query, + // handleAs:"text", + error: function(err) { + console.log(err); + }, + load: function(result) { + self.connected = false; + hideChat(); + self.controlDropDown.dropDown.onCancel(true); + self.controlElem.replaceChild(self.connectDropDown.domNode, self.controlDropDown.domNode); + } + }); } var hideChat = function() { diff --git a/apps/samples/miles/miles.scxml b/apps/samples/miles/miles.scxml index 9e486b4..1889ffa 100644 --- a/apps/samples/miles/miles.scxml +++ b/apps/samples/miles/miles.scxml @@ -11,12 +11,14 @@
+
+
@@ -39,7 +41,7 @@ - + @@ -51,6 +53,15 @@ + + + + + + + + + @@ -153,4 +164,4 @@ - \ No newline at end of file + diff --git a/src/uscxml/plugins/invoker/miles/.MilesSessionInvoker.cpp.swp b/src/uscxml/plugins/invoker/miles/.MilesSessionInvoker.cpp.swp new file mode 100644 index 0000000..368f327 Binary files /dev/null and b/src/uscxml/plugins/invoker/miles/.MilesSessionInvoker.cpp.swp differ diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp index d4a709b..5887f8a 100644 --- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp +++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp @@ -201,9 +201,13 @@ void MilesSessionInvoker::send(const SendRequest& req) { void MilesSessionInvoker::processEventStart(const std::string& origin, const std::string& userid, const std::string& reflector, const std::string& session) { + Event ev; + ev.data.compound["origin"] = origin; //std::cout << req; if(_isRunning) { LOG(ERROR) << "already connected"; + ev.name = "start.error"; + returnEvent(ev); return; } @@ -213,6 +217,8 @@ void MilesSessionInvoker::processEventStart(const std::string& origin, const std rv = miles_connect_reflector_session((char*)reflector.c_str(), (char*)session.c_str()); if (!rv) { LOG(ERROR) << "Could not setup reflector session"; + ev.name = "start.error"; + returnEvent(ev); return; } LOG(ERROR) << "session set up"; @@ -271,24 +277,32 @@ void MilesSessionInvoker::processEventStart(const std::string& origin, const std if(audio_available) _audioThread = new tthread::thread(MilesSessionInvoker::runAudio, this); _videoThread = new tthread::thread(MilesSessionInvoker::runVideo, this); - Event ev; ev.name = "start.reply"; - ev.data.compound["origin"] = origin; returnEvent(ev); } void MilesSessionInvoker::processEventStop(const std::string& origin) { + Event ev; + ev.data.compound["origin"] = origin; + + if(!_isRunning) { + LOG(ERROR) << "not connected"; + ev.name = "stop.error"; + returnEvent(ev); + return; + } int rv = miles_disconnect_reflector_session((char*)_reflector.c_str(), (char*)_session.c_str()); if (!rv) { LOG(ERROR) << "Could not disconnect from reflector session"; + ev.name = "stop.error"; + returnEvent(ev); return; } free_media_buffers(); _isRunning = false; - Event ev; ev.name = "stop.reply"; - ev.data.compound["origin"] = origin; returnEvent(ev); + LOG(ERROR) << "disconnected from reflector session"; } void MilesSessionInvoker::processEventParticipants(const std::string& origin) { @@ -308,6 +322,14 @@ void MilesSessionInvoker::processEventParticipants(const std::string& origin) { } void MilesSessionInvoker::processEventThumbnail(const std::string& origin, const std::string& userid) { + Event ev; + ev.data.compound["origin"] = origin; + if(!_isRunning) { + LOG(ERROR) << "not connected"; + ev.name = "thumbnail.error"; + returnEvent(ev); + return; + } LOG(ERROR) << "processEventThumbnail"; URL imageURL("emptyface.jpg"); imageURL.toAbsolute(_interpreter->getBaseURI()); @@ -315,9 +337,7 @@ void MilesSessionInvoker::processEventThumbnail(const std::string& origin, const ssImage << imageURL; std::string imageContent = ssImage.str(); - Event ev; ev.name = "thumbnail.reply"; - ev.data.compound["origin"] = origin; int has_thumb = 0; struct miles_rtp_in_stream *rtps; @@ -406,9 +426,15 @@ void MilesSessionInvoker::processEventPostText(const std::string& origin, const } void MilesSessionInvoker::processEventGetText(const std::string& origin) { Event ev; - ev.name = "gettext.reply"; ev.data.compound["origin"] = origin; + if(!_isRunning) { + LOG(ERROR) << "not connected"; + ev.name = "gettext.error"; + returnEvent(ev); + return; + } + ev.name = "gettext.reply"; 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); -- cgit v0.12 From 0a8628a436dd98ca8cff1c1325298bf04328e997 Mon Sep 17 00:00:00 2001 From: Autobuilder at buildslave-ubuntu-12-32 Date: Wed, 6 Nov 2013 11:14:40 +0100 Subject: sending video/audio enable/disable --- .../plugins/invoker/miles/MilesSessionInvoker.cpp | 23 ++++++++++++++++++---- .../plugins/invoker/miles/MilesSessionInvoker.h | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp index 5887f8a..8343758 100644 --- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp +++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.cpp @@ -247,9 +247,13 @@ void MilesSessionInvoker::processEventStart(const std::string& origin, const std /* Set up video capture */ video_grabber_available = setup_video_grabber(); + if(video_grabber_available) + sendvideo_enabled = 1; /* Set up audio capture/playback */ audio_available = setup_audio(); + if(audio_available) + sendaudio_enabled = 1; /* Set up outgoing RTP stream for video */ if(video_grabber_available) { @@ -308,6 +312,13 @@ void MilesSessionInvoker::processEventStop(const std::string& origin) { void MilesSessionInvoker::processEventParticipants(const std::string& origin) { Event ev; + ev.data.compound["origin"] = origin; + if(!_isRunning) { + LOG(ERROR) << "not connected"; + ev.name = "participants.error"; + returnEvent(ev); + return; + } // create an array with objects inside for (int i = 0; i < 5; i++) { Data userInfo; @@ -317,10 +328,9 @@ void MilesSessionInvoker::processEventParticipants(const std::string& origin) { } ev.name = "participants.reply"; - ev.data.compound["origin"] = origin; returnEvent(ev); - } + void MilesSessionInvoker::processEventThumbnail(const std::string& origin, const std::string& userid) { Event ev; ev.data.compound["origin"] = origin; @@ -398,6 +408,7 @@ void MilesSessionInvoker::processEventSendVideo(const std::string& origin, size_ Event ev; ev.name = "sendvideo.reply"; ev.data.compound["origin"] = origin; + sendvideo_enabled = 1; returnEvent(ev); } void MilesSessionInvoker::processEventSendVideoOff(const std::string& origin) { @@ -405,18 +416,21 @@ void MilesSessionInvoker::processEventSendVideoOff(const std::string& origin) { ev.name = "sendvideooff.reply"; ev.data.compound["origin"] = origin; returnEvent(ev); + sendvideo_enabled = 0; } void MilesSessionInvoker::processEventSendAudio(const std::string& origin, const std::string& encoding) { Event ev; ev.name = "sendaudio.reply"; ev.data.compound["origin"] = origin; returnEvent(ev); + sendaudio_enabled = 1; } void MilesSessionInvoker::processEventSendAudioOff(const std::string& origin) { Event ev; ev.name = "sendaudiooff.reply"; ev.data.compound["origin"] = origin; returnEvent(ev); + sendaudio_enabled = 0; } void MilesSessionInvoker::processEventPostText(const std::string& origin, const std::string& userid, const std::string& message) { Event ev; @@ -454,7 +468,7 @@ void MilesSessionInvoker::runVideo(void* instance) { void MilesSessionInvoker::processVideo() { while(_isRunning) { rtp_video_receiver(video_session); - if(video_grabber_available) + if(video_grabber_available && sendvideo_enabled) video_transmitter(video_grabber, video_encoder, out_rtp_video_stream, out_rtcp_video_stream); } } @@ -462,7 +476,8 @@ void MilesSessionInvoker::processVideo() { void MilesSessionInvoker::processAudio() { while(_isRunning) { rtp_audio_receiver(audio_session); - audio_transmitter(audio_dev, audio_encoder, out_rtp_audio_stream, out_rtcp_audio_stream); + if(audio_available && sendaudio_enabled) + audio_transmitter(audio_dev, audio_encoder, out_rtp_audio_stream, out_rtcp_audio_stream); } } diff --git a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h index 32d4610..efa3ba2 100644 --- a/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h +++ b/src/uscxml/plugins/invoker/miles/MilesSessionInvoker.h @@ -124,6 +124,8 @@ protected: int audio_dev_playback_id; int audio_available; int video_grabber_available; + int sendvideo_enabled; + int sendaudio_enabled; static void runAudio(void* instance); static void runVideo(void* instance); -- cgit v0.12 From c3238c9a5c627491d26ad527f99a08ccfd218c29 Mon Sep 17 00:00:00 2001 From: Autobuilder at buildslave-ubuntu-12-32 Date: Wed, 6 Nov 2013 18:05:37 +0100 Subject: text messaging --- apps/samples/miles/miles.js | 14 ++--- apps/samples/miles/miles.scxml | 10 ++-- .../plugins/invoker/miles/MilesSessionInvoker.cpp | 66 +++++++++++++++++++++- .../plugins/invoker/miles/MilesSessionInvoker.h | 3 + 4 files changed, 78 insertions(+), 15 deletions(-) diff --git a/apps/samples/miles/miles.js b/apps/samples/miles/miles.js index 1ef1c68..4f31d68 100644 --- a/apps/samples/miles/miles.js +++ b/apps/samples/miles/miles.js @@ -12,17 +12,15 @@ function Miles(element, params) { this.connected = false; this.imageIteration = 0; - this.width = 300; - this.height = 200; + this.width = 320; + this.height = 240; // private attributes var scxmlURL = "localhost:8080" var reflectorIp = "88.131.107.12" - //var email = "user@smartvortex.eu"; - var email = "mathias"; + var email = "user@smartvortex.eu"; var problemName = "webconfero"; - //var remoteEmail = "other@smartvortex.eu"; - var remoteEmail = "stefan"; + var remoteEmail = "other@smartvortex.eu"; var participants = []; // empty array var videoCompressions = [ @@ -192,7 +190,7 @@ function Miles(element, params) { }, load: function(result) { if (result.message) { - self.chatOutputElem.innerHTML += stopChatScrolling + " " + Math.random() + ": " + result.message + '
'; + self.chatOutputElem.innerHTML += result.message + '
'; if (!stopChatScrolling) self.chatOutputElem.scrollTop = self.chatOutputElem.scrollHeight; } @@ -299,7 +297,7 @@ function Miles(element, params) { self.chatSendButton = new Button({ label: "Send", onClick: function(){ - alert(self.chatInput.value); + //alert(self.chatInput.value); self.xhr.post({ // The URL to request url: "http://" + scxmlURL + "/miles/text", diff --git a/apps/samples/miles/miles.scxml b/apps/samples/miles/miles.scxml index 1889ffa..22ebdda 100644 --- a/apps/samples/miles/miles.scxml +++ b/apps/samples/miles/miles.scxml @@ -3,7 +3,7 @@ - + @@ -40,8 +40,8 @@
- - + + @@ -144,8 +144,8 @@ - - + + 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' || 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; -- cgit v0.12