|
| 1 | +/* |
| 2 | + * TeleStax, Open Source Cloud Communications |
| 3 | + * Copyright 2011-2015, Telestax Inc and individual contributors |
| 4 | + * by the @authors tag. |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * under the terms of the GNU Affero General Public License as |
| 8 | + * published by the Free Software Foundation; either version 3 of |
| 9 | + * the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU Affero General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Affero General Public License |
| 17 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 18 | + * |
| 19 | + * For questions related to commercial use licensing, please contact sales@telestax.com. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
1 | 23 | package com.telestax.restcomm_helloworld; |
2 | 24 |
|
3 | 25 | //import android.support.v7.app.ActionBarActivity; |
4 | 26 |
|
5 | 27 | import android.Manifest; |
6 | 28 | import android.app.Activity; |
| 29 | +import android.content.ComponentName; |
| 30 | +import android.content.Context; |
7 | 31 | import android.content.Intent; |
| 32 | +import android.content.ServiceConnection; |
8 | 33 | import android.content.pm.PackageManager; |
| 34 | +import android.graphics.drawable.ColorDrawable; |
9 | 35 | import android.opengl.GLSurfaceView; |
10 | 36 | import android.os.Bundle; |
| 37 | +import android.os.IBinder; |
11 | 38 | import android.support.v4.app.ActivityCompat; |
12 | 39 | import android.view.Menu; |
13 | 40 | import android.view.MenuItem; |
|
23 | 50 | import java.util.HashMap; |
24 | 51 | import java.util.ListIterator; |
25 | 52 |
|
26 | | -import org.mobicents.restcomm.android.client.sdk.RCClient; |
27 | | -import org.mobicents.restcomm.android.client.sdk.RCConnection; |
28 | | -import org.mobicents.restcomm.android.client.sdk.RCConnectionListener; |
29 | | -import org.mobicents.restcomm.android.client.sdk.RCDevice; |
30 | | -import org.mobicents.restcomm.android.client.sdk.RCDeviceListener; |
31 | | -import org.mobicents.restcomm.android.client.sdk.RCPresenceEvent; |
| 53 | +import org.restcomm.android.sdk.RCClient; |
| 54 | +import org.restcomm.android.sdk.RCConnection; |
| 55 | +import org.restcomm.android.sdk.RCConnectionListener; |
| 56 | +import org.restcomm.android.sdk.RCDevice; |
| 57 | +import org.restcomm.android.sdk.RCDeviceListener; |
| 58 | +import org.restcomm.android.sdk.RCPresenceEvent; |
32 | 59 | import org.webrtc.VideoRenderer; |
33 | 60 | import org.webrtc.VideoRendererGui; |
34 | 61 | import org.webrtc.VideoTrack; |
35 | 62 |
|
36 | | -public class MainActivity extends Activity implements RCDeviceListener, RCConnectionListener, OnClickListener { |
| 63 | +public class MainActivity extends Activity implements RCDeviceListener, RCConnectionListener, OnClickListener, |
| 64 | + ServiceConnection { |
37 | 65 |
|
38 | 66 | private RCDevice device; |
| 67 | + boolean serviceBound = false; |
| 68 | + |
39 | 69 | private RCConnection connection, pendingConnection; |
40 | 70 | private HashMap<String, Object> params; |
41 | 71 | private static final String TAG = "MainActivity"; |
@@ -71,53 +101,95 @@ protected void onCreate(Bundle savedInstanceState) |
71 | 101 | btnDial.setOnClickListener(this); |
72 | 102 | btnHangup = (Button) findViewById(R.id.button_hangup); |
73 | 103 | btnHangup.setOnClickListener(this); |
| 104 | + } |
74 | 105 |
|
75 | | - // Initialized Restcomm Client SDK entities |
76 | | - RCClient.setLogLevel(Log.VERBOSE); |
77 | | - RCClient.initialize(getApplicationContext(), new RCClient.RCInitListener() { |
78 | | - public void onInitialized() |
79 | | - { |
80 | | - Log.i(TAG, "RCClient initialized"); |
81 | | - } |
| 106 | + @Override |
| 107 | + protected void onStart() |
| 108 | + { |
| 109 | + super.onStart(); |
| 110 | + // The activity is about to become visible. |
| 111 | + Log.i(TAG, "%% onStart"); |
82 | 112 |
|
83 | | - public void onError(Exception exception) |
84 | | - { |
85 | | - Log.e(TAG, "RCClient initialization error"); |
86 | | - } |
87 | | - }); |
| 113 | + bindService(new Intent(this, RCDevice.class), this, Context.BIND_AUTO_CREATE); |
| 114 | + } |
88 | 115 |
|
89 | | - params = new HashMap<String, Object>(); |
90 | | - // update the IP address to your Restcomm instance |
91 | | - params.put(RCDevice.ParameterKeys.SIGNALING_DOMAIN, ""); |
92 | | - params.put(RCDevice.ParameterKeys.SIGNALING_USERNAME, "android-sdk"); |
93 | | - params.put(RCDevice.ParameterKeys.SIGNALING_PASSWORD, "1234"); |
94 | | - params.put(RCDevice.ParameterKeys.MEDIA_ICE_URL, "https://service.xirsys.com/ice"); |
95 | | - params.put(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME, "atsakiridis"); |
96 | | - params.put(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD, "4e89a09e-bf6f-11e5-a15c-69ffdcc2b8a7"); |
97 | | - params.put(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, true); |
98 | | - device = RCClient.createDevice(params, this); |
99 | | - Intent intent = new Intent(getApplicationContext(), MainActivity.class); |
100 | | - // we don't have a separate activity for the calls and messages, so let's use the same intent both for calls and messages |
101 | | - device.setPendingIntents(intent, intent); |
| 116 | + @Override |
| 117 | + protected void onStop() |
| 118 | + { |
| 119 | + super.onStop(); |
| 120 | + // The activity is no longer visible (it is now "stopped") |
| 121 | + Log.i(TAG, "%% onStop"); |
| 122 | + |
| 123 | + // Unbind from the service |
| 124 | + if (serviceBound) { |
| 125 | + //device.detach(); |
| 126 | + unbindService(this); |
| 127 | + serviceBound = false; |
| 128 | + } |
102 | 129 | } |
103 | 130 |
|
| 131 | + |
104 | 132 | @Override |
105 | 133 | protected void onDestroy() |
106 | 134 | { |
107 | 135 | super.onDestroy(); |
108 | 136 | // The activity is about to be destroyed. |
109 | 137 | Log.i(TAG, "%% onDestroy"); |
| 138 | + device.release(); |
| 139 | + /* |
110 | 140 | RCClient.shutdown(); |
111 | 141 | device = null; |
| 142 | + */ |
112 | 143 | } |
113 | 144 |
|
114 | | - /* |
115 | | - private void videoContextReady() |
| 145 | + // Callbacks for service binding, passed to bindService() |
| 146 | + @Override |
| 147 | + public void onServiceConnected(ComponentName className, IBinder service) |
116 | 148 | { |
117 | | - videoReady = true; |
| 149 | + Log.i(TAG, "%% onServiceConnected"); |
| 150 | + // We've bound to LocalService, cast the IBinder and get LocalService instance |
| 151 | + RCDevice.RCDeviceBinder binder = (RCDevice.RCDeviceBinder) service; |
| 152 | + device = binder.getService(); |
| 153 | + |
| 154 | + Intent intent = new Intent(getApplicationContext(), MainActivity.class); |
| 155 | + |
| 156 | + HashMap<String, Object> params = new HashMap<String, Object>(); |
| 157 | + // we don't have a separate activity for the calls and messages, so let's use the same intent both for calls and messages |
| 158 | + params.put(RCDevice.ParameterKeys.INTENT_INCOMING_CALL, intent); |
| 159 | + params.put(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, intent); |
| 160 | + params.put(RCDevice.ParameterKeys.SIGNALING_DOMAIN, ""); |
| 161 | + params.put(RCDevice.ParameterKeys.SIGNALING_USERNAME, "android-sdk"); |
| 162 | + params.put(RCDevice.ParameterKeys.SIGNALING_PASSWORD, "1234"); |
| 163 | + params.put(RCDevice.ParameterKeys.MEDIA_ICE_URL, "https://service.xirsys.com/ice"); |
| 164 | + params.put(RCDevice.ParameterKeys.MEDIA_ICE_USERNAME, "atsakiridis"); |
| 165 | + params.put(RCDevice.ParameterKeys.MEDIA_ICE_PASSWORD, "4e89a09e-bf6f-11e5-a15c-69ffdcc2b8a7"); |
| 166 | + params.put(RCDevice.ParameterKeys.MEDIA_TURN_ENABLED, true); |
| 167 | + //params.put(RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.SIGNALING_SECURE_ENABLED, false)); |
| 168 | + |
| 169 | + // The SDK provides the user with default sounds for calling, ringing, busy (declined) and message, but the user can override them |
| 170 | + // by providing their own resource files (i.e. .wav, .mp3, etc) at res/raw passing them with Resource IDs like R.raw.user_provided_calling_sound |
| 171 | + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_CALLING, R.raw.user_provided_calling_sound); |
| 172 | + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_RINGING, R.raw.user_provided_ringing_sound); |
| 173 | + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_DECLINED, R.raw.user_provided_declined_sound); |
| 174 | + //params.put(RCDevice.ParameterKeys.RESOURCE_SOUND_MESSAGE, R.raw.user_provided_message_sound); |
| 175 | + |
| 176 | + // This is for debugging purposes, not for release builds |
| 177 | + //params.put(RCDevice.ParameterKeys.SIGNALING_JAIN_SIP_LOGGING_ENABLED, prefs.getBoolean(RCDevice.ParameterKeys.SIGNALING_JAIN_SIP_LOGGING_ENABLED, true)); |
| 178 | + |
| 179 | + if (!device.isInitialized()) { |
| 180 | + device.initialize(getApplicationContext(), params, this); |
| 181 | + device.setLogLevel(Log.VERBOSE); |
| 182 | + } |
| 183 | + |
| 184 | + serviceBound = true; |
118 | 185 | } |
119 | | - */ |
120 | 186 |
|
| 187 | + @Override |
| 188 | + public void onServiceDisconnected(ComponentName arg0) |
| 189 | + { |
| 190 | + Log.i(TAG, "%% onServiceDisconnected"); |
| 191 | + serviceBound = false; |
| 192 | + } |
121 | 193 | @Override |
122 | 194 | public boolean onCreateOptionsMenu(Menu menu) |
123 | 195 | { |
|
0 commit comments