From bdb56d48846d16323dde1506f986a86f294cc220 Mon Sep 17 00:00:00 2001
From: Anton Georgiev <anto.georgiev@gmail.com>
Date: Thu, 18 Jun 2015 22:07:15 +0000
Subject: [PATCH] FS video share/view messages from fs to bbb-apps

---
 akka-bbb-apps/build.sbt                       |  2 +-
 .../receivers/DeskShareMessageReceiver.java   | 48 ++++++++++++++
 .../receivers/RedisMessageReceiver.java       |  5 +-
 akka-bbb-fsesl/build.sbt                      |  2 +-
 .../FreeswitchConferenceEventListener.java    | 30 ++++++++-
 .../voice/IVoiceConferenceService.java        |  4 ++
 .../voice/events/DeskShareEndedEvent.java     | 39 ++++++++++++
 .../voice/events/DeskShareStartedEvent.java   | 39 ++++++++++++
 .../events/DeskShareViewerJoinedEvent.java    | 39 ++++++++++++
 .../events/DeskShareViewerLeftEvent.java      | 39 ++++++++++++
 .../voice/freeswitch/ESLEventListener.java    | 61 ++++++++++++++----
 .../freeswitch/VoiceConferenceService.scala   | 24 +++++++
 bbb-common-message/build.sbt                  |  2 +-
 .../messages/DeskShareEndedEventMessage.java  | 63 +++++++++++++++++++
 .../DeskShareStartedEventMessage.java         | 63 +++++++++++++++++++
 .../DeskShareViewerJoinedEventMessage.java    | 63 +++++++++++++++++++
 .../DeskShareViewerLeftEventMessage.java      | 63 +++++++++++++++++++
 17 files changed, 568 insertions(+), 18 deletions(-)
 create mode 100644 akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/DeskShareMessageReceiver.java
 create mode 100644 akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareEndedEvent.java
 create mode 100644 akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareStartedEvent.java
 create mode 100644 akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerJoinedEvent.java
 create mode 100644 akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerLeftEvent.java
 create mode 100644 bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareEndedEventMessage.java
 create mode 100644 bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareStartedEventMessage.java
 create mode 100644 bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerJoinedEventMessage.java
 create mode 100644 bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerLeftEventMessage.java

diff --git a/akka-bbb-apps/build.sbt b/akka-bbb-apps/build.sbt
index b5474a81bb..54e0936b73 100755
--- a/akka-bbb-apps/build.sbt
+++ b/akka-bbb-apps/build.sbt
@@ -50,7 +50,7 @@ libraryDependencies ++= {
 	  "com.google.code.gson"      %  "gson"              % "1.7.1",
 	  "redis.clients"             %  "jedis"             % "2.1.0",
       "org.apache.commons"        %  "commons-lang3"     % "3.2",
-      "org.bigbluebutton"         %  "bbb-common-message" % "0.0.4"
+      "org.bigbluebutton"         %  "bbb-common-message" % "0.0.5-SNAPSHOT"
 	)}
 
 
