Forge Acision 是国外的一家做即时通讯的机构,旗下产品包括:短消息服务、消息推送、音视频对话等,官网https://www.xura.com/,提供客户端sdk,包括android、iphone、浏览器javascript相关SDK,另外提供企业自建业务平台的对接sdk叫forge as api,这个sdk用于企业自建业务平台对接forge云平台服务,forge提供公共云服务平台,用于登陆认证、信令交换、打洞服务。主要还是基于webrtc作为架构核心进行的二次研发的产物。
下面对于他的产品我做一下android端的使用介绍:
使用其产品需要再进官网申请一个apikey,用来让云服务识别连接身份。
2、下载android sdk http://releases.sdk.xura.com/latest/acisionsdk-android.zip
3、打开android studio新建工程,导入sdk包中的 aar 文件
4、修改AndroidManifest.xml文件,其中加入
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
5、假设启动文件是MainActivity
在MainActivity中加入
import android.util.Log; import android.widget.TextView; import com.acision.acisionsdk.AcisionSdk; import com.acision.acisionsdk.AcisionSdkCallbacks; import com.acision.acisionsdk.AcisionSdkConfiguration; import com.acision.acisionsdk.authentication.AuthenticationFailureData;
private static final String TAG = "com.acision.acisionsdkdemo";
private AcisionSdk forgeClient;
@Override protected void onStart() { Log.w(TAG, "onStart"); AcisionSdkConfiguration config = new AcisionSdkConfiguration("APIKEY", "USERNAME", "PASSWORD", this.getApplication());//连接云服务器 config.setPersistent(true); forgeClient = new AcisionSdk(config, new AcisionSdkCallbacks() { @Override public void onAuthenticationFailure(AcisionSdk forgeClient, AuthenticationFailureData data) //连接失败回调 { Log.w(TAG, "Application has got an onAuthenticationFailure callback"); TextView textElement = (TextView) findViewById(R.id.hello); textElement.setText("forge authentication failed. check your config."); } @Override public void onConnected(AcisionSdk forgeClient) //连接成功回调 { Log.d(TAG, "Application has got an onConnected callback"); TextView textElement = (TextView) findViewById(R.id.hello);//修改text textElement.setText("Hello forge"); } }); super.onStart(); }其中APIKEY是你在官网注册的apikey,USERNAME、PASSWORD为测试用户名密码,此处forge提供第三方认证,比如facebook,youtube,inline,what'sapp等登陆认证,当然国外不支持微信、QQ、微博等认证。也支持自有服务器认证,自有服务器认证的流程是,登陆用户名和密码先提交云服务平台,然后云服务平台再调用你提供的自由服务器登陆接口进行认证。官网为了方便测试,提供了从test00~test99的测试用户名,密码和用户名一致。
6,我们用test00/test00作为用户名/密码登陆云服务平台,启动app,进行连接
7、实时对话,修改onConnected回调函数
@Override public void onConnected(AcisionSdk forgeClient) { Log.d(TAG, "Application has got an onConnected callback"); callbacks.onConnected(); ourName = forgeClient.getAddress(); ourName = ourName.substring(0, ourName.indexOf("@")); messaging = forgeClient.getMessaging(); messaging.setCallbacks(new MessagingReceiveCallbacks() { @Override public void onMessageReceived(Messaging messaging, MessagingReceivedMessage message) { Log.d(TAG, "Message received "); if (receiver != null) { receiver.receiveMessage(message.getFrom(), message.getContent(), message.getSubmitted()); } } }); }8、定义发送函数
public void sendToDestination(final String to, final String message, final MessageStateCallbacks callbacks) { MessagingSendOptions options = new MessagingSendOptions(); messaging.sendToDestination(to, message, options, new MessagingSendCallbacks() { @Override public void onMessagingAcknowledged(Messaging messaging, String MsgId, Date submitted) { Log.d(TAG, "Application got acknowledgement of message sent"); } @Override public void onMessagingError(Messaging messaging, String code, String message) { Log.w(TAG, "Application failed to send message"); } }); }