iOS: Move AppRTC logging methods to public headers.

BUG=

Review URL: https://codereview.webrtc.org/1241283004

Cr-Commit-Position: refs/heads/master@{#9629}
This commit is contained in:
tkchin
2015-07-23 12:50:55 -07:00
committed by Commit bot
parent 28bae02bd3
commit c3f46a9f7f
13 changed files with 135 additions and 120 deletions

View File

@ -25,44 +25,40 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#import "ARDLogging.h" #import "RTCLogging.h"
#include "webrtc/base/logging.h" #include "webrtc/base/logging.h"
void ARDLogInit() { rtc::LoggingSeverity RTCGetNativeLoggingSeverity(RTCLoggingSeverity severity) {
#ifndef _DEBUG switch (severity) {
// In debug builds the default level is LS_INFO and in non-debug builds it is case kRTCLoggingSeverityVerbose:
// disabled. Continue to log to console in non-debug builds, but only return rtc::LS_VERBOSE;
// warnings and errors. case kRTCLoggingSeverityInfo:
rtc::LogMessage::LogToDebug(rtc::LS_WARNING); return rtc::LS_INFO;
#endif case kRTCLoggingSeverityWarning:
} return rtc::LS_WARNING;
case kRTCLoggingSeverityError:
void ARDLogToWebRTCLogger(ARDLogSeverity severity, NSString *logString) { return rtc::LS_ERROR;
if (logString.length) {
const char* utf8String = logString.UTF8String;
switch (severity) {
case kARDLogSeverityVerbose:
LOG(LS_VERBOSE) << utf8String;
break;
case kARDLogSeverityInfo:
LOG(LS_INFO) << utf8String;
break;
case kARDLogSeverityWarning:
LOG(LS_WARNING) << utf8String;
break;
case kARDLogSeverityError:
LOG(LS_ERROR) << utf8String;
break;
}
} }
} }
NSString *ARDFileName(const char *filePath) { void RTCLogEx(RTCLoggingSeverity severity, NSString* logString) {
NSString *nsFilePath = if (logString.length) {
[[NSString alloc] initWithBytesNoCopy:const_cast<char *>(filePath) const char* utf8String = logString.UTF8String;
LOG_V(RTCGetNativeLoggingSeverity(severity)) << utf8String;
}
}
void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity) {
rtc::LogMessage::LogToDebug(RTCGetNativeLoggingSeverity(severity));
}
NSString* RTCFileName(const char* filePath) {
NSString* nsFilePath =
[[NSString alloc] initWithBytesNoCopy:const_cast<char*>(filePath)
length:strlen(filePath) length:strlen(filePath)
encoding:NSUTF8StringEncoding encoding:NSUTF8StringEncoding
freeWhenDone:NO]; freeWhenDone:NO];
return nsFilePath.lastPathComponent; return nsFilePath.lastPathComponent;
} }

View File