diff --git a/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/DeskShareMessageReceiver.java b/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/DeskShareMessageReceiver.java
new file mode 100644
index 0000000000..5b09b921ee
--- /dev/null
+++ b/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/DeskShareMessageReceiver.java
@@ -0,0 +1,48 @@
+package org.bigbluebutton.core.pubsub.receivers;
+
+import com.google.gson.JsonParser;
+import com.google.gson.JsonObject;
+
+import org.bigbluebutton.common.messages.DeskShareStartedEventMessage;
+import org.bigbluebutton.common.messages.DeskShareEndedEventMessage;
+import org.bigbluebutton.common.messages.DeskShareViewerJoinedEventMessage;
+import org.bigbluebutton.common.messages.DeskShareViewerLeftEventMessage;
+import org.bigbluebutton.common.messages.MessagingConstants;
+import org.bigbluebutton.core.api.IBigBlueButtonInGW;
+
+public class DeskShareMessageReceiver implements MessageHandler {
+
+	private IBigBlueButtonInGW bbbGW;
+	
+	public DeskShareMessageReceiver(IBigBlueButtonInGW bbbGW) {
+		this.bbbGW = bbbGW;
+	}
+
+	@Override
+	public void handleMessage(String pattern, String channel, String message) {
+		if (channel.equalsIgnoreCase(MessagingConstants.FROM_VOICE_CONF_SYSTEM_CHAN)) {
+			JsonParser parser = new JsonParser();
+			JsonObject obj = (JsonObject) parser.parse(message);
+			if (obj.has("header") && obj.has("payload")) {
+				JsonObject header = (JsonObject) obj.get("header");
+				if (header.has("name")) {
+					String messageName = header.get("name").getAsString();
+
+					if (DeskShareStartedEventMessage.DESK_SHARE_STARTED_MESSAGE.equals(messageName)) {
+						DeskShareStartedEventMessage msg = DeskShareStartedEventMessage.fromJson(message);
+//						// TODO
+					} else if (DeskShareEndedEventMessage.DESK_SHARE_ENDED_MESSAGE.equals(messageName)) {
+						DeskShareEndedEventMessage msg = DeskShareEndedEventMessage.fromJson(message);
+//						// TODO
+					} else if (DeskShareViewerJoinedEventMessage.DESK_SHARE_VIEWER_JOINED_MESSAGE.equals(messageName)) {
+						DeskShareViewerJoinedEventMessage msg = DeskShareViewerJoinedEventMessage.fromJson(message);
+//						// TODO
+					} else if (DeskShareViewerLeftEventMessage.DESK_SHARE_VIEWER_LEFT_MESSAGE.equals(messageName)) {
+						DeskShareViewerLeftEventMessage msg = DeskShareViewerLeftEventMessage.fromJson(message);
+//						// TODO
+					}
+				}
+			}
+		}
+	}
+}
diff --git a/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/RedisMessageReceiver.java b/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/RedisMessageReceiver.java
index 0e6eeb5c4b..457b12769c 100755
--- a/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/RedisMessageReceiver.java
+++ b/akka-bbb-apps/src/main/java/org/bigbluebutton/core/pubsub/receivers/RedisMessageReceiver.java
@@ -30,7 +30,10 @@ public class RedisMessageReceiver {
 				
 		WhiteboardMessageReceiver whiteboardRx = new WhiteboardMessageReceiver(bbbGW);
 		receivers.add(whiteboardRx);
-		
+
+		DeskShareMessageReceiver deskShareRx = new DeskShareMessageReceiver(bbbGW);
+		receivers.add(deskShareRx);
+
 		MeetingMessageReceiver meetingRx = new MeetingMessageReceiver(bbbGW);
 		receivers.add(meetingRx);
 	}
diff --git a/akka-bbb-fsesl/build.sbt b/akka-bbb-fsesl/build.sbt
index 81333704a3..da14959a85 100755
--- a/akka-bbb-fsesl/build.sbt
+++ b/akka-bbb-fsesl/build.sbt
@@ -50,7 +50,7 @@ libraryDependencies ++= {
 	  "com.google.code.gson"      %  "gson"              % "1.7.1",
 	  "redis.clients"             %  "jedis"             % "2.1.0",
       "org.apache.commons"        %  "commons-lang3"     % "3.2",
-      "org.bigbluebutton"         %  "bbb-common-message" % "0.0.4",
+      "org.bigbluebutton"         %  "bbb-common-message" % "0.0.5-SNAPSHOT",
       "org.bigbluebutton"         %  "bbb-fsesl-client"   % "0.0.2"
 	)}
 
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java
index 69326c4956..ab304cbec3 100755
--- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/FreeswitchConferenceEventListener.java
@@ -24,7 +24,11 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
+import org.bigbluebutton.freeswitch.voice.events.DeskShareStartedEvent;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareEndedEvent;
 import org.bigbluebutton.freeswitch.voice.events.ConferenceEventListener;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareViewerJoinedEvent;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareViewerLeftEvent;
 import org.bigbluebutton.freeswitch.voice.events.VoiceConferenceEvent;
 import org.bigbluebutton.freeswitch.voice.events.VoiceStartRecordingEvent;
 import org.bigbluebutton.freeswitch.voice.events.VoiceUserJoinedEvent;
@@ -78,7 +82,27 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene
 					VoiceStartRecordingEvent evt = (VoiceStartRecordingEvent) event;
 					System.out.println("************** FreeswitchConferenceEventListener VoiceStartRecordingEvent recording=[" + evt.startRecord() + "]");
 					vcs.voiceConfRecordingStarted(evt.getRoom(), evt.getRecordingFilename(), evt.startRecord(), evt.getTimestamp());
