1 /*
2  *  Copyright 2013 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 package org.appspot.apprtc;
12 
13 import org.webrtc.IceCandidate;
14 import org.webrtc.PeerConnection;
15 import org.webrtc.SessionDescription;
16 
17 import java.util.List;
18 
19 /**
20  * AppRTCClient is the interface representing an AppRTC client.
21  */
22 public interface AppRTCClient {
23 
24   /**
25    * Struct holding the connection parameters of an AppRTC room.
26    */
27   public static class RoomConnectionParameters {
28     public final String roomUrl;
29     public final String roomId;
30     public final boolean loopback;
RoomConnectionParameters( String roomUrl, String roomId, boolean loopback)31     public RoomConnectionParameters(
32         String roomUrl, String roomId, boolean loopback) {
33       this.roomUrl = roomUrl;
34       this.roomId = roomId;
35       this.loopback = loopback;
36     }
37   }
38 
39   /**
40    * Asynchronously connect to an AppRTC room URL using supplied connection
41    * parameters. Once connection is established onConnectedToRoom()
42    * callback with room parameters is invoked.
43    */
connectToRoom(RoomConnectionParameters connectionParameters)44   public void connectToRoom(RoomConnectionParameters connectionParameters);
45 
46   /**
47    * Send offer SDP to the other participant.
48    */
sendOfferSdp(final SessionDescription sdp)49   public void sendOfferSdp(final SessionDescription sdp);
50 
51   /**
52    * Send answer SDP to the other participant.
53    */
sendAnswerSdp(final SessionDescription sdp)54   public void sendAnswerSdp(final SessionDescription sdp);
55 
56   /**
57    * Send Ice candidate to the other participant.
58    */
sendLocalIceCandidate(final IceCandidate candidate)59   public void sendLocalIceCandidate(final IceCandidate candidate);
60 
61   /**
62    * Disconnect from room.
63    */
disconnectFromRoom()64   public void disconnectFromRoom();
65 
66   /**
67    * Struct holding the signaling parameters of an AppRTC room.
68    */
69   public static class SignalingParameters {
70     public final List<PeerConnection.IceServer> iceServers;
71     public final boolean initiator;
72     public final String clientId;
73     public final String wssUrl;
74     public final String wssPostUrl;
75     public final SessionDescription offerSdp;
76     public final List<IceCandidate> iceCandidates;
77 
SignalingParameters( List<PeerConnection.IceServer> iceServers, boolean initiator, String clientId, String wssUrl, String wssPostUrl, SessionDescription offerSdp, List<IceCandidate> iceCandidates)78     public SignalingParameters(
79         List<PeerConnection.IceServer> iceServers,
80         boolean initiator, String clientId,
81         String wssUrl, String wssPostUrl,
82         SessionDescription offerSdp, List<IceCandidate> iceCandidates) {
83       this.iceServers = iceServers;
84       this.initiator = initiator;
85       this.clientId = clientId;
86       this.wssUrl = wssUrl;
87       this.wssPostUrl = wssPostUrl;
88       this.offerSdp = offerSdp;
89       this.iceCandidates = iceCandidates;
90     }
91   }
92 
93   /**
94    * Callback interface for messages delivered on signaling channel.
95    *
96    * <p>Methods are guaranteed to be invoked on the UI thread of |activity|.
97    */
98   public static interface SignalingEvents {
99     /**
100      * Callback fired once the room's signaling parameters
101      * SignalingParameters are extracted.
102      */
onConnectedToRoom(final SignalingParameters params)103     public void onConnectedToRoom(final SignalingParameters params);
104 
105     /**
106      * Callback fired once remote SDP is received.
107      */
onRemoteDescription(final SessionDescription sdp)108     public void onRemoteDescription(final SessionDescription sdp);
109 
110     /**
111      * Callback fired once remote Ice candidate is received.
112      */
onRemoteIceCandidate(final IceCandidate candidate)113     public void onRemoteIceCandidate(final IceCandidate candidate);
114 
115     /**
116      * Callback fired once channel is closed.
117      */
onChannelClose()118     public void onChannelClose();
119 
120     /**
121      * Callback fired once channel error happened.
122      */
onChannelError(final String description)123     public void onChannelError(final String description);
124   }
125 }
126