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 * Struct holding the connection parameters of an AppRTC room. 25 */ 26 class RoomConnectionParameters { 27 public final String roomUrl; 28 public final String roomId; 29 public final boolean loopback; 30 public final String urlParameters; RoomConnectionParameters( String roomUrl, String roomId, boolean loopback, String urlParameters)31 public RoomConnectionParameters( 32 String roomUrl, String roomId, boolean loopback, String urlParameters) { 33 this.roomUrl = roomUrl; 34 this.roomId = roomId; 35 this.loopback = loopback; 36 this.urlParameters = urlParameters; 37 } RoomConnectionParameters(String roomUrl, String roomId, boolean loopback)38 public RoomConnectionParameters(String roomUrl, String roomId, boolean loopback) { 39 this(roomUrl, roomId, loopback, null /* urlParameters */); 40 } 41 } 42 43 /** 44 * Asynchronously connect to an AppRTC room URL using supplied connection 45 * parameters. Once connection is established onConnectedToRoom() 46 * callback with room parameters is invoked. 47 */ connectToRoom(RoomConnectionParameters connectionParameters)48 void connectToRoom(RoomConnectionParameters connectionParameters); 49 50 /** 51 * Send offer SDP to the other participant. 52 */ sendOfferSdp(final SessionDescription sdp)53 void sendOfferSdp(final SessionDescription sdp); 54 55 /** 56 * Send answer SDP to the other participant. 57 */ sendAnswerSdp(final SessionDescription sdp)58 void sendAnswerSdp(final SessionDescription sdp); 59 60 /** 61 * Send Ice candidate to the other participant. 62 */ sendLocalIceCandidate(final IceCandidate candidate)63 void sendLocalIceCandidate(final IceCandidate candidate); 64 65 /** 66 * Send removed ICE candidates to the other participant. 67 */ sendLocalIceCandidateRemovals(final IceCandidate[] candidates)68 void sendLocalIceCandidateRemovals(final IceCandidate[] candidates); 69 70 /** 71 * Disconnect from room. 72 */ disconnectFromRoom()73 void disconnectFromRoom(); 74 75 /** 76 * Struct holding the signaling parameters of an AppRTC room. 77 */ 78 class SignalingParameters { 79 public final List<PeerConnection.IceServer> iceServers; 80 public final boolean initiator; 81 public final String clientId; 82 public final String wssUrl; 83 public final String wssPostUrl; 84 public final SessionDescription offerSdp; 85 public final List<IceCandidate> iceCandidates; 86 SignalingParameters(List<PeerConnection.IceServer> iceServers, boolean initiator, String clientId, String wssUrl, String wssPostUrl, SessionDescription offerSdp, List<IceCandidate> iceCandidates)87 public SignalingParameters(List<PeerConnection.IceServer> iceServers, boolean initiator, 88 String clientId, String wssUrl, String wssPostUrl, SessionDescription offerSdp, 89 List<IceCandidate> iceCandidates) { 90 this.iceServers = iceServers; 91 this.initiator = initiator; 92 this.clientId = clientId; 93 this.wssUrl = wssUrl; 94 this.wssPostUrl = wssPostUrl; 95 this.offerSdp = offerSdp; 96 this.iceCandidates = iceCandidates; 97 } 98 } 99 100 /** 101 * Callback interface for messages delivered on signaling channel. 102 * 103 * <p>Methods are guaranteed to be invoked on the UI thread of |activity|. 104 */ 105 interface SignalingEvents { 106 /** 107 * Callback fired once the room's signaling parameters 108 * SignalingParameters are extracted. 109 */ onConnectedToRoom(final SignalingParameters params)110 void onConnectedToRoom(final SignalingParameters params); 111 112 /** 113 * Callback fired once remote SDP is received. 114 */ onRemoteDescription(final SessionDescription sdp)115 void onRemoteDescription(final SessionDescription sdp); 116 117 /** 118 * Callback fired once remote Ice candidate is received. 119 */ onRemoteIceCandidate(final IceCandidate candidate)120 void onRemoteIceCandidate(final IceCandidate candidate); 121 122 /** 123 * Callback fired once remote Ice candidate removals are received. 124 */ onRemoteIceCandidatesRemoved(final IceCandidate[] candidates)125 void onRemoteIceCandidatesRemoved(final IceCandidate[] candidates); 126 127 /** 128 * Callback fired once channel is closed. 129 */ onChannelClose()130 void onChannelClose(); 131 132 /** 133 * Callback fired once channel error happened. 134 */ onChannelError(final String description)135 void onChannelError(final String description); 136 } 137 } 138