1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef TEST_PCOBSERVER_H_ 6 #define TEST_PCOBSERVER_H_ 7 8 #include "nsNetCID.h" 9 #include "nsITimer.h" 10 #include "nsComponentManagerUtils.h" 11 #include "nsIComponentManager.h" 12 #include "nsIComponentRegistrar.h" 13 14 #include "mozilla/Mutex.h" 15 #include "AudioSegment.h" 16 #include "MediaSegment.h" 17 #include "StreamTracks.h" 18 #include "nsTArray.h" 19 #include "nsIRunnable.h" 20 #include "nsISupportsImpl.h" 21 #include "mozilla/dom/PeerConnectionObserverEnumsBinding.h" 22 #include "PeerConnectionImpl.h" 23 #include "nsWeakReference.h" 24 25 namespace mozilla { 26 class PeerConnectionImpl; 27 } 28 29 class nsIDOMWindow; 30 class nsIDOMDataChannel; 31 32 namespace test { 33 34 class AFakePCObserver : public nsSupportsWeakReference 35 { 36 protected: 37 typedef mozilla::ErrorResult ER; 38 public: 39 enum Action { 40 OFFER, 41 ANSWER 42 }; 43 44 enum ResponseState { 45 stateNoResponse, 46 stateSuccess, 47 stateError 48 }; 49 AFakePCObserver(mozilla::PeerConnectionImpl * peerConnection,const std::string & aName)50 AFakePCObserver(mozilla::PeerConnectionImpl *peerConnection, 51 const std::string &aName) : 52 state(stateNoResponse), addIceSuccessCount(0), 53 onAddStreamCalled(false), 54 name(aName), 55 pc(peerConnection) { 56 } 57 AFakePCObserver()58 AFakePCObserver() : 59 state(stateNoResponse), addIceSuccessCount(0), 60 onAddStreamCalled(false), 61 name(""), 62 pc(nullptr) { 63 } 64 ~AFakePCObserver()65 virtual ~AFakePCObserver() {} 66 GetStreams()67 std::vector<mozilla::DOMMediaStream *> GetStreams() { return streams; } 68 69 ResponseState state; 70 std::string lastString; 71 mozilla::PeerConnectionImpl::Error lastStatusCode; 72 mozilla::dom::PCObserverStateType lastStateType; 73 int addIceSuccessCount; 74 bool onAddStreamCalled; 75 std::string name; 76 std::vector<std::string> candidates; 77 78 NS_IMETHOD OnCreateOfferSuccess(const char* offer, ER&) = 0; 79 NS_IMETHOD OnCreateOfferError(uint32_t code, const char *msg, ER&) = 0; 80 NS_IMETHOD OnCreateAnswerSuccess(const char* answer, ER&) = 0; 81 NS_IMETHOD OnCreateAnswerError(uint32_t code, const char *msg, ER&) = 0; 82 NS_IMETHOD OnSetLocalDescriptionSuccess(ER&) = 0; 83 NS_IMETHOD OnSetRemoteDescriptionSuccess(ER&) = 0; 84 NS_IMETHOD OnSetLocalDescriptionError(uint32_t code, const char *msg, ER&) = 0; 85 NS_IMETHOD OnSetRemoteDescriptionError(uint32_t code, const char *msg, ER&) = 0; 86 NS_IMETHOD NotifyDataChannel(nsIDOMDataChannel *channel, ER&) = 0; 87 NS_IMETHOD OnStateChange(mozilla::dom::PCObserverStateType state_type, ER&, 88 void* = nullptr) = 0; 89 NS_IMETHOD OnAddStream(mozilla::DOMMediaStream &stream, ER&) = 0; 90 NS_IMETHOD OnRemoveStream(mozilla::DOMMediaStream &stream, ER&) = 0; 91 NS_IMETHOD OnAddTrack(mozilla::dom::MediaStreamTrack &track, ER&) = 0; 92 NS_IMETHOD OnRemoveTrack(mozilla::dom::MediaStreamTrack &track, ER&) = 0; 93 NS_IMETHOD OnReplaceTrackSuccess(ER&) = 0; 94 NS_IMETHOD OnReplaceTrackError(uint32_t code, const char *msg, ER&) = 0; 95 NS_IMETHOD OnAddIceCandidateSuccess(ER&) = 0; 96 NS_IMETHOD OnAddIceCandidateError(uint32_t code, const char *msg, ER&) = 0; 97 NS_IMETHOD OnIceCandidate(uint16_t level, const char *mid, 98 const char *candidate, ER&) = 0; 99 NS_IMETHOD OnNegotiationNeeded(ER&) = 0; 100 protected: 101 mozilla::PeerConnectionImpl *pc; 102 std::vector<mozilla::DOMMediaStream *> streams; 103 }; 104 } 105 106 namespace mozilla { 107 namespace dom { 108 typedef test::AFakePCObserver PeerConnectionObserver; 109 } 110 } 111 112 #endif 113