-				} 				
+				} else if (event instanceof DeskShareStartedEvent) {
+//					System.out.println("********START******\n\n\n\n\n\n\n FreeswitchConferenceEventListener ");
+					DeskShareStartedEvent evt = (DeskShareStartedEvent) event;
+					System.out.println("************** FreeswitchConferenceEventListener DeskShareStartedEvent");
+					vcs.deskShareStarted(evt.getRoom(), evt.getCallerIdNum(), evt.getCallerIdName());
+				} else if (event instanceof DeskShareEndedEvent) {
+//					System.out.println("********END******\n\n\n\n\n FreeswitchConferenceEventListener ");
+					DeskShareEndedEvent evt = (DeskShareEndedEvent) event;
+					System.out.println("************** FreeswitchConferenceEventListener DeskShareEndedEvent");
+					vcs.deskShareEnded(evt.getRoom(), evt.getCallerIdNum(), evt.getCallerIdName());
+				} else if (event instanceof DeskShareViewerJoinedEvent) {
+//					System.out.println("********VIEWER JOINED******\n\n\n\n\n FreeswitchConferenceEventListener ");
+					DeskShareViewerJoinedEvent evt = (DeskShareViewerJoinedEvent) event;
+					System.out.println("************** FreeswitchConferenceEventListener DeskShareViewerJoinedEvent");
+					vcs.deskShareViewerJoined(evt.getRoom(), evt.getCallerIdNum(), evt.getCallerIdName());
+				} else if (event instanceof DeskShareViewerLeftEvent) {
+//					System.out.println("********VIEWER LEFT******\n\n\n\n\n FreeswitchConferenceEventListener ");
+					DeskShareViewerLeftEvent evt = (DeskShareViewerLeftEvent) event;
+					System.out.println("************** FreeswitchConferenceEventListener DeskShareViewerLeftEvent");
+					vcs.deskShareViewerLeft(evt.getRoom(), evt.getCallerIdNum(), evt.getCallerIdName());
+				}
 			}
 		};
 		
@@ -97,7 +121,7 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene
 					} catch (InterruptedException e) {
 						// TODO Auto-generated catch block
 						e.printStackTrace();
-					}									
+					}
 				}
 			}
 		};
@@ -111,5 +135,5 @@ public class FreeswitchConferenceEventListener implements ConferenceEventListene
 	public void handleConferenceEvent(VoiceConferenceEvent event) {
 		queueMessage(event);
 	}
