3
3
//import android.support.v7.app.ActionBarActivity;
4
4
import android .app .Activity ;
5
5
import android .content .Intent ;
6
+ import android .opengl .GLSurfaceView ;
6
7
import android .os .Bundle ;
7
8
import android .view .Menu ;
8
9
import android .view .MenuItem ;
9
10
import android .view .View ;
10
11
import android .util .Log ;
12
+ import android .view .Window ;
13
+ import android .view .WindowManager ;
11
14
import android .widget .Button ;
12
15
import android .view .View .OnClickListener ;
13
16
import java .util .HashMap ;
18
21
import org .mobicents .restcomm .android .client .sdk .RCDevice ;
19
22
import org .mobicents .restcomm .android .client .sdk .RCDeviceListener ;
20
23
import org .mobicents .restcomm .android .client .sdk .RCPresenceEvent ;
24
+ import org .webrtc .VideoRenderer ;
25
+ import org .webrtc .VideoRendererGui ;
26
+ import org .webrtc .VideoTrack ;
21
27
22
28
public class MainActivity extends Activity implements RCDeviceListener , RCConnectionListener , OnClickListener {
23
29
24
30
private RCDevice device ;
25
31
private RCConnection connection , pendingConnection ;
26
- private HashMap <String , String > params ;
32
+ private HashMap <String , Object > params ;
27
33
private static final String TAG = "MainActivity" ;
28
34
35
+ private GLSurfaceView videoView ;
36
+ private VideoRenderer .Callbacks localRender = null ;
37
+ private VideoRenderer .Callbacks remoteRender = null ;
38
+ private boolean videoReady = false ;
39
+ VideoTrack localVideoTrack , remoteVideoTrack ;
40
+ VideoRenderer localVideoRenderer , remoteVideoRenderer ;
41
+
42
+ // Local preview screen position before call is connected.
43
+ private static final int LOCAL_X_CONNECTING = 0 ;
44
+ private static final int LOCAL_Y_CONNECTING = 0 ;
45
+ private static final int LOCAL_WIDTH_CONNECTING = 100 ;
46
+ private static final int LOCAL_HEIGHT_CONNECTING = 100 ;
47
+ // Local preview screen position after call is connected.
48
+ private static final int LOCAL_X_CONNECTED = 72 ;
49
+ private static final int LOCAL_Y_CONNECTED = 2 ;
50
+ private static final int LOCAL_WIDTH_CONNECTED = 25 ;
51
+ private static final int LOCAL_HEIGHT_CONNECTED = 25 ;
52
+ // Remote video screen position
53
+ private static final int REMOTE_X = 0 ;
54
+ private static final int REMOTE_Y = 0 ;
55
+ private static final int REMOTE_WIDTH = 100 ;
56
+ private static final int REMOTE_HEIGHT = 100 ;
57
+ private VideoRendererGui .ScalingType scalingType ;
58
+
29
59
// UI elements
30
60
Button btnDial ;
31
61
Button btnHangup ;
32
62
33
63
@ Override
34
64
protected void onCreate (Bundle savedInstanceState ) {
35
65
super .onCreate (savedInstanceState );
66
+ // Set window styles for fullscreen-window size. Needs to be done before
67
+ // adding content.
68
+ requestWindowFeature (Window .FEATURE_NO_TITLE );
69
+ getWindow ().addFlags (
70
+ WindowManager .LayoutParams .FLAG_FULLSCREEN
71
+ | WindowManager .LayoutParams .FLAG_KEEP_SCREEN_ON
72
+ | WindowManager .LayoutParams .FLAG_DISMISS_KEYGUARD
73
+ | WindowManager .LayoutParams .FLAG_SHOW_WHEN_LOCKED
74
+ | WindowManager .LayoutParams .FLAG_TURN_SCREEN_ON );
75
+ getWindow ().getDecorView ().setSystemUiVisibility (
76
+ View .SYSTEM_UI_FLAG_HIDE_NAVIGATION
77
+ | View .SYSTEM_UI_FLAG_FULLSCREEN
78
+ | View .SYSTEM_UI_FLAG_IMMERSIVE_STICKY );
79
+
36
80
setContentView (R .layout .activity_main );
37
81
38
82
// initialize UI
@@ -41,36 +85,57 @@ protected void onCreate(Bundle savedInstanceState) {
41
85
btnHangup = (Button )findViewById (R .id .button_hangup );
42
86
btnHangup .setOnClickListener (this );
43
87
44
- RCClient .initialize (getApplicationContext (), new RCClient .RCInitListener ()
45
- {
46
- public void onInitialized ()
47
- {
88
+ RCClient .initialize (getApplicationContext (), new RCClient .RCInitListener () {
89
+ public void onInitialized () {
48
90
Log .i (TAG , "RCClient initialized" );
49
-
50
91
}
51
92
52
- public void onError (Exception exception )
53
- {
93
+ public void onError (Exception exception ) {
54
94
Log .e (TAG , "RCClient initialization error" );
55
95
}
56
96
});
57
97
58
- // TODO: we don't support capability tokens yet so let's use an empty string
59
- device = RCClient .createDevice ("" , this );
98
+ params = new HashMap <String , Object >();
99
+ // CHANGEME: update the IP address to your Restcomm instance
100
+ params .put ("pref_proxy_ip" , "23.23.228.238" );
101
+ params .put ("pref_proxy_port" , "5080" );
102
+ params .put ("pref_sip_user" , "bob" );
103
+ params .put ("pref_sip_password" , "1234" );
104
+ device = RCClient .createDevice (params , this );
60
105
Intent intent = new Intent (getApplicationContext (), MainActivity .class );
61
106
// we don't have a separate activity for the calls, so use the same intent both for calls and messages
62
107
device .setPendingIntents (intent , intent );
63
108
64
- connection = null ;
109
+ // Setup video stuff
110
+ scalingType = VideoRendererGui .ScalingType .SCALE_ASPECT_FILL ;
111
+ videoView = (GLSurfaceView ) findViewById (R .id .glview_call );
112
+ // Create video renderers.
113
+ VideoRendererGui .setView (videoView , new Runnable () {
114
+ @ Override
115
+ public void run () {
116
+ videoContextReady ();
117
+ }
118
+ });
119
+ remoteRender = VideoRendererGui .create (
120
+ REMOTE_X , REMOTE_Y ,
121
+ REMOTE_WIDTH , REMOTE_HEIGHT , scalingType , false );
122
+ localRender = VideoRendererGui .create (
123
+ LOCAL_X_CONNECTING , LOCAL_Y_CONNECTING ,
124
+ LOCAL_WIDTH_CONNECTING , LOCAL_HEIGHT_CONNECTING , scalingType , true );
125
+ }
65
126
66
- params = new HashMap <String , String >();
67
- // CHANGEME: update the IP address to your Restcomm instance
68
- params .put ("pref_proxy_ip" , "54.225.212.193" );
69
- params .put ("pref_proxy_port" , "5080" );
70
- params .put ("pref_sip_user" , "bob" );
71
- params .put ("pref_sip_password" , "1234" );
72
- // register on startup
73
- device .updateParams (params );
127
+ @ Override
128
+ protected void onDestroy () {
129
+ super .onDestroy ();
130
+ // The activity is about to be destroyed.
131
+ Log .i (TAG , "%% onDestroy" );
132
+ RCClient .shutdown ();
133
+ device = null ;
134
+ }
135
+
136
+ private void videoContextReady ()
137
+ {
138
+ videoReady = true ;
74
139
}
75
140
76
141
@ Override
@@ -106,7 +171,8 @@ public void onClick(View view) {
106
171
HashMap <String , Object > connectParams = new HashMap <String , Object >();
107
172
// CHANGEME: update the IP address to your Restcomm instance. Also, you can update the number
108
173
// from '1235' to any Restcomm application you wish to reach
109
- connectParams .
put (
"username" ,
"sip:[email protected] :5080" );
174
+ connectParams .
put (
"username" ,
"sip:[email protected] :5080" );
175
+ connectParams .put ("video-enabled" , true );
110
176
111
177
// if you want to add custom SIP headers, please uncomment this
112
178
//HashMap<String, String> sipHeaders = new HashMap<>();
@@ -194,6 +260,22 @@ public void onDisconnected(RCConnection connection)
194
260
Log .i (TAG , "RCConnection disconnected" );
195
261
this .connection = null ;
196
262
pendingConnection = null ;
263
+
264
+ // reside local renderer to take up all screen now that the call is over
265
+ VideoRendererGui .update (localRender ,
266
+ LOCAL_X_CONNECTING , LOCAL_Y_CONNECTING ,
267
+ LOCAL_WIDTH_CONNECTING , LOCAL_HEIGHT_CONNECTING , scalingType , true );
268
+
269
+ if (localVideoTrack != null ) {
270
+
271
+ localVideoTrack .removeRenderer (localVideoRenderer );
272
+ localVideoTrack = null ;
273
+ }
274
+
275
+ if (remoteVideoTrack != null ) {
276
+ remoteVideoTrack .removeRenderer (remoteVideoRenderer );
277
+ remoteVideoTrack = null ;
278
+ }
197
279
}
198
280
199
281
public void onDisconnected (RCConnection connection , int errorCode , String errorText ) {
@@ -214,6 +296,34 @@ public void onDeclined(RCConnection connection) {
214
296
this .connection = null ;
215
297
pendingConnection = null ;
216
298
}
299
+ public void onReceiveLocalVideo (RCConnection connection , VideoTrack videoTrack ) {
300
+ Log .v (TAG , "onReceiveLocalVideo(), VideoTrack: " + videoTrack );
301
+ if (videoTrack != null ) {
302
+ //show media on screen
303
+ videoTrack .setEnabled (true );
304
+ localVideoRenderer = new VideoRenderer (localRender );
305
+ videoTrack .addRenderer (localVideoRenderer );
306
+ localVideoTrack = videoTrack ;
307
+ }
308
+ }
217
309
218
-
310
+ public void onReceiveRemoteVideo (RCConnection connection , VideoTrack videoTrack ) {
311
+ Log .v (TAG , "onReceiveRemoteVideo(), VideoTrack: " + videoTrack );
312
+ if (videoTrack != null ) {
313
+ //show media on screen
314
+ videoTrack .setEnabled (true );
315
+ remoteVideoRenderer = new VideoRenderer (remoteRender );
316
+ videoTrack .addRenderer (remoteVideoRenderer );
317
+
318
+ VideoRendererGui .update (remoteRender ,
319
+ REMOTE_X , REMOTE_Y ,
320
+ REMOTE_WIDTH , REMOTE_HEIGHT , scalingType , false );
321
+ VideoRendererGui .update (localRender ,
322
+ LOCAL_X_CONNECTED , LOCAL_Y_CONNECTED ,
323
+ LOCAL_WIDTH_CONNECTED , LOCAL_HEIGHT_CONNECTED ,
324
+ VideoRendererGui .ScalingType .SCALE_ASPECT_FIT , true );
325
+
326
+ remoteVideoTrack = videoTrack ;
327
+ }
328
+ }
219
329
}
0 commit comments