Skip to content

Commit

Permalink
(ios) Fix imports and usage after file + class rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Lindsay-Needs-Sleep committed Jan 25, 2020
1 parent d47546a commit 35cd482
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 118 deletions.
7 changes: 2 additions & 5 deletions src/ios/MLPCastRequestDelegate.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//
// CastRequestDelegate.h
// MLPCastRequestDelegate.h
// ChromeCast
//
// Created by mac on 2019/9/30.
//

#import <Foundation/Foundation.h>
#import <GoogleCast/GoogleCast.h>
Expand Down Expand Up @@ -36,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithReceiverAvailableUpdate:(void(^)(BOOL available))onReceiverAvailableUpdate onSessionRejoin:(void(^)(NSDictionary* session))onSessionRejoin onMediaLoaded:(void(^)(NSDictionary* m))onMediaLoaded onMediaUpdated:(void(^)(NSDictionary* media))onMediaUpdated onSessionUpdated:(void(^)(NSDictionary* session))onSessionUpdated onSessionEnd:(void(^)(NSDictionary* session))onSessionEnd onMessageReceived:(void(^)(NSDictionary* session,NSString* namespace,NSString* message))onMessageReceived ;
@end

@interface CastRequestDelegate : NSObject<GCKRequestDelegate>
@interface MLPCastRequestDelegate : NSObject<GCKRequestDelegate>
{
void (^didSuccess)(void);
void (^didFail)(GCKError*);
Expand Down
9 changes: 3 additions & 6 deletions src/ios/MLPCastRequestDelegate.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
//
// CastRequestDelegate.m
// MLPCastRequestDelegate.m
// ChromeCast
//
// Created by mac on 2019/9/30.
//

#import "CastRequestDelegate.h"
#import "MLPCastRequestDelegate.h"

@implementation CastConnectionListener

Expand Down Expand Up @@ -67,7 +64,7 @@ - (void)onMessageReceived:(NSDictionary *)session namespace:(NSString *)namespac

@end

@implementation CastRequestDelegate
@implementation MLPCastRequestDelegate

- (instancetype)initWithSuccess:(void(^)(void))success failure:(void(^)(GCKError*))failure abortion:(void(^)(GCKRequestAbortReason))abortion
{
Expand Down
7 changes: 2 additions & 5 deletions src/ios/MLPCastUtilities.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
//
// CastUtilities.h
// MLPCastUtilities.h
// ChromeCast
//
// Created by mac on 2019/9/30.
//

#import <Foundation/Foundation.h>
#import <GoogleCast/GoogleCast.h>

NS_ASSUME_NONNULL_BEGIN

@interface CastUtilities : NSObject
@interface MLPCastUtilities : NSObject

+(GCKMediaInformation *)buildMediaInformation:(NSString *)contentUrl customData:(id )customData contentType:(NSString *)contentType duration:(double)duration streamType:(NSString *)streamType startTime:(double)startTime metaData:(NSDictionary *)metaData textTrackStyle:(NSDictionary *)textTrackStyle;
+(GCKMediaQueueItem *)buildMediaQueueItem:(NSDictionary *)item;
Expand Down
81 changes: 39 additions & 42 deletions src/ios/MLPCastUtilities.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//
// CastUtilities.m
// MLPCastUtilities.m
// ChromeCast
//
// Created by mac on 2019/9/30.
//

#import "CastUtilities.h"
#import "MLPCastUtilities.h"

@implementation CastUtilities
@implementation MLPCastUtilities

NSDictionary* queueOrderIDsByItemId = nil;

Expand All @@ -27,8 +24,8 @@ + (GCKMediaInformation *)buildMediaInformation:(NSString *)contentUrl customData
mediaInfoBuilder.streamType = GCKMediaStreamTypeNone;
}
mediaInfoBuilder.startAbsoluteTime = startTime;
mediaInfoBuilder.metadata = [CastUtilities buildMediaMetadata:metaData];
mediaInfoBuilder.textTrackStyle = [CastUtilities buildTextTrackStyle:textTrackStyle];
mediaInfoBuilder.metadata = [MLPCastUtilities buildMediaMetadata:metaData];
mediaInfoBuilder.textTrackStyle = [MLPCastUtilities buildTextTrackStyle:textTrackStyle];

return [mediaInfoBuilder build];
}
Expand All @@ -45,7 +42,7 @@ + (GCKMediaQueueItem *)buildMediaQueueItem:(NSDictionary *)item {
queueItemBuilder.startTime = startTime;
queueItemBuilder.preloadTime = [item[@"preloadTime"] doubleValue];

queueItemBuilder.mediaInformation = [CastUtilities buildMediaInformation:media[@"contentId"] customData:media[@"customData"] contentType:media[@"contentType"] duration:duration streamType:media[@"streamType"] startTime:startTime metaData:media[@"metadata"] textTrackStyle:item[@"textTrackStyle"]];
queueItemBuilder.mediaInformation = [MLPCastUtilities buildMediaInformation:media[@"contentId"] customData:media[@"customData"] contentType:media[@"contentType"] duration:duration streamType:media[@"streamType"] startTime:startTime metaData:media[@"metadata"] textTrackStyle:item[@"textTrackStyle"]];

return [queueItemBuilder build];
}
Expand Down Expand Up @@ -75,7 +72,7 @@ + (GCKMediaTextTrackStyle *)buildTextTrackStyle:(NSDictionary *)data {

NSString* edgeType = data[@"edgeType"];
if (edgeType != nil) {
mediaTextTrackStyle.edgeType = [CastUtilities parseEdgeType:edgeType];
mediaTextTrackStyle.edgeType = [MLPCastUtilities parseEdgeType:edgeType];
}

NSString* fontFamily = data[@"fontFamily"];
Expand All @@ -85,7 +82,7 @@ + (GCKMediaTextTrackStyle *)buildTextTrackStyle:(NSDictionary *)data {

NSString* fontGenericFamily = data[@"fontGenericFamily"];
if (fontGenericFamily != nil) {
mediaTextTrackStyle.fontGenericFamily = [CastUtilities parseFontGenericFamily:fontGenericFamily];
mediaTextTrackStyle.fontGenericFamily = [MLPCastUtilities parseFontGenericFamily:fontGenericFamily];
}

CGFloat fontScale = (CGFloat)[data[@"fontScale"] floatValue];
Expand All @@ -95,7 +92,7 @@ + (GCKMediaTextTrackStyle *)buildTextTrackStyle:(NSDictionary *)data {

NSString* fontStyle = data[@"fontStyle"];
if (fontFamily != nil) {
mediaTextTrackStyle.fontStyle = [CastUtilities parseFontStyle:fontStyle];
mediaTextTrackStyle.fontStyle = [MLPCastUtilities parseFontStyle:fontStyle];
}
NSString* foregroundColor = data[@"foregroundColor"];
if (fontFamily != nil) {
Expand All @@ -114,7 +111,7 @@ + (GCKMediaTextTrackStyle *)buildTextTrackStyle:(NSDictionary *)data {

NSString* windowType = data[@"windowType"];
if (windowType != nil) {
mediaTextTrackStyle.windowType = [CastUtilities parseWindowType:windowType];
mediaTextTrackStyle.windowType = [MLPCastUtilities parseWindowType:windowType];
}
}
return mediaTextTrackStyle;
Expand All @@ -129,7 +126,7 @@ +(GCKMediaMetadata*)buildMediaMetadata:(NSDictionary*)data {
}
NSData* imagesRaw = data[@"images"];
if (imagesRaw != nil) {
NSArray<GCKImage*>* images = [CastUtilities getMetadataImages:imagesRaw];
NSArray<GCKImage*>* images = [MLPCastUtilities getMetadataImages:imagesRaw];
for (GCKImage* image in images) {
[mediaMetaData addImage:image];
}
Expand All @@ -140,8 +137,8 @@ +(GCKMediaMetadata*)buildMediaMetadata:(NSDictionary*)data {
if ([key isEqualToString:@"metadataType"] || [key isEqualToString:@"images"] || [key isEqualToString:@"type"]) {
continue;
}
NSString* convertedKey = [CastUtilities getiOSMetadataName:key];
NSString* dataType = [CastUtilities getMetadataType:convertedKey];
NSString* convertedKey = [MLPCastUtilities getiOSMetadataName:key];
NSString* dataType = [MLPCastUtilities getMetadataType:convertedKey];
if ([dataType isEqualToString:@"string"]) {
if (data[key]) {
[mediaMetaData setString:data[key] forKey:convertedKey];
Expand Down Expand Up @@ -471,7 +468,7 @@ +(NSString*)getClientMetadataName:(NSString*)iOSName {
}

+ (NSDictionary*)createSessionObject:(GCKCastSession *)session {
return [CastUtilities createSessionObject:session status:@""];
return [MLPCastUtilities createSessionObject:session status:@""];
}

+ (NSDictionary*)createSessionObject:(GCKCastSession *)session status:(NSString*)status {
Expand All @@ -488,10 +485,10 @@ + (NSDictionary*)createSessionObject:(GCKCastSession *)session status:(NSString*
@"muted" : @(session.currentDeviceMuted)
}
};
sessionOut[@"status"] = ![status isEqual: @""]? status : [CastUtilities getConnectionStatus:session.connectionState];
sessionOut[@"status"] = ![status isEqual: @""]? status : [MLPCastUtilities getConnectionStatus:session.connectionState];

NSMutableArray<NSDictionary*>* mediaArray = [[NSMutableArray alloc] init];
NSDictionary* mediaObj = [CastUtilities createMediaObject:session];
NSDictionary* mediaObj = [MLPCastUtilities createMediaObject:session];
if (![mediaObj isEqual: @{}]) {
[mediaArray addObject:mediaObj];
}
Expand Down Expand Up @@ -524,7 +521,7 @@ + (NSDictionary *)createMediaObject:(GCKCastSession *)session {
for (int i=0; i<mediaStatus.queueItemCount; i++) {
item = [mediaStatus queueItemAtIndex:i];
orderID = [[queueOrderIDsByItemId valueForKey:[NSString stringWithFormat:@"%d", item.itemID]] integerValue];
NSDictionary *qItem = [CastUtilities createQueueItem: item orderID:orderID];
NSDictionary *qItem = [MLPCastUtilities createQueueItem: item orderID:orderID];
[qItems addObject:qItem];
}

Expand All @@ -536,21 +533,21 @@ + (NSDictionary *)createMediaObject:(GCKCastSession *)session {
mediaOut[@"isAlive"] = mediaStatus.playerState != GCKMediaPlayerStateIdle? @(YES) : @(NO);
mediaOut[@"items"] = qItems;
mediaOut[@"loadingItemId"] = @(mediaStatus.loadingItemID);
mediaOut[@"media"] = [CastUtilities createMediaInfoObject:mediaStatus.mediaInformation];
mediaOut[@"media"] = [MLPCastUtilities createMediaInfoObject:mediaStatus.mediaInformation];
mediaOut[@"mediaSessionId"] = @(mediaStatus.mediaSessionID);
mediaOut[@"playbackRate"] = @(mediaStatus.playbackRate);
mediaOut[@"playerState"] = [CastUtilities getPlayerState:mediaStatus.playerState];
mediaOut[@"playerState"] = [MLPCastUtilities getPlayerState:mediaStatus.playerState];
mediaOut[@"preloadedItemId"] = @(mediaStatus.preloadedItemID);
mediaOut[@"queueData"] = [CastUtilities createQueueData:mediaStatus] == nil ? NULL : [CastUtilities createQueueData:mediaStatus];
mediaOut[@"repeatMode"] = [CastUtilities getRepeatMode:mediaStatus.queueRepeatMode];
mediaOut[@"queueData"] = [MLPCastUtilities createQueueData:mediaStatus] == nil ? NULL : [MLPCastUtilities createQueueData:mediaStatus];
mediaOut[@"repeatMode"] = [MLPCastUtilities getRepeatMode:mediaStatus.queueRepeatMode];
mediaOut[@"sessionId"] = session.sessionID;
mediaOut[@"volume"] = @{
@"level" : @(mediaStatus.volume),
@"muted" : @(mediaStatus.isMuted),
};

if ([CastUtilities getIdleReason:mediaStatus.idleReason]) {
mediaOut[@"idleReason"] = [CastUtilities getIdleReason:mediaStatus.idleReason];
if ([MLPCastUtilities getIdleReason:mediaStatus.idleReason]) {
mediaOut[@"idleReason"] = [MLPCastUtilities getIdleReason:mediaStatus.idleReason];
}

return [NSDictionary dictionaryWithDictionary:mediaOut];
Expand All @@ -563,7 +560,7 @@ + (NSDictionary *)createQueueItem:(GCKMediaQueueItem *)queueItem orderID:(int)or
returnDict[@"customData"] = (queueItem.customData == nil)? @{} : queueItem.customData;
returnDict[@"itemId"] = @(queueItem.itemID); //[NSNumber numberWithInteger:queueItem.itemID];
returnDict[@"orderId" ] = @(orderID);
returnDict[@"media"] = queueItem.mediaInformation ? [CastUtilities createMediaInfoObject:queueItem.mediaInformation] : @"";
returnDict[@"media"] = queueItem.mediaInformation ? [MLPCastUtilities createMediaInfoObject:queueItem.mediaInformation] : @"";
returnDict[@"startTime"] = (queueItem.startTime == kGCKInvalidTimeInterval || queueItem.startTime != queueItem.startTime) ? @(0.0) : @(queueItem.startTime);
returnDict[@"preloadTime"] = (queueItem.preloadTime == kGCKInvalidTimeInterval || queueItem.preloadTime != queueItem.preloadTime) ? @(0.0) : @(queueItem.preloadTime);
return returnDict;
Expand All @@ -575,7 +572,7 @@ + (NSDictionary*)createQueueData:(GCKMediaStatus*)mediaStatus {
return nil;
}
NSMutableDictionary* returnDict = [[NSMutableDictionary alloc] init];
returnDict[@"repeatMode"] = [CastUtilities getRepeatMode:queueData.repeatMode];
returnDict[@"repeatMode"] = [MLPCastUtilities getRepeatMode:queueData.repeatMode];
returnDict[@"shuffle"] = queueData.repeatMode == GCKMediaRepeatModeAllAndShuffle? @(YES) : @(NO);
returnDict[@"startIndex"] = @(queueData.startIndex);

Expand All @@ -592,10 +589,10 @@ + (NSDictionary *)createMediaInfoObject:(GCKMediaInformation *)mediaInfo {
returnDict[@"contentType"] = mediaInfo.contentType;
returnDict[@"customData"] = mediaInfo.customData == nil ? @{} : mediaInfo.customData;
returnDict[@"duration"] = @(mediaInfo.streamDuration);
returnDict[@"metadata" ] = [CastUtilities createMetadataObject:mediaInfo.metadata];
returnDict[@"streamType"] = [CastUtilities getStreamType:mediaInfo.streamType];
returnDict[@"tracks"] = [CastUtilities getMediaTracks:mediaInfo.mediaTracks];
returnDict[@"textTrackSytle"] = [CastUtilities getTextTrackStyle:mediaInfo.textTrackStyle];
returnDict[@"metadata" ] = [MLPCastUtilities createMetadataObject:mediaInfo.metadata];
returnDict[@"streamType"] = [MLPCastUtilities getStreamType:mediaInfo.streamType];
returnDict[@"tracks"] = [MLPCastUtilities getMediaTracks:mediaInfo.mediaTracks];
returnDict[@"textTrackSytle"] = [MLPCastUtilities getTextTrackStyle:mediaInfo.textTrackStyle];
return returnDict;
}

Expand All @@ -605,17 +602,17 @@ + (NSDictionary*)createMetadataObject:(GCKMediaMetadata*)metadata {
if (!metadata) {
return [NSDictionary dictionaryWithDictionary:outputDict];
}
outputDict[@"images"] = [CastUtilities createImagesArray:metadata.images];
outputDict[@"images"] = [MLPCastUtilities createImagesArray:metadata.images];
outputDict[@"metadataType"] = @(metadata.metadataType);
outputDict[@"type"] = @(metadata.metadataType);

NSArray* keys = metadata.allKeys;
for (NSString* key in keys) {
NSString* outKey = [CastUtilities getClientMetadataName:key];
NSString* outKey = [MLPCastUtilities getClientMetadataName:key];
if ([outKey isEqualToString:key] || [outKey isEqualToString:@"type"]) {
continue;
}
NSString* dataType = [CastUtilities getMetadataType:key];
NSString* dataType = [MLPCastUtilities getMetadataType:key];
if ([dataType isEqualToString:@"string"]) {
outputDict[outKey] = [metadata stringForKey:key];
}
Expand All @@ -633,7 +630,7 @@ + (NSDictionary*)createMetadataObject:(GCKMediaMetadata*)metadata {
}
}
for (NSString* key in keys) {
NSString* outKey = [CastUtilities getClientMetadataName:key];
NSString* outKey = [MLPCastUtilities getClientMetadataName:key];
if (![outKey isEqualToString:key] || [outputDict.allKeys containsObject:outKey] || [outKey isEqualToString:@"type"]) {
continue;
}
Expand Down Expand Up @@ -688,10 +685,10 @@ +(NSArray*)createDeviceArray {
// @"customData": mediaTrack.customData == nil? @{} : mediaTrack.customData,
// @"language": mediaTrack.languageCode == nil? @"" : mediaTrack.languageCode,
// @"name": mediaTrack.name == nil? @"" : mediaTrack.name,
// @"subtype": [CastUtilities getTextTrackSubtype:mediaTrack.textSubtype],
// @"subtype": [MLPCastUtilities getTextTrackSubtype:mediaTrack.textSubtype],
// @"trackContentId": mediaTrack.contentIdentifier == nil ? @"" : mediaTrack.contentIdentifier,
// @"trackContentType": mediaTrack.contentType == nil ? @"" : mediaTrack.contentType,
// @"type": [CastUtilities getTrackType:mediaTrack.type],
// @"type": [MLPCastUtilities getTrackType:mediaTrack.type],
// };
// [tracks addObject:track];
// }
Expand All @@ -709,15 +706,15 @@ + (NSDictionary *)getTextTrackStyle:(GCKMediaTextTrackStyle *)textTrackStyle {
}
textTrackStyleOut[@"customData"] = textTrackStyle.customData == nil? @{} : textTrackStyle.customData;
textTrackStyleOut[@"edgeColor"] = textTrackStyle.edgeColor.CSSString == nil? @"" : textTrackStyle.edgeColor.CSSString;
textTrackStyleOut[@"edgeType"] = [CastUtilities getEdgeType:textTrackStyle.edgeType];
textTrackStyleOut[@"edgeType"] = [MLPCastUtilities getEdgeType:textTrackStyle.edgeType];
textTrackStyleOut[@"fontFamily"] = textTrackStyle.fontFamily;
textTrackStyleOut[@"fontGenericFamily"] = [CastUtilities getFontGenericFamily:textTrackStyle.fontGenericFamily];
textTrackStyleOut[@"fontGenericFamily"] = [MLPCastUtilities getFontGenericFamily:textTrackStyle.fontGenericFamily];
textTrackStyleOut[@"fontScale"] = @(textTrackStyle.fontScale);
textTrackStyleOut[@"fontStyle"] = [CastUtilities getFontStyle:textTrackStyle.fontStyle];
textTrackStyleOut[@"fontStyle"] = [MLPCastUtilities getFontStyle:textTrackStyle.fontStyle];
textTrackStyleOut[@"foregroundColor"] = textTrackStyle.foregroundColor.CSSString;
textTrackStyleOut[@"windowColor"] = textTrackStyle.windowColor.CSSString;
textTrackStyleOut[@"windowRoundedCornerRadius"] = @(textTrackStyle.windowRoundedCornerRadius);
textTrackStyleOut[@"windowType"] = [CastUtilities getWindowType:textTrackStyle.windowType];
textTrackStyleOut[@"windowType"] = [MLPCastUtilities getWindowType:textTrackStyle.windowType];

return textTrackStyleOut;
}
Expand Down
13 changes: 5 additions & 8 deletions src/ios/MLPChromecast.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
//
// Chromecast.h
// MLPChromecast.h
// ChromeCast
//
// Created by mac on 2019/9/30.
//

#import <Foundation/Foundation.h>
#import <GoogleCast/GoogleCast.h>
#import <Cordova/CDV.h>
#import "ChromecastSession.h"
#import "CastUtilities.h"
#import "MLPChromecastSession.h"
#import "MLPCastUtilities.h"

NS_ASSUME_NONNULL_BEGIN

@interface Chromecast : CDVPlugin<GCKDiscoveryManagerListener,GCKLoggerDelegate,CastSessionListener, GCKSessionManagerListener>
@interface MLPChromecast : CDVPlugin<GCKDiscoveryManagerListener,GCKLoggerDelegate,CastSessionListener, GCKSessionManagerListener>

@property (nonatomic, strong) NSMutableArray* devicesAvailable;
@property (nonatomic, strong) ChromecastSession* currentSession;
@property (nonatomic, strong) MLPChromecastSession* currentSession;
@property (nonatomic, strong) CDVInvokedUrlCommand* eventCommand;

- (void)onReset;
Expand Down
Loading

0 comments on commit 35cd482

Please sign in to comment.