-	
+
 }
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/IVoiceConferenceService.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/IVoiceConferenceService.java
index 6bf57784ff..0709740d67 100755
--- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/IVoiceConferenceService.java
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/IVoiceConferenceService.java
@@ -8,5 +8,9 @@ public interface IVoiceConferenceService {
 	void userLockedInVoiceConf(String voiceConfId, String voiceUserId, Boolean locked);
 	void userMutedInVoiceConf(String voiceConfId, String voiceUserId, Boolean muted);
 	void userTalkingInVoiceConf(String voiceConfId, String voiceUserId, Boolean talking);
+	void deskShareStarted(String voiceConfId, String callerIdNum, String callerIdName);
+	void deskShareEnded(String voiceConfId, String callerIdNum, String callerIdName);
+	void deskShareViewerJoined(String voiceConfId, String callerIdNum, String callerIdName);
+	void deskShareViewerLeft(String voiceConfId, String callerIdNum, String callerIdName);
 
 }
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareEndedEvent.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareEndedEvent.java
new file mode 100644
index 0000000000..ea5e543e8e
--- /dev/null
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareEndedEvent.java
@@ -0,0 +1,39 @@
+/**
+* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
+* 
+* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below).
+*
+* This program is free software; you can redistribute it and/or modify it under the
+* terms of the GNU Lesser General Public License as published by the Free Software
+* Foundation; either version 3.0 of the License, or (at your option) any later
+* version.
+* 
+* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
+* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License along
+* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.bigbluebutton.freeswitch.voice.events;
+
+public class DeskShareEndedEvent extends VoiceConferenceEvent {
+
+	private final String callerIdNum;
+	private final String callerIdName;
+	
+	public DeskShareEndedEvent(String room, String callerIdNum, String callerIdName) {
+		super(room);
+		this.callerIdName = callerIdName;
+		this.callerIdNum = callerIdNum;
+	}
+
+	public String getCallerIdNum() {
+		return callerIdNum;
+	}
+
+	public String getCallerIdName() {
+		return callerIdName;
+	}
+}
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareStartedEvent.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareStartedEvent.java
new file mode 100644
index 0000000000..9cb325ca8d
--- /dev/null
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareStartedEvent.java
@@ -0,0 +1,39 @@
+/**
+* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
+* 
+* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below).
+*
+* This program is free software; you can redistribute it and/or modify it under the
+* terms of the GNU Lesser General Public License as published by the Free Software
+* Foundation; either version 3.0 of the License, or (at your option) any later
+* version.
+* 
+* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
+* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License along
+* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.bigbluebutton.freeswitch.voice.events;
+
+public class DeskShareStartedEvent extends VoiceConferenceEvent {
+
+	private final String callerIdNum;
+	private final String callerIdName;
+	
+	public DeskShareStartedEvent(String room, String callerIdNum, String callerIdName) {
+		super(room);
+		this.callerIdName = callerIdName;
+		this.callerIdNum = callerIdNum;
+	}
+
+	public String getCallerIdNum() {
+		return callerIdNum;
+	}
+
+	public String getCallerIdName() {
+		return callerIdName;
+	}
+}
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerJoinedEvent.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerJoinedEvent.java
new file mode 100644
index 0000000000..aa4b593a20
--- /dev/null
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerJoinedEvent.java
@@ -0,0 +1,39 @@
+/**
+* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
+* 
+* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below).
+*
+* This program is free software; you can redistribute it and/or modify it under the
+* terms of the GNU Lesser General Public License as published by the Free Software
+* Foundation; either version 3.0 of the License, or (at your option) any later
+* version.
+* 
+* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
+* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License along
+* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.bigbluebutton.freeswitch.voice.events;
+
+public class DeskShareViewerJoinedEvent extends VoiceConferenceEvent {
+
+	private final String callerIdNum;
+	private final String callerIdName;
+	
+	public DeskShareViewerJoinedEvent(String room, String callerIdNum, String callerIdName) {
+		super(room);
+		this.callerIdName = callerIdName;
+		this.callerIdNum = callerIdNum;
+	}
+
+	public String getCallerIdNum() {
+		return callerIdNum;
+	}
+
+	public String getCallerIdName() {
+		return callerIdName;
+	}
+}
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerLeftEvent.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerLeftEvent.java
new file mode 100644
index 0000000000..79b34f517d
--- /dev/null
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/events/DeskShareViewerLeftEvent.java
@@ -0,0 +1,39 @@
+/**
+* BigBlueButton open source conferencing system - http://www.bigbluebutton.org/
+* 
+* Copyright (c) 2015 BigBlueButton Inc. and by respective authors (see below).
+*
+* This program is free software; you can redistribute it and/or modify it under the
+* terms of the GNU Lesser General Public License as published by the Free Software
+* Foundation; either version 3.0 of the License, or (at your option) any later
+* version.
+* 
+* BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
+* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License along
+* with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
+*
+*/
+package org.bigbluebutton.freeswitch.voice.events;
+
+public class DeskShareViewerLeftEvent extends VoiceConferenceEvent {
+
+	private final String callerIdNum;
+	private final String callerIdName;
+	
+	public DeskShareViewerLeftEvent(String room, String callerIdNum, String callerIdName) {
+		super(room);
+		this.callerIdName = callerIdName;
+		this.callerIdNum = callerIdNum;
+	}
+
+	public String getCallerIdNum() {
+		return callerIdNum;
+	}
+
+	public String getCallerIdName() {
+		return callerIdName;
+	}
+}
diff --git a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java
index 7e6c2b4a34..40acb8f9bd 100755
--- a/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java
+++ b/akka-bbb-fsesl/src/main/java/org/bigbluebutton/freeswitch/voice/freeswitch/ESLEventListener.java
@@ -7,6 +7,10 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.bigbluebutton.freeswitch.voice.events.ConferenceEventListener;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareEndedEvent;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareStartedEvent;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareViewerJoinedEvent;
+import org.bigbluebutton.freeswitch.voice.events.DeskShareViewerLeftEvent;
 import org.bigbluebutton.freeswitch.voice.events.VoiceStartRecordingEvent;
 import org.bigbluebutton.freeswitch.voice.events.VoiceUserJoinedEvent;
 import org.bigbluebutton.freeswitch.voice.events.VoiceUserLeftEvent;
