16
16
import android .util .DisplayMetrics ;
17
17
import android .util .Log ;
18
18
import android .view .WindowManager ;
19
- import android .widget .GridLayout ;
20
19
import android .widget .Toast ;
21
20
22
21
import androidx .annotation .NonNull ;
64
63
import org .webrtc .audio .JavaAudioDeviceModule ;
65
64
66
65
import java .nio .ByteBuffer ;
66
+ import java .nio .charset .StandardCharsets ;
67
67
import java .util .ArrayList ;
68
68
import java .util .Arrays ;
69
69
import java .util .Collections ;
86
86
import io .antmedia .webrtcandroidframework .apprtc .AppRTCAudioManager ;
87
87
import io .antmedia .webrtcandroidframework .websocket .AntMediaSignallingEvents ;
88
88
import io .antmedia .webrtcandroidframework .websocket .Broadcast ;
89
+ import io .antmedia .webrtcandroidframework .websocket .WebSocketConstants ;
89
90
import io .antmedia .webrtcandroidframework .websocket .WebSocketHandler ;
90
91
91
92
public class WebRTCClient implements IWebRTCClient , AntMediaSignallingEvents {
@@ -1576,6 +1577,7 @@ public void onJoinedTheRoom(String streamId, String[] streams) {
1576
1577
config .webRTCListener .onJoinedTheRoom (streamId , streams );
1577
1578
}
1578
1579
1580
+
1579
1581
@ Override
1580
1582
public void onRoomInformation (String [] streams ) {
1581
1583
config .webRTCListener .onRoomInformation (streams );
@@ -1787,6 +1789,11 @@ public void onStateChange() {
1787
1789
}
1788
1790
});
1789
1791
}
1792
+ protected String toTextMessage (DataChannel .Buffer buffer ) {
1793
+ ByteBuffer data = buffer .data ;
1794
+ String messageText = new String (data .array (), StandardCharsets .UTF_8 );
1795
+ return messageText ;
1796
+ }
1790
1797
1791
1798
@ Override
1792
1799
public void onMessage (final DataChannel .Buffer buffer ) {
@@ -1799,6 +1806,7 @@ public void onMessage(final DataChannel.Buffer buffer) {
1799
1806
handler .post (() -> {
1800
1807
if (config .dataChannelObserver == null || dataChannel == null ) return ;
1801
1808
try {
1809
+ handleNotification (toTextMessage (bufferCopy ));
1802
1810
config .dataChannelObserver .onMessage (bufferCopy , dataChannel .label ());
1803
1811
}catch (IllegalStateException e ) {
1804
1812
Log .e (TAG , "Data channel related error:" + e .getMessage ());
@@ -1807,6 +1815,37 @@ public void onMessage(final DataChannel.Buffer buffer) {
1807
1815
}
1808
1816
}
1809
1817
1818
+ public void handleNotification (String message ) {
1819
+ if (message == null || !message .contains ("eventType" ))
1820
+ return ;
1821
+
1822
+ JSONObject jsonMessage ;
1823
+ String streamId ;
1824
+ String eventTyp ;
1825
+
1826
+ try {
1827
+ jsonMessage = new JSONObject (message );
1828
+ streamId = jsonMessage .getString (WebSocketConstants .STREAM_ID );
1829
+ eventTyp = jsonMessage .getString ("eventType" );
1830
+ } catch (Exception e ) {
1831
+ return ;
1832
+ }
1833
+
1834
+ switch (eventTyp ) {
1835
+ case WebSocketConstants .CAM_TURNED_OFF :
1836
+ config .webRTCListener .onCameraTurnOffFor (streamId );
1837
+ break ;
1838
+ case WebSocketConstants .CAM_TURNED_ON :
1839
+ config .webRTCListener .onCameraTurnOnFor (streamId );
1840
+ break ;
1841
+ case WebSocketConstants .MIC_MUTED :
1842
+ config .webRTCListener .onMutedFor (streamId );
1843
+ break ;
1844
+ case WebSocketConstants .MIC_UNMUTED :
1845
+ config .webRTCListener .onUnmutedFor (streamId );
1846
+ }
1847
+ }
1848
+
1810
1849
public void sendMessageViaDataChannel (String streamId , DataChannel .Buffer buffer ) {
1811
1850
if (isDataChannelEnabled ()) {
1812
1851
executor .execute (() -> {
0 commit comments