daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jun 7th, 2017 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.jadefrh.nightylogin;
  2.  
  3. import android.content.Intent;
  4. import android.content.SharedPreferences;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7.  
  8. import com.quickblox.auth.QBAuth;
  9. import com.quickblox.auth.session.QBSession;
  10. import com.quickblox.auth.session.QBSettings;
  11. import com.quickblox.chat.QBChatService;
  12. import com.quickblox.chat.QBSignaling;
  13. import com.quickblox.chat.QBWebRTCSignaling;
  14. import com.quickblox.chat.listeners.QBVideoChatSignalingManagerListener;
  15. import com.quickblox.core.QBEntityCallback;
  16. import com.quickblox.core.exception.QBResponseException;
  17. import com.quickblox.users.model.QBUser;
  18. import com.quickblox.videochat.webrtc.QBRTCAudioTrack;
  19. import com.quickblox.videochat.webrtc.QBRTCClient;
  20. import com.quickblox.videochat.webrtc.QBRTCMediaConfig;
  21. import com.quickblox.videochat.webrtc.QBRTCSession;
  22. import com.quickblox.videochat.webrtc.QBRTCTypes;
  23. import com.quickblox.videochat.webrtc.callbacks.QBRTCClientAudioTracksCallback;
  24. import com.quickblox.videochat.webrtc.callbacks.QBRTCClientSessionCallbacks;
  25. import com.quickblox.videochat.webrtc.callbacks.QBRTCClientVideoTracksCallbacks;
  26. import com.quickblox.videochat.webrtc.callbacks.QBRTCSessionConnectionCallbacks;
  27. import com.quickblox.videochat.webrtc.callbacks.QBRTCSessionEventsCallback;
  28. import com.quickblox.videochat.webrtc.exception.QBRTCException;
  29. import com.quickblox.videochat.webrtc.view.QBRTCSurfaceView;
  30. import com.quickblox.videochat.webrtc.view.QBRTCVideoTrack;
  31.  
  32. import org.webrtc.EglBase;
  33. import org.webrtc.VideoRenderer;
  34.  
  35. import java.util.ArrayList;
  36. import java.util.HashMap;
  37. import java.util.List;
  38. import java.util.Map;
  39.  
  40. import static com.jadefrh.nightylogin.InitActivity.MY_PREFS_NAME;
  41. import static com.quickblox.videochat.webrtc.QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO;
  42.  
  43. public class VideoActivity extends AppCompatActivity implements QBRTCClientSessionCallbacks, QBRTCSessionConnectionCallbacks, QBRTCClientVideoTracksCallbacks, QBRTCClientAudioTracksCallback {
  44.  
  45.     private String qbLogin;
  46.     private String qbPassword = "Fa8grOp89bKgi76gFPsm";
  47.  
  48.     static final String APP_ID = "57763";
  49.     static final String AUTH_KEY = "FAd4zvhKvsALGwD";
  50.     static final String AUTH_SECRET = "f2DFnCfrkcmvepE";
  51.     static final String ACCOUNT_KEY = "RyqpYix2Y54TzqeSACQs";
  52.  
  53.     private QBRTCClient rtcClient;
  54.     private QBRTCSurfaceView surfaceView;
  55.  
  56.     private Integer quickblox_id;
  57.  
  58.     @Override
  59.     protected void onCreate(Bundle savedInstanceState) {
  60.         super.onCreate(savedInstanceState);
  61.         setContentView(R.layout.activity_video);
  62.  
  63.         Intent i = getIntent();
  64.         quickblox_id = i.getIntExtra("quickblox_id", 0);
  65.         Integer user_id = i.getIntExtra("user_id", 0);
  66.         Integer call_max_duration = i.getIntExtra("call_max_duration", 0);
  67.         Integer call_ring_duration = i.getIntExtra("call_ring_duration", 0);
  68.         Integer call_delay_interaction = i.getIntExtra("call_delay_interaction", 0);
  69.  
  70.         System.out.println("quickblox : " + quickblox_id);
  71.  
  72.         SharedPreferences prefs = this.getSharedPreferences(MY_PREFS_NAME, this.MODE_PRIVATE);
  73.         qbLogin = prefs.getString("user_email", null);
  74.  
  75.         System.out.println("LOGIN WITH: " + qbLogin);
  76.         System.out.println("LOGIN WITH: " + qbPassword);
  77.  
  78.         QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
  79.         QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
  80.  
  81. //        surfaceView = (QBRTCSurfaceView) findViewById(R.id.localView);
  82. //        EglBase eglContext = QBRTCClient.getInstance(this).getEglContext();
  83. //        surfaceView.init(eglContext.getEglBaseContext(), null);
  84.  
  85.         final QBUser user = new QBUser(qbLogin, qbPassword);
  86.  
  87.         // CREATE SESSION WITH USER
  88.         // If you use create session with user data,
  89.         // then the user will be logged in automatically
  90.         QBAuth.createSession(user).performAsync(new QBEntityCallback<QBSession>() {
  91.             @Override
  92.             public void onSuccess(QBSession session, Bundle bundle) {
  93.  
  94.                 System.out.println("VIDEO: CREATESESSION ONSUCCESS");
  95.  
  96.                 user.setId(session.getUserId());
  97.                 // INIT CHAT SERVICE
  98.                 QBChatService chatService = QBChatService.getInstance();
  99.  
  100. //                // LOG IN CHAT SERVICE
  101.                 chatService.login(user, new QBEntityCallback<QBUser>() {
  102.  
  103.                     @Override
  104.                     public void onSuccess(QBUser qbUser, Bundle bundle) {
  105.                         //success
  106.                         initQBRTCClient();
  107.                     }
  108.  
  109.                     @Override
  110.                     public void onError(QBResponseException errors) {
  111.                         //error
  112.                     }
  113.                 });
  114.             }
  115.  
  116.             @Override
  117.             public void onError(QBResponseException errors) {
  118.                 //error
  119.                 System.out.println("VIDEO: CREATESESSION ONERROR");
  120.             }
  121.         });
  122.  
  123.         //initQBRTCClient();
  124.  
  125.     }
  126.  
  127.     private void initQBRTCClient() {
  128.         rtcClient = QBRTCClient.getInstance(this);
  129.  
  130.         System.out.println("VIDEO: INIT QBRTCCLIENT");
  131.         QBChatService.getInstance().getVideoChatWebRTCSignalingManager()
  132.                 .addSignalingManagerListener(new QBVideoChatSignalingManagerListener() {
  133.                     @Override
  134.                     public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
  135.  
  136.                         System.out.println("VIDEO: ADDSIGNALMANAGERTRUC");
  137.  
  138.                         if (!createdLocally) {
  139.                             rtcClient.addSignaling((QBWebRTCSignaling) qbSignaling);
  140.                         }
  141.                     }
  142.                 });
  143.  
  144.         rtcClient.prepareToProcessCalls();
  145.         rtcClient.addSessionCallbacksListener(VideoActivity.this);
  146.  
  147.         QBRTCTypes.QBConferenceType qbConferenceType = QB_CONFERENCE_TYPE_VIDEO;
  148.  
  149.         // Initiate opponents list
  150.         List<Integer> opponents = new ArrayList<Integer>();
  151.         opponents.add(quickblox_id); //12345 - QBUser ID
  152.  
  153.         // Set user information
  154.         // User can set any string key and value in user info
  155.         // Then retrieve this data from sessions which is returned in callbacks
  156.         // and parse them as he wish
  157.         Map<String, String> userInfo = new HashMap<>();
  158.         userInfo.put("key", "value");
  159.  
  160.         // Init session
  161.         QBRTCSession session = QBRTCClient.getInstance(VideoActivity.this).createNewSessionWithOpponents(opponents, qbConferenceType);
  162.  
  163.         // Start call
  164.         session.startCall(userInfo);
  165.  
  166.         System.out.println("ON VA APPELER L'UTILISATEUR #" + quickblox_id);
  167.  
  168.     }
  169.  
  170.     private void fillVideoView(int userId, QBRTCSurfaceView videoView, QBRTCVideoTrack videoTrack,
  171.                                boolean remoteRenderer) {
  172.         videoTrack.addRenderer(new VideoRenderer(videoView));
  173.     }
  174.  
  175.     @Override
  176.     public void onLocalVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack) {
  177.         System.out.println("VIDEO: onLocalVideoTrackReceive()");
  178.     }
  179.  
  180.     @Override
  181.     public void onRemoteVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack, Integer integer) {
  182.         System.out.println("VIDEO: onRemoteVideoTrackReceive()");
  183.     }
  184.  
  185.     @Override
  186.     public void onStartConnectToUser(QBRTCSession qbrtcSession, Integer integer) {
  187.         System.out.println("VIDEO: onStartConnectToUser()");
  188.     }
  189.  
  190.     @Override
  191.     public void onConnectedToUser(QBRTCSession qbrtcSession, Integer integer) {
  192.         System.out.println("VIDEO: onConnectedToUser()");
  193.     }
  194.  
  195.     @Override
  196.     public void onConnectionClosedForUser(QBRTCSession qbrtcSession, Integer integer) {
  197.         System.out.println("VIDEO: onConnectionClosedForUser()");
  198.     }
  199.  
  200.     @Override
  201.     public void onDisconnectedFromUser(QBRTCSession qbrtcSession, Integer integer) {
  202.         System.out.println("VIDEO: onDisconnectedFromUser()");
  203.     }
  204.  
  205.     @Override
  206.     public void onDisconnectedTimeoutFromUser(QBRTCSession qbrtcSession, Integer integer) {
  207.         System.out.println("VIDEO: onDisconnectedTimeoutFromUser()");
  208.     }
  209.  
  210.     @Override
  211.     public void onConnectionFailedWithUser(QBRTCSession qbrtcSession, Integer integer) {
  212.         System.out.println("VIDEO: onConnectionFailedWithUser()");
  213.     }
  214.  
  215.     @Override
  216.     public void onError(QBRTCSession qbrtcSession, QBRTCException e) {
  217.         System.out.println("VIDEO: onError()");
  218.     }
  219.  
  220.     @Override
  221.     public void onLocalAudioTrackReceive(QBRTCSession qbrtcSession, QBRTCAudioTrack qbrtcAudioTrack) {
  222.         System.out.println("VIDEO: onLocalAudioTrackReceive()");
  223.     }
  224.  
  225.     @Override
  226.     public void onRemoteAudioTrackReceive(QBRTCSession qbrtcSession, QBRTCAudioTrack qbrtcAudioTrack, Integer integer) {
  227.         System.out.println("VIDEO: onRemoteAudioTrackReceive()");
  228.     }
  229.  
  230.     @Override
  231.     public void onUserNotAnswer(QBRTCSession qbrtcSession, Integer integer) {
  232.         System.out.println("VIDEO: onUserNotAnswer()");
  233.     }
  234.  
  235.     @Override
  236.     public void onCallRejectByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
  237.         System.out.println("VIDEO: onCallRejectByUser()");
  238.     }
  239.  
  240.     @Override
  241.     public void onCallAcceptByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
  242.         System.out.println("VIDEO: onCallAcceptByUser()");
  243.     }
  244.  
  245.     @Override
  246.     public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
  247.         System.out.println("VIDEO: onReceiveHangUpFromUser()");
  248.     }
  249.  
  250.     @Override
  251.     public void onSessionClosed(QBRTCSession qbrtcSession) {
  252.         System.out.println("VIDEO: onSessionClosed()");
  253.     }
  254.  
  255.     @Override
  256.     public void onReceiveNewSession(QBRTCSession qbrtcSession) {
  257.         System.out.println("VIDEO: onReceiveNewSession()");
  258.         System.out.println("ON EST EN TRAIN DE T'APPELER MON POTE");
  259.  
  260.         // obtain received user info
  261. //        Map<String,String> userInfo = qbrtcSession.getUserInfo();
  262.  
  263.         // .....
  264.         // ..... your code
  265.         // .....
  266.  
  267.  
  268.         // Set userInfo
  269.         // User can set any string key and value in user info
  270.         Map<String,String> userInfo = new HashMap<String,String>();
  271.         userInfo.put("Key", "Value");
  272.  
  273.         // Accept incoming call
  274.         qbrtcSession.acceptCall(userInfo);
  275.     }
  276.  
  277.     @Override
  278.     public void onUserNoActions(QBRTCSession qbrtcSession, Integer integer) {
  279.         System.out.println("VIDEO: onUserNoActions()");
  280.     }
  281.  
  282.     @Override
  283.     public void onSessionStartClose(QBRTCSession qbrtcSession) {
  284.         System.out.println("VIDEO: onSessionStartClose()");
  285.     }
  286. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top