@ -27,62 +27,66 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
// We route all logging through the WebRTC logger. By doing this we will get // Subset of rtc::LoggingSeverity.
// both app and WebRTC logs in the same place, which we can then route to a typedef NS_ENUM(NSInteger, RTCLoggingSeverity) {
// file if we need to. A side effect of this is that we get severity for free. kRTCLoggingSeverityVerbose,
typedef NS_ENUM(NSInteger, ARDLogSeverity) { kRTCLoggingSeverityInfo,
kARDLogSeverityVerbose, kRTCLoggingSeverityWarning,
kARDLogSeverityInfo, kRTCLoggingSeverityError,
kARDLogSeverityWarning,
kARDLogSeverityError,
}; };
#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" void ARDLogToWebRTCLogger(ARDLogSeverity severity, extern "C" void RTCLogEx(RTCLoggingSeverity severity, NSString* logString);
NSString *logString); extern "C" void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity);
extern "C" NSString *ARDFileName(const char *filePath); extern "C" NSString* RTCFileName(const char* filePath);
extern "C" void ARDLogInit();
#else #else
// Logs |logString| to the WebRTC logger at the given severity.
extern void ARDLogToWebRTCLogger(ARDLogSeverity severity, NSString *logString); // Wrapper for C++ LOG(sev) macros.
// Logs the log string to the webrtc logstream for the given severity.
extern void RTCLogEx(RTCLoggingSeverity severity, NSString* logString);
// Wrapper for rtc::LogMessage::LogToDebug.
// Sets the minimum severity to be logged to console.
extern void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity);
// Returns the filename with the path prefix removed. // Returns the filename with the path prefix removed.
extern NSString *ARDFileName(const char *filePath); extern NSString* RTCFileName(const char* filePath);
// Initializes the correct logging levels. This should be called once on app
// startup.
extern void ARDLogInit();
#endif #endif
#define ARDLogString(format, ...) \ // Some convenience macros.
#define RTCLogString(format, ...) \
[NSString stringWithFormat:@"(%@:%d %s): " format, \ [NSString stringWithFormat:@"(%@:%d %s): " format, \
ARDFileName(__FILE__), \ RTCFileName(__FILE__), \
__LINE__, \ __LINE__, \
__FUNCTION__, \ __FUNCTION__, \
##__VA_ARGS__] ##__VA_ARGS__]
#define ARDLogEx(severity, format, ...) \ #define RTCLogFormat(severity, format, ...) \
do { \ do { \
NSString *logString = ARDLogString(format, ##__VA_ARGS__); \ NSString *logString = RTCLogString(format, ##__VA_ARGS__); \
ARDLogToWebRTCLogger(severity, logString); \ RTCLogEx(severity, logString); \
} while (false) } while (false)
#define ARDLogVerbose(format, ...) \ #define RTCLogVerbose(format, ...) \
ARDLogEx(kARDLogSeverityVerbose, format, ##__VA_ARGS__) \ RTCLogFormat(kRTCLoggingSeverityVerbose, format, ##__VA_ARGS__) \
#define ARDLogInfo(format, ...) \ #define RTCLogInfo(format, ...) \
ARDLogEx(kARDLogSeverityInfo, format, ##__VA_ARGS__) \ RTCLogFormat(kRTCLoggingSeverityInfo, format, ##__VA_ARGS__) \
#define ARDLogWarning(format, ...) \ #define RTCLogWarning(format, ...) \
ARDLogEx(kARDLogSeverityWarning, format, ##__VA_ARGS__) \ RTCLogFormat(kRTCLoggingSeverityWarning, format, ##__VA_ARGS__) \
#define ARDLogError(format, ...) \ #define RTCLogError(format, ...) \
ARDLogEx(kARDLogSeverityError, format, ##__VA_ARGS__) \ RTCLogFormat(kRTCLoggingSeverityError, format, ##__VA_ARGS__) \
#ifdef _DEBUG #ifdef _DEBUG
#define ARDLogDebug(format, ...) ARDLogInfo(format, ##__VA_ARGS__) #define RTCLogDebug(format, ...) RTCLogInfo(format, ##__VA_ARGS__)
#else #else
#define ARDLogDebug(format, ...) \ #define RTCLogDebug(format, ...) \
do { \ do { \
} while (false) } while (false)
#endif #endif
#define ARDLog(format, ...) ARDLogInfo(format, ##__VA_ARGS__) #define RTCLog(format, ...) RTCLogInfo(format, ##__VA_ARGS__)

View File

@ -32,17 +32,16 @@
#endif #endif
#import "RTCFileLogger.h" #import "RTCFileLogger.h"
#import "RTCICEServer.h" #import "RTCICEServer.h"
#import "RTCLogging.h"
#import "RTCMediaConstraints.h" #import "RTCMediaConstraints.h"
#import "RTCMediaStream.h" #import "RTCMediaStream.h"
#import "RTCPair.h" #import "RTCPair.h"
#import "RTCPeerConnectionInterface.h" #import "RTCPeerConnectionInterface.h"
#import "RTCVideoCapturer.h" #import "RTCVideoCapturer.h"
#import "RTCAVFoundationVideoSource.h"
#import "ARDAppEngineClient.h" #import "ARDAppEngineClient.h"
#import "ARDCEODTURNClient.h" #import "ARDCEODTURNClient.h"
#import "ARDJoinResponse.h" #import "ARDJoinResponse.h"
#import "ARDLogging.h"
#import "ARDMessageResponse.h" #import "ARDMessageResponse.h"
#import "ARDSDPUtils.h" #import "ARDSDPUtils.h"
#import "ARDSignalingMessage.h" #import "ARDSignalingMessage.h"
@ -162,7 +161,8 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
[_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers, [_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers,
NSError *error) { NSError *error) {
if (error) { if (error) {
ARDLog("Error retrieving TURN servers: %@", error.localizedDescription); RTCLogError("Error retrieving TURN servers: %@",
error.localizedDescription);
} }
ARDAppClient *strongSelf = weakSelf; ARDAppClient *strongSelf = weakSelf;
[strongSelf.iceServers addObjectsFromArray:turnServers]; [strongSelf.iceServers addObjectsFromArray:turnServers];
@ -181,12 +181,12 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
NSError *joinError = NSError *joinError =
[[strongSelf class] errorForJoinResultType:response.result]; [[strongSelf class] errorForJoinResultType:response.result];
if (joinError) { if (joinError) {
ARDLog(@"Failed to join room:%@ on room server.", roomId); RTCLogError(@"Failed to join room:%@ on room server.", roomId);
[strongSelf disconnect]; [strongSelf disconnect];
[strongSelf.delegate appClient:strongSelf didError:joinError]; [strongSelf.delegate appClient:strongSelf didError:joinError];
return; return;
} }
ARDLog(@"Joined room:%@ on room server.", roomId); RTCLog(@"Joined room:%@ on room server.", roomId);
strongSelf.roomId = response.roomId; strongSelf.roomId = response.roomId;
strongSelf.clientId = response.clientId; strongSelf.clientId = response.clientId;
strongSelf.isInitiator = response.isInitiator; strongSelf.isInitiator = response.isInitiator;
@ -278,13 +278,13 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
signalingStateChanged:(RTCSignalingState)stateChanged { signalingStateChanged:(RTCSignalingState)stateChanged {
ARDLog(@"Signaling state changed: %d", stateChanged); RTCLog(@"Signaling state changed: %d", stateChanged);
} }
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
addedStream:(RTCMediaStream *)stream { addedStream:(RTCMediaStream *)stream {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
ARDLog(@"Received %lu video tracks and %lu audio tracks", RTCLog(@"Received %lu video tracks and %lu audio tracks",
(unsigned long)stream.videoTracks.count, (unsigned long)stream.videoTracks.count,
(unsigned long)stream.audioTracks.count); (unsigned long)stream.audioTracks.count);
if (stream.videoTracks.count) { if (stream.videoTracks.count) {
@ -296,17 +296,17 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
removedStream:(RTCMediaStream *)stream { removedStream:(RTCMediaStream *)stream {
ARDLog(@"Stream was removed."); RTCLog(@"Stream was removed.");
} }
- (void)peerConnectionOnRenegotiationNeeded: - (void)peerConnectionOnRenegotiationNeeded:
(RTCPeerConnection *)peerConnection { (RTCPeerConnection *)peerConnection {
ARDLog(@"WARNING: Renegotiation needed but unimplemented."); RTCLog(@"WARNING: Renegotiation needed but unimplemented.");
} }
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
iceConnectionChanged:(RTCICEConnectionState)newState { iceConnectionChanged:(RTCICEConnectionState)newState {
ARDLog(@"ICE state changed: %d", newState); RTCLog(@"ICE state changed: %d", newState);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[_delegate appClient:self didChangeConnectionState:newState]; [_delegate appClient:self didChangeConnectionState:newState];
}); });
@ -314,7 +314,7 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
iceGatheringChanged:(RTCICEGatheringState)newState { iceGatheringChanged:(RTCICEGatheringState)newState {
ARDLog(@"ICE gathering state changed: %d", newState); RTCLog(@"ICE gathering state changed: %d", newState);
} }
- (void)peerConnection:(RTCPeerConnection *)peerConnection - (void)peerConnection:(RTCPeerConnection *)peerConnection
@ -339,7 +339,7 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
error:(NSError *)error { error:(NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (error) { if (error) {
ARDLog(@"Failed to create session description. Error: %@", error); RTCLogError(@"Failed to create session description. Error: %@", error);
[self disconnect]; [self disconnect];
NSDictionary *userInfo = @{ NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to create session description.", NSLocalizedDescriptionKey: @"Failed to create session description.",
@ -368,7 +368,7 @@ static NSInteger const kARDAppClientErrorInvalidRoom = -6;
didSetSessionDescriptionWithError:(NSError *)error { didSetSessionDescriptionWithError:(NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (error) { if (error) {
ARDLog(@"Failed to set session description. Error: %@", error); RTCLogError(@"Failed to set session description. Error: %@", error);
[self disconnect]; [self disconnect];
NSDictionary *userInfo = @{ NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to set session description.", NSLocalizedDescriptionKey: @"Failed to set session description.",

View File

@ -27,8 +27,9 @@
#import "ARDAppEngineClient.h" #import "ARDAppEngineClient.h"
#import "RTCLogging.h"
#import "ARDJoinResponse.h" #import "ARDJoinResponse.h"
#import "ARDLogging.h"
#import "ARDMessageResponse.h" #import "ARDMessageResponse.h"
#import "ARDSignalingMessage.h" #import "ARDSignalingMessage.h"
#import "ARDUtilities.h" #import "ARDUtilities.h"
@ -58,7 +59,7 @@ static NSInteger const kARDAppEngineClientErrorBadResponse = -1;
NSString *urlString = NSString *urlString =
[NSString stringWithFormat:kARDRoomServerJoinFormat, roomId]; [NSString stringWithFormat:kARDRoomServerJoinFormat, roomId];
NSURL *roomURL = [NSURL URLWithString:urlString]; NSURL *roomURL = [NSURL URLWithString:urlString];
ARDLog(@"Joining room:%@ on room server.", roomId); RTCLog(@"Joining room:%@ on room server.", roomId);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL];
request.HTTPMethod = @"POST"; request.HTTPMethod = @"POST";
__weak ARDAppEngineClient *weakSelf = self; __weak ARDAppEngineClient *weakSelf = self;
@ -102,7 +103,7 @@ static NSInteger const kARDAppEngineClientErrorBadResponse = -1;
[NSString stringWithFormat: [NSString stringWithFormat:
kARDRoomServerMessageFormat, roomId, clientId]; kARDRoomServerMessageFormat, roomId, clientId];
NSURL *url = [NSURL URLWithString:urlString]; NSURL *url = [NSURL URLWithString:urlString];
ARDLog(@"C->RS POST: %@", message); RTCLog(@"C->RS POST: %@", message);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST"; request.HTTPMethod = @"POST";
request.HTTPBody = data; request.HTTPBody = data;
@ -148,19 +149,19 @@ static NSInteger const kARDAppEngineClientErrorBadResponse = -1;
NSError *error = nil; NSError *error = nil;
// We want a synchronous request so that we know that we've left the room on // We want a synchronous request so that we know that we've left the room on
// room server before we do any further work. // room server before we do any further work.
ARDLog(@"C->RS: BYE"); RTCLog(@"C->RS: BYE");
[NSURLConnection sendSynchronousRequest:request [NSURLConnection sendSynchronousRequest:request
returningResponse:&response returningResponse:&response
error:&error]; error:&error];
if (error) { if (error) {
ARDLog(@"Error leaving room %@ on room server: %@", RTCLogError(@"Error leaving room %@ on room server: %@",
roomId, error.localizedDescription); roomId, error.localizedDescription);
if (completionHandler) { if (completionHandler) {
completionHandler(error); completionHandler(error);
} }
return; return;
} }
ARDLog(@"Left room:%@ on room server.", roomId); RTCLog(@"Left room:%@ on room server.", roomId);
if (completionHandler) { if (completionHandler) {
completionHandler(nil); completionHandler(nil);
} }

View File

@ -27,7 +27,7 @@
#import "ARDSDPUtils.h" #import "ARDSDPUtils.h"
#import "ARDLogging.h" #import "RTCLogging.h"
#import "RTCSessionDescription.h" #import "RTCSessionDescription.h"
@implementation ARDSDPUtils @implementation ARDSDPUtils
@ -71,11 +71,11 @@
} }
} }
if (mLineIndex == -1) { if (mLineIndex == -1) {
ARDLog(@"No m=video line, so can't prefer %@", codec); RTCLog(@"No m=video line, so can't prefer %@", codec);
return description; return description;
} }
if (!codecRtpMap) { if (!codecRtpMap) {
ARDLog(@"No rtpmap for %@", codec); RTCLog(@"No rtpmap for %@", codec);
return description; return description;
} }
NSArray *origMLineParts = NSArray *origMLineParts =
@ -99,7 +99,7 @@
[lines replaceObjectAtIndex:mLineIndex [lines replaceObjectAtIndex:mLineIndex
withObject:newMLine]; withObject:newMLine];
} else { } else {
ARDLog(@"Wrong SDP media description format: %@", lines[mLineIndex]); RTCLogWarning(@"Wrong SDP media description format: %@", lines[mLineIndex]);
} }
NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator]; NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator];
return [[RTCSessionDescription alloc] initWithType:description.type return [[RTCSessionDescription alloc] initWithType:description.type

View File

@ -27,7 +27,8 @@
#import "ARDSignalingMessage.h" #import "ARDSignalingMessage.h"
#import "ARDLogging.h" #import "RTCLogging.h"
#import "ARDUtilities.h" #import "ARDUtilities.h"
#import "RTCICECandidate+JSON.h" #import "RTCICECandidate+JSON.h"
#import "RTCSessionDescription+JSON.h" #import "RTCSessionDescription+JSON.h"
@ -53,7 +54,7 @@ static NSString const *kARDSignalingMessageTypeKey = @"type";
+ (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString { + (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString {
NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString]; NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString];
if (!values) { if (!values) {
ARDLog(@"Error parsing signaling message JSON."); RTCLogError(@"Error parsing signaling message JSON.");
return nil; return nil;
} }
@ -72,7 +73,7 @@ static NSString const *kARDSignalingMessageTypeKey = @"type";
} else if ([typeString isEqualToString:@"bye"]) { } else if ([typeString isEqualToString:@"bye"]) {
message = [[ARDByeMessage alloc] init]; message = [[ARDByeMessage alloc] init];
} else { } else {
ARDLog(@"Unexpected type: %@", typeString); RTCLogError(@"Unexpected type: %@", typeString);
} }
return message; return message;
} }

View File

@ -27,10 +27,11 @@
#import "ARDWebSocketChannel.h" #import "ARDWebSocketChannel.h"
#import "ARDLogging.h" #import "RTCLogging.h"
#import "ARDUtilities.h"
#import "SRWebSocket.h" #import "SRWebSocket.h"
#import "ARDUtilities.h"
// TODO(tkchin): move these to a configuration object. // TODO(tkchin): move these to a configuration object.
static NSString const *kARDWSSMessageErrorKey = @"error"; static NSString const *kARDWSSMessageErrorKey = @"error";
static NSString const *kARDWSSMessagePayloadKey = @"msg"; static NSString const *kARDWSSMessagePayloadKey = @"msg";
@ -58,7 +59,7 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
_delegate = delegate; _delegate = delegate;
_socket = [[SRWebSocket alloc] initWithURL:url]; _socket = [[SRWebSocket alloc] initWithURL:url];
_socket.delegate = self; _socket.delegate = self;
ARDLog(@"Opening WebSocket."); RTCLog(@"Opening WebSocket.");
[_socket open]; [_socket open];
} }
return self; return self;
@ -105,12 +106,12 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
NSString *messageString = NSString *messageString =
[[NSString alloc] initWithData:messageJSONObject [[NSString alloc] initWithData:messageJSONObject
encoding:NSUTF8StringEncoding]; encoding:NSUTF8StringEncoding];
ARDLog(@"C->WSS: %@", messageString); RTCLog(@"C->WSS: %@", messageString);
[_socket send:messageString]; [_socket send:messageString];
} else { } else {
NSString *dataString = NSString *dataString =
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
ARDLog(@"C->WSS POST: %@", dataString); RTCLog(@"C->WSS POST: %@", dataString);
NSString *urlString = NSString *urlString =
[NSString stringWithFormat:@"%@/%@/%@", [NSString stringWithFormat:@"%@/%@/%@",
[_restURL absoluteString], _roomId, _clientId]; [_restURL absoluteString], _roomId, _clientId];
@ -127,7 +128,7 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
return; return;
} }
[_socket close]; [_socket close];
ARDLog(@"C->WSS DELETE rid:%@ cid:%@", _roomId, _clientId); RTCLog(@"C->WSS DELETE rid:%@ cid:%@", _roomId, _clientId);
NSString *urlString = NSString *urlString =
[NSString stringWithFormat:@"%@/%@/%@", [NSString stringWithFormat:@"%@/%@/%@",
[_restURL absoluteString], _roomId, _clientId]; [_restURL absoluteString], _roomId, _clientId];
@ -141,7 +142,7 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
#pragma mark - SRWebSocketDelegate #pragma mark - SRWebSocketDelegate
- (void)webSocketDidOpen:(SRWebSocket *)webSocket { - (void)webSocketDidOpen:(SRWebSocket *)webSocket {
ARDLog(@"WebSocket connection opened."); RTCLog(@"WebSocket connection opened.");
self.state = kARDSignalingChannelStateOpen; self.state = kARDSignalingChannelStateOpen;
if (_roomId.length && _clientId.length) { if (_roomId.length && _clientId.length) {
[self registerWithCollider]; [self registerWithCollider];
@ -155,24 +156,24 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
options:0 options:0
error:nil]; error:nil];
if (![jsonObject isKindOfClass:[NSDictionary class]]) { if (![jsonObject isKindOfClass:[NSDictionary class]]) {
ARDLog(@"Unexpected message: %@", jsonObject); RTCLogError(@"Unexpected message: %@", jsonObject);
return; return;
} }
NSDictionary *wssMessage = jsonObject; NSDictionary *wssMessage = jsonObject;
NSString *errorString = wssMessage[kARDWSSMessageErrorKey]; NSString *errorString = wssMessage[kARDWSSMessageErrorKey];
if (errorString.length) { if (errorString.length) {
ARDLog(@"WSS error: %@", errorString); RTCLogError(@"WSS error: %@", errorString);
return; return;
} }
NSString *payload = wssMessage[kARDWSSMessagePayloadKey]; NSString *payload = wssMessage[kARDWSSMessagePayloadKey];
ARDSignalingMessage *signalingMessage = ARDSignalingMessage *signalingMessage =
[ARDSignalingMessage messageFromJSONString:payload]; [ARDSignalingMessage messageFromJSONString:payload];
ARDLog(@"WSS->C: %@", payload); RTCLog(@"WSS->C: %@", payload);
[_delegate channel:self didReceiveMessage:signalingMessage]; [_delegate channel:self didReceiveMessage:signalingMessage];
} }
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error { - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error {
ARDLog(@"WebSocket error: %@", error); RTCLogError(@"WebSocket error: %@", error);
self.state = kARDSignalingChannelStateError; self.state = kARDSignalingChannelStateError;
} }
@ -180,7 +181,7 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
didCloseWithCode:(NSInteger)code didCloseWithCode:(NSInteger)code
reason:(NSString *)reason reason:(NSString *)reason
wasClean:(BOOL)wasClean { wasClean:(BOOL)wasClean {
ARDLog(@"WebSocket closed with code: %ld reason:%@ wasClean:%d", RTCLog(@"WebSocket closed with code: %ld reason:%@ wasClean:%d",
(long)code, reason, wasClean); (long)code, reason, wasClean);
NSParameterAssert(_state != kARDSignalingChannelStateError); NSParameterAssert(_state != kARDSignalingChannelStateError);
self.state = kARDSignalingChannelStateClosed; self.state = kARDSignalingChannelStateClosed;
@ -205,7 +206,7 @@ static NSString const *kARDWSSMessagePayloadKey = @"msg";
error:nil]; error:nil];
NSString *messageString = NSString *messageString =
[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding]; [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
ARDLog(@"Registering on WSS for rid:%@ cid:%@", _roomId, _clientId); RTCLog(@"Registering on WSS for rid:%@ cid:%@", _roomId, _clientId);
// Registration can fail if server rejects it. For example, if the room is // Registration can fail if server rejects it. For example, if the room is
// full. // full.
[_socket send:messageString]; [_socket send:messageString];

View File

@ -27,7 +27,7 @@
#import "RTCICECandidate+JSON.h" #import "RTCICECandidate+JSON.h"
#import "ARDLogging.h" #import "RTCLogging.h"
static NSString const *kRTCICECandidateTypeKey = @"type"; static NSString const *kRTCICECandidateTypeKey = @"type";
static NSString const *kRTCICECandidateTypeValue = @"candidate"; static NSString const *kRTCICECandidateTypeValue = @"candidate";
@ -58,7 +58,7 @@ static NSString const *kRTCICECandidateSdpKey = @"candidate";
options:NSJSONWritingPrettyPrinted options:NSJSONWritingPrettyPrinted
error:&error]; error:&error];
if (error) { if (error) {
ARDLog(@"Error serializing JSON: %@", error); RTCLogError(@"Error serializing JSON: %@", error);
return nil; return nil;
} }
return data; return data;

View File

@ -25,9 +25,10 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#import "ARDLogging.h"
#import "ARDUtilities.h" #import "ARDUtilities.h"
#import "RTCLogging.h"
@implementation NSDictionary (ARDUtilites) @implementation NSDictionary (ARDUtilites)
+ (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString { + (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString {
@ -37,7 +38,7 @@
NSDictionary *dict = NSDictionary *dict =
[NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error) { if (error) {
ARDLog(@"Error parsing JSON: %@", error.localizedDescription); RTCLogError(@"Error parsing JSON: %@", error.localizedDescription);
} }
return dict; return dict;
} }
@ -47,7 +48,7 @@
NSDictionary *dict = NSDictionary *dict =
[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error]; [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (error) { if (error) {
ARDLog(@"Error parsing JSON: %@", error.localizedDescription); RTCLogError(@"Error parsing JSON: %@", error.localizedDescription);
} }
return dict; return dict;
} }
@ -85,7 +86,7 @@
NSData *data, NSData *data,
NSError *error) { NSError *error) {
if (error) { if (error) {
ARDLog(@"Error posting data: %@", error.localizedDescription); RTCLogError(@"Error posting data: %@", error.localizedDescription);
if (completionHandler) { if (completionHandler) {
completionHandler(NO, data); completionHandler(NO, data);
} }
@ -96,7 +97,7 @@
NSString *serverResponse = data.length > 0 ? NSString *serverResponse = data.length > 0 ?
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] : [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] :
nil; nil;
ARDLog(@"Received bad response: %@", serverResponse); RTCLogError(@"Received bad response: %@", serverResponse);
if (completionHandler) { if (completionHandler) {
completionHandler(NO, data); completionHandler(NO, data);
} }

View File

@ -27,10 +27,11 @@
#import "ARDAppDelegate.h" #import "ARDAppDelegate.h"
#import "ARDLogging.h" #import "RTCLogging.h"
#import "ARDMainViewController.h"
#import "RTCPeerConnectionFactory.h" #import "RTCPeerConnectionFactory.h"
#import "ARDMainViewController.h"
@implementation ARDAppDelegate { @implementation ARDAppDelegate {
UIWindow *_window; UIWindow *_window;
} }
@ -44,7 +45,14 @@
[_window makeKeyAndVisible]; [_window makeKeyAndVisible];
ARDMainViewController *viewController = [[ARDMainViewController alloc] init]; ARDMainViewController *viewController = [[ARDMainViewController alloc] init];
_window.rootViewController = viewController; _window.rootViewController = viewController;
ARDLogInit();
#ifndef _DEBUG
// In debug builds the default level is LS_INFO and in non-debug builds it is
// disabled. Continue to log to console in non-debug builds, but only
// warnings and errors.
RTCSetMinDebugLogLevel(kRTCLoggingSeverityWarning);
#endif
return YES; return YES;
} }

View File

@ -28,9 +28,9 @@
#import "ARDVideoCallViewController.h" #import "ARDVideoCallViewController.h"
#import "RTCAVFoundationVideoSource.h" #import "RTCAVFoundationVideoSource.h"
#import "RTCLogging.h"
#import "ARDAppClient.h" #import "ARDAppClient.h"
#import "ARDLogging.h"
#import "ARDVideoCallView.h" #import "ARDVideoCallView.h"
@interface ARDVideoCallViewController () <ARDAppClientDelegate, @interface ARDVideoCallViewController () <ARDAppClientDelegate,
@ -70,13 +70,13 @@
didChangeState:(ARDAppClientState)state { didChangeState:(ARDAppClientState)state {
switch (state) { switch (state) {
case kARDAppClientStateConnected: case kARDAppClientStateConnected:
ARDLog(@"Client connected."); RTCLog(@"Client connected.");
break; break;
case kARDAppClientStateConnecting: case kARDAppClientStateConnecting:
ARDLog(@"Client connecting."); RTCLog(@"Client connecting.");
break; break;
case kARDAppClientStateDisconnected: case kARDAppClientStateDisconnected:
ARDLog(@"Client disconnected."); RTCLog(@"Client disconnected.");
[self hangup]; [self hangup];
break; break;
} }
@ -84,7 +84,7 @@
- (void)appClient:(ARDAppClient *)client - (void)appClient:(ARDAppClient *)client
didChangeConnectionState:(RTCICEConnectionState)state { didChangeConnectionState:(RTCICEConnectionState)state {
ARDLog(@"ICE state changed: %d", state); RTCLog(@"ICE state changed: %d", state);
__weak ARDVideoCallViewController *weakSelf = self; __weak ARDVideoCallViewController *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
ARDVideoCallViewController *strongSelf = weakSelf; ARDVideoCallViewController *strongSelf = weakSelf;

View File

@ -247,6 +247,7 @@
'app/webrtc/objc/RTCICECandidate.mm', 'app/webrtc/objc/RTCICECandidate.mm',
'app/webrtc/objc/RTCICEServer+Internal.h', 'app/webrtc/objc/RTCICEServer+Internal.h',
'app/webrtc/objc/RTCICEServer.mm', 'app/webrtc/objc/RTCICEServer.mm',
'app/webrtc/objc/RTCLogging.mm',
'app/webrtc/objc/RTCMediaConstraints+Internal.h', 'app/webrtc/objc/RTCMediaConstraints+Internal.h',
'app/webrtc/objc/RTCMediaConstraints.mm', 'app/webrtc/objc/RTCMediaConstraints.mm',
'app/webrtc/objc/RTCMediaConstraintsNative.cc', 'app/webrtc/objc/RTCMediaConstraintsNative.cc',
@ -285,6 +286,7 @@
'app/webrtc/objc/public/RTCI420Frame.h', 'app/webrtc/objc/public/RTCI420Frame.h',
'app/webrtc/objc/public/RTCICECandidate.h', 'app/webrtc/objc/public/RTCICECandidate.h',
'app/webrtc/objc/public/RTCICEServer.h', 'app/webrtc/objc/public/RTCICEServer.h',
'app/webrtc/objc/public/RTCLogging.h',
'app/webrtc/objc/public/RTCMediaConstraints.h', 'app/webrtc/objc/public/RTCMediaConstraints.h',
'app/webrtc/objc/public/RTCMediaSource.h', 'app/webrtc/objc/public/RTCMediaSource.h',
'app/webrtc/objc/public/RTCMediaStream.h', 'app/webrtc/objc/public/RTCMediaStream.h',

View File

@ -155,9 +155,10 @@
{ {
'target_name': 'apprtc_common', 'target_name': 'apprtc_common',
'type': 'static_library', 'type': 'static_library',
'dependencies': [
'libjingle.gyp:libjingle_peerconnection_objc',
],
'sources': [ 'sources': [
'examples/objc/AppRTCDemo/common/ARDLogging.h',
'examples/objc/AppRTCDemo/common/ARDLogging.mm',
'examples/objc/AppRTCDemo/common/ARDUtilities.h', 'examples/objc/AppRTCDemo/common/ARDUtilities.h',
'examples/objc/AppRTCDemo/common/ARDUtilities.m', 'examples/objc/AppRTCDemo/common/ARDUtilities.m',
], ],