YBSocketPlay.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. //
  2. // YBSocketPlay.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/11/29.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBSocketPlay.h"
  9. #import <SocketIO/SocketIO-Swift.h>
  10. @interface YBSocketPlay()
  11. {
  12. NSDictionary *_hostDic;
  13. }
  14. @property(nonatomic,strong)SocketManager *socketManager;
  15. @property(nonatomic,strong)SocketIOClient *socketClient;
  16. @end
  17. @implementation YBSocketPlay
  18. static YBSocketPlay*playSocketManeger = nil;
  19. +(instancetype)playSocketManeger {
  20. static dispatch_once_t onceToken;
  21. dispatch_once(&onceToken, ^{
  22. playSocketManeger = [[super allocWithZone:NULL]init];
  23. });
  24. return playSocketManeger;
  25. }
  26. +(instancetype)allocWithZone:(struct _NSZone *)zone {
  27. return [self playSocketManeger];
  28. }
  29. #pragma mark - 进房间、连socket
  30. -(void)enterRoomAndConnectSocket:(NSDictionary *)conDic complete:(SocketPlayBlock)complete {
  31. //列表上传递的主播信息
  32. _hostDic = conDic;
  33. YBWeakSelf;
  34. NSDictionary *postDic = @{@"liveuid":minstr([_hostDic valueForKey:@"uid"]),@"stream":minstr([_hostDic valueForKey:@"stream"])};
  35. [YBNetworking postWithUrl:@"Live.enterRoom" Dic:postDic Suc:^(int code, id info, NSString *msg) {
  36. if (code == 0) {
  37. NSDictionary *infoDic = [info firstObject];
  38. [weakSelf playConnectSocket:infoDic];
  39. if (complete) {
  40. complete(@"0",infoDic);
  41. }
  42. }else {
  43. if (complete) {
  44. complete(msg,@{});
  45. }
  46. }
  47. } Fail:^(id fail) {
  48. if (complete) {
  49. complete(YZMsg(@"进入房间失败"),@{});
  50. }
  51. }];
  52. }
  53. -(void)playConnectSocket:(NSDictionary *)conDic{
  54. NSMutableDictionary *m_dic = [NSMutableDictionary dictionaryWithDictionary:conDic];
  55. [m_dic addEntriesFromDictionary:_hostDic];
  56. //列表传递主播信息+enterroom返回的信息合并
  57. _hostDic = [NSDictionary dictionaryWithDictionary:m_dic];
  58. NSString *socketUrl = minstr([_hostDic valueForKey:@"chatserver"]);
  59. NSString *liveStream = minstr([_hostDic valueForKey:@"stream"]);
  60. _socketManager = [[SocketManager alloc]initWithSocketURL:[NSURL URLWithString:socketUrl] config:@{@"log": @NO, @"compress": @YES}];
  61. _socketClient = _socketManager.defaultSocket;
  62. NSArray *cur = @[@{@"username":[Config getOwnNicename],
  63. @"uid":[Config getOwnID],
  64. @"token":[Config getOwnToken],
  65. @"roomnum":minstr([_hostDic valueForKey:@"uid"]),
  66. @"stream":liveStream,
  67. @"lang":[YBLanguageTools serviceLang],
  68. }];
  69. [_socketClient connect];
  70. [_socketClient on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
  71. [_socketClient emit:@"conn" with:cur];
  72. NSLog(@"socket链接");
  73. }];
  74. [_socketClient on:@"disconnect" callback:^(NSArray* data, SocketAckEmitter* ack) {
  75. NSLog(@"socket.io disconnect---%@",data);
  76. }];
  77. [_socketClient on:@"error" callback:^(NSArray* data, SocketAckEmitter* ack) {
  78. NSLog(@"socket.io error -- %@",data);
  79. }];
  80. [_socketClient on:@"conn" callback:^(NSArray* data, SocketAckEmitter* ack) {
  81. NSLog(@"进入房间");
  82. }];
  83. YBWeakSelf;
  84. [_socketClient on:@"broadcastingListen" callback:^(NSArray* data, SocketAckEmitter* ack) {
  85. /*
  86. if ([[data[0] firstObject] isEqual:@"stopplay"]) {
  87. if (weakSelf.roomCloseByAdmin) {
  88. weakSelf.roomCloseByAdmin(@"用户-超管关播", @{});
  89. }
  90. return ;
  91. }
  92. */
  93. for (NSString *path in data[0]) {
  94. NSDictionary *jsonArray = [path JSONValue];
  95. NSDictionary *msg = [[jsonArray valueForKey:@"msg"] firstObject];
  96. NSString *retcode = [NSString stringWithFormat:@"%@",[jsonArray valueForKey:@"retcode"]];
  97. NSString *method = [msg valueForKey:@"_method_"];
  98. if ([retcode isEqual:@"409002"]) {
  99. [MBProgressHUD showError:YZMsg(@"你已被禁言")];
  100. return;
  101. }
  102. [weakSelf getmessage:msg andMethod:method];
  103. }
  104. }];
  105. }
  106. -(void)getmessage:(NSDictionary *)msg andMethod:(NSString *)method{
  107. NSLog(@"收到socekt:%@",msg);
  108. if ([method isEqual:Soc_SendMsg]) {
  109. //文本消息
  110. NSString *msgtype = minstr([msg valueForKey:@"msgtype"]);
  111. NSString *action = minstr([msg valueForKey:@"action"]);
  112. if([msgtype isEqual:@"2"]) {
  113. //默认-聊天消息
  114. NSString *titleColor = @"0";
  115. NSString *ct = minstr([msg valueForKey:@"ct"]);
  116. if ([lagType isEqual:EN] && ![PublicObj checkNull:minstr([msg valueForKey:@"ct_en"])]) {
  117. ct = minstr([msg valueForKey:@"ct_en"]);
  118. }
  119. NSString *uname = minstr([msg valueForKey:@"uname"]);
  120. NSString *uid = minstr([msg valueForKey:@"uid"]);
  121. NSString *userType = minstr([msg valueForKey:@"usertype"]);
  122. NSString *guardType = minstr([msg valueForKey:@"guard_type"]);
  123. NSString *isAnchor = @"0";
  124. if (![PublicObj checkNull:minstr([msg valueForKey:@"heart"])]) {
  125. //说明是点亮消息
  126. titleColor = [@"light" stringByAppendingFormat:@"%@",[msg valueForKey:@"heart"]];
  127. if (self.userLight) {
  128. self.userLight(@"用户-用户点亮", @{});
  129. }
  130. }
  131. NSDictionary *chatDic = @{@"userName":uname,
  132. @"contentChat":ct,
  133. @"id":uid,
  134. @"titleColor":titleColor,
  135. @"usertype":userType,
  136. @"isAnchor":isAnchor,
  137. @"guard_type":guardType,
  138. };
  139. if (self.userSendMsg) {
  140. self.userSendMsg(@"用户-收到发言", chatDic);
  141. }
  142. }
  143. if([msgtype isEqual:@"0"]) {
  144. NSString *action = minstr([msg valueForKey:@"action"]);
  145. if ([action isEqual:@"1"] && self.userLeave) {
  146. //用户离开.离开的用户 id 在 ct 里边 'id'
  147. self.userLeave(@"用户-用户离开", msg);
  148. }
  149. if ([action isEqual:@"0"] && self.userEnter) {
  150. //用户进入.离开的用户 id 在 ct 里边 'id'
  151. self.userEnter(@"用户-用户进入", msg);
  152. }
  153. }
  154. if ([msgtype isEqual:@"1"] && [action isEqual:@"18"]) {
  155. if (self.liveOff) {
  156. self.liveOff(@"用户-直播关闭", @{});
  157. }
  158. }
  159. }
  160. else if ([method isEqual:Soc_SystemNot] || [method isEqual:Soc_ShutUpUser]){
  161. //系统消息、禁言
  162. NSString *msgtype = minstr([msg valueForKey:@"msgtype"]);
  163. NSString *action = minstr([msg valueForKey:@"action"]);
  164. NSString *touid = minstr([msg valueForKey:@"touid"]);
  165. NSString *showCt = minstr([msg valueForKey:@"ct"]);
  166. if ([lagType isEqual:EN] && ![PublicObj checkNull:minstr([msg valueForKey:@"ct_en"])]) {
  167. showCt = minstr([msg valueForKey:@"ct_en"]);
  168. }
  169. if([msgtype isEqual:@"4"] && [action isEqual:@"13"] && [touid isEqual:[Config getOwnID]]) {
  170. //关注
  171. [self showAlert:showCt];
  172. }
  173. if ([msgtype isEqual:@"4"] && [action isEqual:@"1"] && [touid isEqual:[Config getOwnID]]){
  174. //禁言
  175. [self showAlert:showCt];
  176. }
  177. NSDictionary *chatDic = @{@"userName":YZMsg(@"直播间消息"),
  178. @"contentChat":showCt,
  179. @"id":@"",
  180. @"titleColor":@"firstlogin",
  181. @"usertype":@"",
  182. @"isAnchor":@"0",
  183. };
  184. if (self.systemMsg) {
  185. self.systemMsg(@"用户-系统消息", chatDic);
  186. }
  187. }
  188. else if ([method isEqual:Soc_setAdmin]){
  189. NSString *msgtype = minstr([msg valueForKey:@"msgtype"]);
  190. NSString *touid = minstr([msg valueForKey:@"touid"]);
  191. NSString *usertype = @"";
  192. NSString *showCt = minstr([msg valueForKey:@"ct"]);
  193. if ([lagType isEqual:EN] && ![PublicObj checkNull:minstr([msg valueForKey:@"ct_en"])]) {
  194. showCt = minstr([msg valueForKey:@"ct_en"]);
  195. }
  196. if ([msgtype isEqual:@"1"] && [touid isEqual:[Config getOwnID]]) {
  197. //设置-取消管理
  198. [self showAlert:showCt];
  199. }
  200. if ([touid isEqual:[Config getOwnID]]) {
  201. if ([minstr([msg valueForKey:@"action"]) isEqual:@"0"]) {
  202. usertype = @"0";
  203. }else {
  204. usertype = @"40";
  205. }
  206. }
  207. NSDictionary *chatDic = @{@"userName":YZMsg(@"直播间消息"),
  208. @"contentChat":showCt,
  209. @"id":@"",
  210. @"titleColor":@"firstlogin",
  211. @"usertype":usertype,
  212. @"isAnchor":@"0",
  213. };
  214. if (self.setAdmin) {
  215. self.setAdmin(@"用户-管理员", chatDic);
  216. }
  217. }
  218. else if ([method isEqual:Soc_KickUser]){
  219. NSString *touid = minstr([msg valueForKey:@"touid"]);
  220. if ([touid isEqual:[Config getOwnID]] && self.kickUser) {
  221. self.kickUser(@"用户-被踢", @{});
  222. [self showAlert:YZMsg(@"你已被踢出房间")];
  223. }
  224. NSString *showCt = minstr([msg valueForKey:@"ct"]);
  225. if ([lagType isEqual:EN] && ![PublicObj checkNull:minstr([msg valueForKey:@"ct_en"])]) {
  226. showCt = minstr([msg valueForKey:@"ct_en"]);
  227. }
  228. NSDictionary *chatDic = @{@"userName":YZMsg(@"直播间消息"),
  229. @"contentChat":showCt,
  230. @"id":@"",
  231. @"titleColor":@"firstlogin",
  232. @"usertype":@"",
  233. @"isAnchor":@"0",
  234. };
  235. if (self.systemMsg) {
  236. self.systemMsg(@"用户-踢人消息", chatDic);
  237. }
  238. }
  239. else if ([method isEqual:Soc_SendGift]){
  240. //送礼物
  241. if ([minstr([msg valueForKey:@"ifpk"]) isEqual:@"1"] && self.linkPKProgress) {
  242. self.linkPKProgress(@"用户-PK进度", msg);
  243. }
  244. if (self.sendGift && [minstr([msg valueForKey:@"roomnum"]) isEqual:minstr([_hostDic valueForKey:@"uid"])]) {
  245. self.sendGift(@"用户-收到礼物", msg);
  246. }
  247. }
  248. else if ([method isEqual:Soc_light]){
  249. //点亮
  250. NSString *msgtype = [msg valueForKey:@"msgtype"];
  251. NSString *action = [msg valueForKey:@"action"];
  252. if([msgtype isEqual:@"0"] && [action isEqual:@"2"] && self.userLight){
  253. self.userLight(@"用户-用户点亮", @{});
  254. }
  255. }
  256. else if ([method isEqual:Soc_stopLive]){
  257. //超管关播
  258. if (self.roomCloseByAdmin) {
  259. self.roomCloseByAdmin(@"用户-超管关播", @{});
  260. }
  261. }
  262. else if ([method isEqual:Soc_StartEndLive]){
  263. //直播结束
  264. NSString *action = minstr([msg valueForKey:@"action"]);
  265. if (self.liveOff && [action isEqual:@"18"]) {
  266. self.liveOff(@"用户-直播关闭", @{});
  267. }
  268. }
  269. else if ([method isEqual:Soc_disconnect]){
  270. //断开链接
  271. if (self.userLeave) {
  272. //用户离开.离开的用户 id 在 ct 里边 'id'
  273. self.userLeave(@"用户-用户离开", msg);
  274. }
  275. }
  276. else if ([method isEqual:Soc_goodsLiveShow]){
  277. //在售商品 action:1-展示 0-隐藏
  278. if (self.onSaleMsg) {
  279. self.onSaleMsg(@"用户-在售", msg);
  280. }
  281. }
  282. else if ([method isEqual:Soc_BuyGuard]){
  283. //购买守护
  284. if (self.buyGuardMsg) {
  285. self.buyGuardMsg(@"用户-买守护", msg);
  286. }
  287. NSDictionary *chatDic = @{@"userName":YZMsg(@"直播间消息"),
  288. @"contentChat":[NSString stringWithFormat:@"%@ %@",[msg valueForKey:@"uname"],YZMsg(@"守护了主播")],
  289. @"id":@"",
  290. @"titleColor":@"firstlogin",
  291. @"usertype":@"",
  292. @"isAnchor":@"0",
  293. };
  294. if (self.systemMsg) {
  295. self.systemMsg(@"用户-系统消息", chatDic);
  296. }
  297. }
  298. else if ([method isEqual:Soc_ConnectVideo]){
  299. //用户-主播连麦
  300. int action = [minstr([msg valueForKey:@"action"]) intValue];
  301. // 1 有人发送连麦请求 2 主播接受连麦 3 主播拒绝连麦 4 用户推流,发送自己的播流地址 5 用户断开连麦 6 主播断开连麦 7 主播正忙碌 8 主播无响应
  302. NSString *touid = minstr([msg valueForKey:@"touid"]);
  303. switch (action) {
  304. case 2:{
  305. if (self.linkHostAgree && [touid isEqual:[Config getOwnID]]) {
  306. self.linkHostAgree(@"用户-主播同意", msg);
  307. }
  308. }break;
  309. case 3:{
  310. if (self.linkHostUnAgree && [touid isEqual:[Config getOwnID]]) {
  311. [MBProgressHUD showPop:YZMsg(@"主播拒绝了您的连麦请求")];
  312. self.linkHostUnAgree(@"用户-主播拒绝", msg);
  313. }
  314. }break;
  315. case 4:{ /* 连麦混流的方式用户端不用处理此 action */ }break;
  316. case 5:{
  317. if (![minstr([msg valueForKey:@"uid"]) isEqual:[Config getOwnID]]) {
  318. [MBProgressHUD showPop:[NSString stringWithFormat:@"%@%@",[msg valueForKey:@"uid"],YZMsg(@"已下麦")]];
  319. }
  320. }break;
  321. case 6:{
  322. if (self.linkHostDisconnect) {
  323. self.linkHostDisconnect(@"用户-主播下麦用户", msg);
  324. }
  325. if ([touid isEqual:[Config getOwnID]]) {
  326. [MBProgressHUD showPop:YZMsg(@"主播已把您下麦")];
  327. }else {
  328. [MBProgressHUD showPop:[NSString stringWithFormat:@"%@%@",touid,YZMsg(@"已下麦")]];
  329. }
  330. }break;
  331. case 7:{
  332. if (self.linkHostBusy && [touid isEqual:[Config getOwnID]]) {
  333. self.linkHostBusy(@"用户-主播忙碌", msg);
  334. [MBProgressHUD showPop:YZMsg(@"主播正忙碌")];
  335. }
  336. }break;
  337. case 8:{
  338. if (self.linkHostTimeout && [touid isEqual:[Config getOwnID]]) {
  339. self.linkHostTimeout(@"用户-主播超时", msg);
  340. [MBProgressHUD showPop:YZMsg(@"当前主播暂时无法接通")];
  341. }
  342. }break;
  343. default:
  344. break;
  345. }
  346. }
  347. else if ([method isEqual:Soc_LiveConnect]){
  348. //主播-主播连麦
  349. int action = [minstr([msg valueForKey:@"action"]) intValue];
  350. //1:发起连麦;2;接受连麦;3:拒绝连麦;4:连麦成功通知;5.手动断开连麦;7:对方正忙碌 8:对方无响应
  351. switch (action) {
  352. case 4:{
  353. if (self.linkHostToHostStart) {
  354. self.linkHostToHostStart(@"用户-主播和主播开始", msg);
  355. }
  356. }break;
  357. case 5:{
  358. if (self.linkHostToHostDisconnect) {
  359. self.linkHostToHostDisconnect(@"用户-主播和主播结束", msg);
  360. }
  361. }break;
  362. default:
  363. break;
  364. }
  365. }
  366. else if ([method isEqual:Soc_LivePK]){
  367. //1:发起PK;2;接受PK;3:拒绝PK;4:PK成功通知;5.;7:对方正忙碌 8:对方无响应 9:PK结果
  368. int action = [minstr([msg valueForKey:@"action"]) intValue];
  369. switch (action) {
  370. case 4:{
  371. if (self.linkPKSuc) {
  372. self.linkPKSuc(@"用户-PK开始", msg);
  373. }
  374. }break;
  375. case 9:{
  376. if (self.linkPKResult) {
  377. self.linkPKResult(@"用户-PK结果", msg);
  378. }
  379. }break;
  380. default:
  381. break;
  382. }
  383. }
  384. }
  385. //提示框
  386. -(void)showAlert:(NSString *)msg;{
  387. NSDictionary *contentDic = @{
  388. @"title":YZMsg(@"提示"),
  389. @"msg":msg,
  390. @"left":@"",
  391. @"right":YZMsg(@"确定")
  392. };
  393. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  394. }];
  395. }
  396. #pragma mark - socket 断开
  397. -(void)playDisconnectSocket {
  398. [_socketClient disconnect];
  399. [_socketClient off:@""];
  400. [_socketClient leaveNamespace];
  401. _socketClient = nil;
  402. _socketManager = nil;
  403. }
  404. #pragma mark - 发送公屏聊天
  405. -(void)playSendMsg:(NSString *)eventStr otherDic:(NSDictionary *)otherDic {
  406. NSArray *msgData =@[
  407. @{
  408. @"msg": @[
  409. @{
  410. @"_method_":Soc_SendMsg,
  411. @"action":@"0",
  412. @"ct":eventStr,
  413. @"msgtype":@"2",
  414. @"isAnchor":@"0",
  415. @"uid":[Config getOwnID],
  416. @"uname":[Config getOwnNicename],
  417. @"usertype":minstr([otherDic valueForKey:@"usertype"]),
  418. @"guard_type":minstr([otherDic valueForKey:@"guard_type"]),
  419. }
  420. ],
  421. @"retcode":@"000000",
  422. @"retmsg":@"OK"
  423. }
  424. ];
  425. [_socketClient emit:@"broadcast" with:msgData];
  426. }
  427. #pragma mark - /** 点亮 */
  428. -(void)playSendLight:(NSString *)userType otherDic:(NSDictionary *)otherDic{
  429. NSInteger random = arc4random()%5;
  430. NSString *num = [NSString stringWithFormat:@"%ld",(long)random];
  431. NSArray *msgData =@[
  432. @{
  433. @"msg": @[
  434. @{
  435. @"_method_": Soc_SendMsg,
  436. @"action": @"0",
  437. @"ct": @"我点亮了",
  438. @"ct_en": @"I'm lighted",
  439. @"msgtype": @"2",
  440. @"uid": [Config getOwnID],
  441. @"uname": [Config getOwnNicename],
  442. @"usertype":userType,
  443. @"heart":num,
  444. @"guard_type":minstr([otherDic valueForKey:@"guard_type"]),
  445. }
  446. ],
  447. @"retcode": @"000000",
  448. @"retmsg": @"OK"
  449. }
  450. ];
  451. [_socketClient emit:@"broadcast" with:msgData];
  452. }
  453. #pragma mark - /** 送礼物 */
  454. -(void)playSendGift:(NSDictionary *)giftDic;{
  455. NSArray *msgData =@[
  456. @{
  457. @"msg": @[
  458. @{
  459. @"_method_": Soc_SendGift,
  460. @"action": @"0",
  461. @"ct":minstr([giftDic valueForKey:@"gifttoken"]),
  462. @"msgtype": @"1",
  463. @"uid": [Config getOwnID],
  464. @"uname": [Config getOwnNicename],
  465. @"evensend":minstr([giftDic valueForKey:@"lianfa"]),
  466. @"uhead":minstr([giftDic valueForKey:@"avatar"]),
  467. @"paintedPath":[giftDic valueForKey:@"paintedPath"], //数组
  468. @"paintedWidth":[giftDic valueForKey:@"paintedWidth"], //对象
  469. @"paintedHeight":[giftDic valueForKey:@"paintedHeight"], //对象
  470. }
  471. ],
  472. @"retcode": @"000000",
  473. @"retmsg": @"OK"
  474. }
  475. ];
  476. [_socketClient emit:@"broadcast" with:msgData];
  477. }
  478. #pragma mark - /** 主播、管理踢人 */
  479. -(void)playSendKickUser:(NSDictionary *)kickDic {
  480. NSString *ct = [NSString stringWithFormat:@"%@ %@",[kickDic valueForKey:@"touname"],@"被踢出房间"];
  481. NSString *ct_en = [NSString stringWithFormat:@"%@ %@",[kickDic valueForKey:@"touname"],@"kicked out of room"];
  482. NSArray* msgData = @[
  483. @{
  484. @"msg":
  485. @[@{
  486. @"_method_":Soc_KickUser,
  487. @"action":@"2",
  488. @"ct":ct,
  489. @"ct_en":ct_en,
  490. @"uid":[Config getOwnID],
  491. @"uname":[Config getOwnNicename],
  492. @"touid":minstr([kickDic valueForKey:@"touid"]),
  493. @"touname":minstr([kickDic valueForKey:@"touname"]),
  494. @"msgtype":@"4",
  495. }],
  496. @"retcode":@"000000",
  497. @"retmsg":@"OK"}];
  498. [MBProgressHUD showError:YZMsg(@"踢人成功")];
  499. [_socketClient emit:@"broadcast" with:msgData];
  500. }
  501. #pragma mark - /** 主播、管理员禁言 */
  502. -(void)playSendShutUpUser:(NSDictionary *)shutUpDic {
  503. NSString *type = minstr([shutUpDic valueForKey:@"type"]);
  504. NSString *touname = minstr([shutUpDic valueForKey:@"touname"]);
  505. NSString *msg = [NSString stringWithFormat:@"%@ %@",touname,@"被本场禁言"];
  506. NSString *msg_en = [NSString stringWithFormat:@"%@ %@",touname,@"has been shup up in this live stream"];
  507. if ([type isEqual:@"0"]) {
  508. msg = [NSString stringWithFormat:@"%@ %@",touname,@"被永久禁言"];
  509. msg_en = [NSString stringWithFormat:@"%@ %@",touname,@"shut up permanently"];
  510. }
  511. NSArray *msgData = @[
  512. @{
  513. @"msg":
  514. @[@{
  515. @"_method_":Soc_ShutUpUser,
  516. @"action":@"1",
  517. @"ct":msg,
  518. @"ct_en":msg_en,
  519. @"uid":[Config getOwnID],
  520. @"uname":[Config getOwnNicename],
  521. @"touid":minstr([shutUpDic valueForKey:@"touid"]),
  522. @"touname":touname,
  523. @"msgtype":@"4",
  524. }],
  525. @"retcode":@"000000",
  526. @"retmsg":@"OK"}];
  527. [MBProgressHUD showError:YZMsg(@"禁言成功")];
  528. [_socketClient emit:@"broadcast" with:msgData];
  529. }
  530. #pragma mark - /** 关注主播 */
  531. -(void)playSendAttention {
  532. NSString *msg = [NSString stringWithFormat:@"%@ %@",[Config getOwnNicename],@"关注了主播"];
  533. NSString *msg_en = [NSString stringWithFormat:@"%@ %@",[Config getOwnNicename],@"followed the anchor"];
  534. NSArray *msgData = @[
  535. @{
  536. @"msg":
  537. @[@{
  538. @"_method_":Soc_SystemNot,
  539. @"action":@"13",
  540. @"ct":msg,
  541. @"ct_en":msg_en,
  542. @"uid":[Config getOwnID],
  543. @"uname":[Config getOwnNicename],
  544. @"msgtype":@"4",
  545. }],
  546. @"retcode":@"000000",
  547. @"retmsg":@"OK"}];
  548. [_socketClient emit:@"broadcast" with:msgData];
  549. }
  550. #pragma mark - /** 超管关播 */
  551. -(void)playSendStopLive:(NSString *)ct {
  552. NSArray *msgData =@[
  553. @{
  554. @"msg": @[
  555. @{
  556. @"_method_":Soc_stopLive,
  557. @"action": @"19",
  558. @"ct":ct,
  559. @"msgtype": @"1",
  560. }
  561. ],
  562. @"retcode": @"000000",
  563. @"retmsg": @"OK"
  564. }
  565. ];
  566. [_socketClient emit:@"broadcast" with:msgData];
  567. }
  568. #pragma mark - /** 购买守护 */
  569. -(void)playSendBuyGuardSuc:(NSDictionary *)guardInfo{
  570. NSArray *msgData =@[
  571. @{
  572. @"msg": @[
  573. @{
  574. @"_method_": Soc_BuyGuard,
  575. @"action":@"0",
  576. @"msgtype": @"0",
  577. @"ct":YZMsg(@"守护了主播"),
  578. @"uid":[Config getOwnID],
  579. @"uname":[Config getOwnNicename],
  580. @"uhead":[Config getUserAvatar],
  581. @"votestotal":minstr([guardInfo valueForKey:@"votestotal"]),
  582. @"guard_nums":minstr([guardInfo valueForKey:@"guard_nums"])
  583. }
  584. ],
  585. @"retcode": @"000000",
  586. @"retmsg": @"OK"
  587. }
  588. ];
  589. [_socketClient emit:@"broadcast" with:msgData];
  590. }
  591. #pragma mark - /** 用户-主播连麦 */
  592. /*
  593. 1 有人发送连麦请求
  594. 2 主播接受连麦
  595. 3 主播拒绝连麦
  596. 4 用户推流,发送自己的播流地址
  597. 5 用户断开连麦
  598. 6 主播断开连麦
  599. 7 主播正忙碌
  600. 8 主播无响应
  601. */
  602. -(void)playSendUserHostLink{
  603. NSArray *msgData =@[
  604. @{
  605. @"msg": @[
  606. @{
  607. @"_method_": Soc_ConnectVideo,
  608. @"action":@"1",
  609. @"msgtype": @"10",
  610. @"uid":[Config getOwnID],
  611. @"uname":[Config getOwnNicename],
  612. @"uhead":[Config getUserAvatar],
  613. @"sex":[Config getUserSex]
  614. }
  615. ],
  616. @"retcode": @"000000",
  617. @"retmsg": @"OK"
  618. }
  619. ];
  620. [_socketClient emit:@"broadcast" with:msgData];
  621. }
  622. -(void)playSendUserLinkUrl:(NSString *)linkUrl; {
  623. NSArray *msgData =@[
  624. @{
  625. @"msg": @[
  626. @{
  627. @"_method_": Soc_ConnectVideo,
  628. @"action":@"4",
  629. @"msgtype": @"10",
  630. @"uid":[Config getOwnID],
  631. @"uname":[Config getOwnNicename],
  632. @"playurl":linkUrl,
  633. }
  634. ],
  635. @"retcode": @"000000",
  636. @"retmsg": @"OK"
  637. }
  638. ];
  639. [_socketClient emit:@"broadcast" with:msgData];
  640. }
  641. -(void)playSendUserDisconnect; {
  642. NSArray *msgData =@[
  643. @{
  644. @"msg": @[
  645. @{
  646. @"_method_": Soc_ConnectVideo,
  647. @"action":@"5",
  648. @"msgtype": @"10",
  649. @"uid":[Config getOwnID],
  650. @"uname":[Config getOwnNicename]
  651. }
  652. ],
  653. @"retcode": @"000000",
  654. @"retmsg": @"OK"
  655. }
  656. ];
  657. [_socketClient emit:@"broadcast" with:msgData];
  658. }
  659. @end