2929
3030static NSString *const MULTI_CONTROL_HOST = @" mc_host" ;
3131
32- static NSString *const MULTI_CONTROL_ACTION = @" action" ;
33-
3432// static NSString *const BEHAVIOR_ID = @"68753A444D6F12269C600050E4C00067";
3533
3634@interface DKMultiControlStreamManager ()
@@ -89,7 +87,7 @@ - (void)enableMultiControlWithUrl:(NSURL *)url {
8987 typeof (weakSelf) self = weakSelf;
9088 if ([commonDTOModel.dataType isEqualToString: MULTI_CONTROL_HOST ]) {
9189 [self changeToSlave ];
92- } else if ([commonDTOModel.dataType isEqualToString: MULTI_CONTROL_ACTION ]) {
90+ } else if ([commonDTOModel.dataType isEqualToString: DK_ACTION ]) {
9391 // Handle behaviorId and process data.
9492 NSData *jsonData = [commonDTOModel.data dataUsingEncoding: NSUTF8StringEncoding];
9593 if (jsonData) {
@@ -103,6 +101,8 @@ - (void)enableMultiControlWithUrl:(NSURL *)url {
103101 }
104102 }
105103 }
104+ } else if ([commonDTOModel.dataType isEqualToString: DK_TCP ]) {
105+ self.tcpHandler ? self.tcpHandler (commonDTOModel.data ) : nil ;
106106 }
107107 };
108108 for (id <DKMultiControlStreamManagerStateListener> listener in self.listenerArray ) {
@@ -395,4 +395,28 @@ - (void)broadcastWithActionMessage:(NSString *)message {
395395 [self .webSocketSession sendString: dataString requestId: nil completionHandler: nil ];
396396}
397397
398+ - (void )broadcastWithTCPMessage : (NSString *)message {
399+ if (!self.webSocketSession ) {
400+ return ;
401+ }
402+ DKCommonDTOModel *commonDTOModel = [[DKCommonDTOModel alloc ] init ];
403+ commonDTOModel.requestId = nil ;
404+ commonDTOModel.deviceType = DK_DEVICE_TYPE ;
405+ commonDTOModel.data = message;
406+ commonDTOModel.method = DK_WEBSOCKET_BROADCAST ;
407+ commonDTOModel.connectSerial = self.webSocketSession .sessionUUID ;
408+ commonDTOModel.dataType = DK_ACTION ;
409+ NSError *error = nil ;
410+ NSDictionary *jsonDictionary = [MTLJSONAdapter JSONDictionaryFromModel: commonDTOModel error: &error];
411+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject: jsonDictionary ?: @{} options: 0 error: &error];
412+ NSString *dataString = nil ;
413+ if (jsonData) {
414+ dataString = [[NSString alloc ] initWithData: jsonData encoding: NSUTF8StringEncoding];
415+ }
416+ if (!dataString) {
417+ return ;
418+ }
419+ [self .webSocketSession sendString: dataString requestId: nil completionHandler: nil ];
420+ }
421+
398422@end
0 commit comments