@@ -22,7 +26,11 @@ public class ESLEventListener implements IEslEventListener {
     private static final String STOP_TALKING_EVENT = "stop-talking";
     private static final String START_RECORDING_EVENT = "start-recording";
     private static final String STOP_RECORDING_EVENT = "stop-recording";
-    
+
+    private static final String DESKSHARE_CONFERENCE_NAME_LABEL = "-DESKSHARE";
+    private static final String DESKSHARE_CALLER_NAME_LABEL = " (Screen)";
+    private static final String DESKSHARE_CALLER_ID_LABEL = " (screen)";
+
     private final ConferenceEventListener conferenceEventListener;
     
     public ESLEventListener(ConferenceEventListener conferenceEventListener) {
@@ -50,7 +58,7 @@ public class ESLEventListener implements IEslEventListener {
     
     @Override
     public void conferenceEventJoin(String uniqueId, String confName, int confSize, EslEvent event) {
-    	
+
         Integer memberId = this.getMemberIdFromEvent(event);
         Map<String, String> headers = event.getEventHeaders();
         String callerId = this.getCallerIdFromEvent(event);
@@ -59,21 +67,35 @@ public class ESLEventListener implements IEslEventListener {
         boolean speaking = headers.get("Talking").equals("true") ? true : false;
 
         String voiceUserId = callerIdName;
-        
+
         System.out.println("User joined voice conference, user=[" + callerIdName + "], conf=[" + confName + "]");
-        
+
         Matcher gapMatcher = GLOBAL_AUDION_PATTERN.matcher(callerIdName);
         if (gapMatcher.matches()) {
         	System.out.println("Ignoring GLOBAL AUDIO USER [" + callerIdName + "]");
         	return;
         }
-        		
-		    Matcher matcher = CALLERNAME_PATTERN.matcher(callerIdName);
-		    if (matcher.matches()) {			
-			    voiceUserId = matcher.group(1).trim();
-			    callerIdName = matcher.group(2).trim();
-		    } 
-        
+
+        // Deskstop sharing conferences have their name in the form xxxxx-DESKSHARE
+        if (confName.endsWith(DESKSHARE_CONFERENCE_NAME_LABEL)) {
+            // Deskstop sharing conferences have the user with the desktop video displayed in this way:
+            // username (Screen) and usernum (screen)
+            if (callerId.endsWith(DESKSHARE_CALLER_ID_LABEL) && callerIdName.endsWith(DESKSHARE_CALLER_NAME_LABEL)) {
+                DeskShareStartedEvent dsStart = new DeskShareStartedEvent(confName, callerId, callerIdName);
+                conferenceEventListener.handleConferenceEvent(dsStart);
+                return; //TODO do we need it?
+            } else {
+                DeskShareViewerJoinedEvent dsJoined = new DeskShareViewerJoinedEvent(confName, callerId, callerIdName);
+                conferenceEventListener.handleConferenceEvent(dsJoined);
+        	}
+        }
+
+        Matcher matcher = CALLERNAME_PATTERN.matcher(callerIdName);
+        if (matcher.matches()) {
+            voiceUserId = matcher.group(1).trim();
+            callerIdName = matcher.group(2).trim();
+        }
+
         VoiceUserJoinedEvent pj = new VoiceUserJoinedEvent(voiceUserId, memberId.toString(), confName, callerId, callerIdName, muted, speaking);
         conferenceEventListener.handleConferenceEvent(pj);
     }
@@ -82,6 +104,23 @@ public class ESLEventListener implements IEslEventListener {
     public void conferenceEventLeave(String uniqueId, String confName, int confSize, EslEvent event) {   	
         Integer memberId = this.getMemberIdFromEvent(event);
         System.out.println("User left voice conference, user=[" + memberId.toString() + "], conf=[" + confName + "]");
+
+        // Deskstop sharing conferences have their name in the form xxxxx-DESKSHARE
+        if (confName.endsWith(DESKSHARE_CONFERENCE_NAME_LABEL)) {
+            String callerId = this.getCallerIdFromEvent(event);
+            String callerIdName = this.getCallerIdNameFromEvent(event);
+            // Deskstop sharing conferences have the user with the desktop video displayed in this way:
+            // username (Screen) and usernum (screen)
+            if (callerId.endsWith(DESKSHARE_CALLER_ID_LABEL) && callerIdName.endsWith(DESKSHARE_CALLER_NAME_LABEL)) {
+                DeskShareEndedEvent dsEnd = new DeskShareEndedEvent(confName, callerId, callerIdName);
+                conferenceEventListener.handleConferenceEvent(dsEnd);
+                return;//TODO do we need it?
+            } else {
+                DeskShareViewerLeftEvent dsLeft = new DeskShareViewerLeftEvent(confName, callerId, callerIdName);
+                conferenceEventListener.handleConferenceEvent(dsLeft);
+            }
+        }
+
         VoiceUserLeftEvent pl = new VoiceUserLeftEvent(memberId.toString(), confName);
         conferenceEventListener.handleConferenceEvent(pl);
     }
diff --git a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/VoiceConferenceService.scala b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/VoiceConferenceService.scala
index f7a44b7159..7d859e62fd 100755
--- a/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/VoiceConferenceService.scala
+++ b/akka-bbb-fsesl/src/main/scala/org/bigbluebutton/freeswitch/VoiceConferenceService.scala
@@ -41,4 +41,28 @@ class VoiceConferenceService(sender: RedisPublisher) extends IVoiceConferenceSer
     val msg = new UserTalkingInVoiceConfMessage(voiceConfId, voiceUserId, talking)
     sender.publish(FROM_VOICE_CONF_SYSTEM_CHAN, msg.toJson())
   }
+
+  def deskShareStarted(voiceConfId: String, callerIdNum: String, callerIdName: String) {
+    println("******** FreeswitchConferenceService received deskShareStarted")
+    val msg = new DeskShareStartedEventMessage(voiceConfId, callerIdNum, callerIdName)
+    sender.publish(FROM_VOICE_CONF_SYSTEM_CHAN, msg.toJson())
+  }
+
+  def deskShareEnded(voiceConfId: String, callerIdNum: String, callerIdName: String) {
+    println("******** FreeswitchConferenceService received deskShareEnded")
+    val msg = new DeskShareEndedEventMessage(voiceConfId, callerIdNum, callerIdName)
+    sender.publish(FROM_VOICE_CONF_SYSTEM_CHAN, msg.toJson())
+  }
+
+  def deskShareViewerJoined(voiceConfId: String, callerIdNum: String, callerIdName: String) {
+    println("******** FreeswitchConferenceService received deskShareViewerJoined")
+    val msg = new DeskShareViewerJoinedEventMessage(voiceConfId, callerIdNum, callerIdName)
+    sender.publish(FROM_VOICE_CONF_SYSTEM_CHAN, msg.toJson())
+  }
+
+  def deskShareViewerLeft(voiceConfId: String, callerIdNum: String, callerIdName: String) {
+    println("******** FreeswitchConferenceService received deskShareViewerLeft")
+    val msg = new DeskShareViewerLeftEventMessage(voiceConfId, callerIdNum, callerIdName)
+    sender.publish(FROM_VOICE_CONF_SYSTEM_CHAN, msg.toJson())
+  }
 }
\ No newline at end of file
diff --git a/bbb-common-message/build.sbt b/bbb-common-message/build.sbt
index bed53efe10..911d8b1a5e 100755
--- a/bbb-common-message/build.sbt
+++ b/bbb-common-message/build.sbt
@@ -4,7 +4,7 @@ name := "bbb-common-message"
 
 organization := "org.bigbluebutton"
 
-version := "0.0.4"
+version := "0.0.5-SNAPSHOT"
 
 // We want to have our jar files in lib_managed dir.
 // This way we'll have the right path when we import
diff --git a/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareEndedEventMessage.java b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareEndedEventMessage.java
new file mode 100644
index 0000000000..3ef7b3b7d9
--- /dev/null
+++ b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareEndedEventMessage.java
@@ -0,0 +1,63 @@
+package org.bigbluebutton.common.messages;
+
+import java.util.HashMap;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+
+public class DeskShareEndedEventMessage {
+	public static final String DESK_SHARE_ENDED_MESSAGE  = "desk_share_ended_message";
+	public static final String VERSION = "0.0.1";
+
+	public static final String CONFERENCE_NAME = "conference_name";
+	public static final String CALLER_ID = "caller_id";
+	public static final String CALLER_ID_NAME = "caller_id_name";
+
+	public final String conferenceName;
+	public final String callerId;
+	public final String callerIdName;
+
+	public DeskShareEndedEventMessage(String conferenceName, String callerId, String callerIdName) {
+		this.conferenceName = conferenceName;
+		this.callerId = callerId;
+		this.callerIdName = callerIdName;
+	}
+
+	public String toJson() {
+		HashMap<String, Object> payload = new HashMap<String, Object>();
+		payload.put(CONFERENCE_NAME, conferenceName);
+		payload.put(CALLER_ID_NAME, callerIdName);
+		payload.put(CALLER_ID, callerId);
+
+		java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(DESK_SHARE_ENDED_MESSAGE, VERSION, null);
+
+		return MessageBuilder.buildJson(header, payload);
+	}
+
+	public static DeskShareEndedEventMessage fromJson(String message) {
+		JsonParser parser = new JsonParser();
+		JsonObject obj = (JsonObject) parser.parse(message);
+
+		if (obj.has("header") && obj.has("payload")) {
+			JsonObject header = (JsonObject) obj.get("header");
+			JsonObject payload = (JsonObject) obj.get("payload");
+
+			if (header.has("name")) {
+				String messageName = header.get("name").getAsString();
+				if (DESK_SHARE_ENDED_MESSAGE.equals(messageName)) {
+					if (payload.has(CONFERENCE_NAME)
+							&& payload.has(CALLER_ID)
+							&& payload.has(CALLER_ID_NAME)) {
+						String conferenceName = payload.get(CONFERENCE_NAME).getAsString();
+						String callerId = payload.get(CALLER_ID_NAME).getAsString();
+						String callerIdName = payload.get(CALLER_ID_NAME).getAsString();
+
+						return new DeskShareEndedEventMessage(conferenceName, callerId, callerIdName);
+					}
+				}
+			}
+		}
+		return null;
+
+	}
+}
diff --git a/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareStartedEventMessage.java b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareStartedEventMessage.java
new file mode 100644
index 0000000000..bbd9898176
--- /dev/null
+++ b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareStartedEventMessage.java
@@ -0,0 +1,63 @@
+package org.bigbluebutton.common.messages;
+
+import java.util.HashMap;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+
+public class DeskShareStartedEventMessage {
+	public static final String DESK_SHARE_STARTED_MESSAGE  = "desk_share_started_message";
+	public static final String VERSION = "0.0.1";
+
+	public static final String CONFERENCE_NAME = "conference_name";
+	public static final String CALLER_ID = "caller_id";
+	public static final String CALLER_ID_NAME = "caller_id_name";
+
+	public final String conferenceName;
+	public final String callerId;
+	public final String callerIdName;
+
+	public DeskShareStartedEventMessage(String conferenceName, String callerId, String callerIdName) {
+		this.conferenceName = conferenceName;
+		this.callerId = callerId;
+		this.callerIdName = callerIdName;
+	}
+
+	public String toJson() {
+		HashMap<String, Object> payload = new HashMap<String, Object>();
+		payload.put(CONFERENCE_NAME, conferenceName);
+		payload.put(CALLER_ID_NAME, callerIdName);
+		payload.put(CALLER_ID, callerId);
+
+		java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(DESK_SHARE_STARTED_MESSAGE, VERSION, null);
+
+		return MessageBuilder.buildJson(header, payload);
+	}
+
+	public static DeskShareStartedEventMessage fromJson(String message) {
+		JsonParser parser = new JsonParser();
+		JsonObject obj = (JsonObject) parser.parse(message);
+
+		if (obj.has("header") && obj.has("payload")) {
+			JsonObject header = (JsonObject) obj.get("header");
+			JsonObject payload = (JsonObject) obj.get("payload");
+
+			if (header.has("name")) {
+				String messageName = header.get("name").getAsString();
+				if (DESK_SHARE_STARTED_MESSAGE.equals(messageName)) {
+					if (payload.has(CONFERENCE_NAME)
+							&& payload.has(CALLER_ID)
+							&& payload.has(CALLER_ID_NAME)) {
+						String conferenceName = payload.get(CONFERENCE_NAME).getAsString();
+						String callerId = payload.get(CALLER_ID_NAME).getAsString();
+						String callerIdName = payload.get(CALLER_ID_NAME).getAsString();
+
+						return new DeskShareStartedEventMessage(conferenceName, callerId, callerIdName);
+					}
+				}
+			}
+		}
+		return null;
+
+	}
+}
diff --git a/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerJoinedEventMessage.java b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerJoinedEventMessage.java
new file mode 100644
index 0000000000..afddd976a1
--- /dev/null
+++ b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerJoinedEventMessage.java
@@ -0,0 +1,63 @@
+package org.bigbluebutton.common.messages;
+
+import java.util.HashMap;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+
+public class DeskShareViewerJoinedEventMessage {
+	public static final String DESK_SHARE_VIEWER_JOINED_MESSAGE = "desk_share_viewer_joined_message";
+	public static final String VERSION = "0.0.1";
+
+	public static final String CONFERENCE_NAME = "conference_name";
+	public static final String CALLER_ID = "caller_id";
+	public static final String CALLER_ID_NAME = "caller_id_name";
+
+	public final String conferenceName;
+	public final String callerId;
+	public final String callerIdName;
+
+	public DeskShareViewerJoinedEventMessage(String conferenceName, String callerId, String callerIdName) {
+		this.conferenceName = conferenceName;
+		this.callerId = callerId;
+		this.callerIdName = callerIdName;
+	}
+
+	public String toJson() {
+		HashMap<String, Object> payload = new HashMap<String, Object>();
+		payload.put(CONFERENCE_NAME, conferenceName);
+		payload.put(CALLER_ID_NAME, callerIdName);
+		payload.put(CALLER_ID, callerId);
+
+		java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(DESK_SHARE_VIEWER_JOINED_MESSAGE, VERSION, null);
+
+		return MessageBuilder.buildJson(header, payload);
+	}
+
+	public static DeskShareViewerJoinedEventMessage fromJson(String message) {
+		JsonParser parser = new JsonParser();
+		JsonObject obj = (JsonObject) parser.parse(message);
+
+		if (obj.has("header") && obj.has("payload")) {
+			JsonObject header = (JsonObject) obj.get("header");
+			JsonObject payload = (JsonObject) obj.get("payload");
+
+			if (header.has("name")) {
+				String messageName = header.get("name").getAsString();
+				if (DESK_SHARE_VIEWER_JOINED_MESSAGE.equals(messageName)) {
+					if (payload.has(CONFERENCE_NAME)
+							&& payload.has(CALLER_ID)
+							&& payload.has(CALLER_ID_NAME)) {
+						String conferenceName = payload.get(CONFERENCE_NAME).getAsString();
+						String callerId = payload.get(CALLER_ID_NAME).getAsString();
+						String callerIdName = payload.get(CALLER_ID_NAME).getAsString();
+
+						return new DeskShareViewerJoinedEventMessage(conferenceName, callerId, callerIdName);
+					}
+				}
+			}
+		}
+		return null;
+
+	}
+}
diff --git a/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerLeftEventMessage.java b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerLeftEventMessage.java
new file mode 100644
index 0000000000..7df5217ef3
--- /dev/null
+++ b/bbb-common-message/src/main/java/org/bigbluebutton/common/messages/DeskShareViewerLeftEventMessage.java
@@ -0,0 +1,63 @@
+package org.bigbluebutton.common.messages;
+
+import java.util.HashMap;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+
+public class DeskShareViewerLeftEventMessage {
+	public static final String DESK_SHARE_VIEWER_LEFT_MESSAGE = "desk_share_viewer_left_message";
+	public static final String VERSION = "0.0.1";
+
+	public static final String CONFERENCE_NAME = "conference_name";
+	public static final String CALLER_ID = "caller_id";
+	public static final String CALLER_ID_NAME = "caller_id_name";
+
+	public final String conferenceName;
+	public final String callerId;
+	public final String callerIdName;
+
+	public DeskShareViewerLeftEventMessage(String conferenceName, String callerId, String callerIdName) {
+		this.conferenceName = conferenceName;
+		this.callerId = callerId;
+		this.callerIdName = callerIdName;
+	}
+
+	public String toJson() {
+		HashMap<String, Object> payload = new HashMap<String, Object>();
+		payload.put(CONFERENCE_NAME, conferenceName);
+		payload.put(CALLER_ID_NAME, callerIdName);
+		payload.put(CALLER_ID, callerId);
+
+		java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(DESK_SHARE_VIEWER_LEFT_MESSAGE, VERSION, null);
+
+		return MessageBuilder.buildJson(header, payload);
+	}
+
+	public static DeskShareViewerLeftEventMessage fromJson(String message) {
+		JsonParser parser = new JsonParser();
+		JsonObject obj = (JsonObject) parser.parse(message);
+
+		if (obj.has("header") && obj.has("payload")) {
+			JsonObject header = (JsonObject) obj.get("header");
+			JsonObject payload = (JsonObject) obj.get("payload");
+
+			if (header.has("name")) {
+				String messageName = header.get("name").getAsString();
+				if (DESK_SHARE_VIEWER_LEFT_MESSAGE.equals(messageName)) {
+					if (payload.has(CONFERENCE_NAME)
+							&& payload.has(CALLER_ID)
+							&& payload.has(CALLER_ID_NAME)) {
+						String conferenceName = payload.get(CONFERENCE_NAME).getAsString();
+						String callerId = payload.get(CALLER_ID_NAME).getAsString();
+						String callerIdName = payload.get(CALLER_ID_NAME).getAsString();
+
+						return new DeskShareViewerLeftEventMessage(conferenceName, callerId, callerIdName);
+					}
+				}
+			}
+		}
+		return null;
+
+	}
+}
-- 
GitLab