YH_SocketService.h 2.17 KB
//
//  YH_SocketService.h
//  Yoho
//
//  Created by Arthur on 16/6/16.
//  Copyright © 2016年 YOHO. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "YH_BarrageViewController.h"
#import "M16Service.h"

typedef NS_ENUM(NSInteger, SOCKET_TAG) {
    SOCKET_TAG_EOR = -1,
    SOCKET_TAG_LOGIN = 1, // 登陆
    SOCKET_TAG_SEND_MSG = 2, // 客户端发消息
    SOCKET_TAG_QUIT = 3, //退出
    SOCKET_TAG_USER_JOIN = 4, //服务器通知新用户加入
    SOCKET_TAG_RESIVE_MSG = 5, //接收弹幕消息
    SOCKET_TAG_HEARTBEAT = 7, //心跳
    SOCKET_TAG_PRAISE = 8, //用户点赞
    SOCKET_TAG_NotifyPRAISE = 9, //服务器通知点赞
    SOCKET_TAG_NotifyPeopleNumber = 10, //服务器通知当前在线人数
    SOCKET_TAG_EndPlay = 11, //结束播放
    SOCKET_TAG_NotifyEndPlay = 12, //服务器通知结束播放
};

@protocol YH_SocketServiceDelegate <NSObject>

- (void)userPraised:(NSString *)currentTotalNum isSelfPraise:(BOOL)isSelf;
- (void)currentPeopleNumber:(NSString *)peopleNumber;
- (void)livePalyEnd:(NSString *)audienceNums likeNums:(NSString *)likeNums videoLen:(NSString *)videoLen;

@end

@interface YH_SocketService : NSObject

@property (nonatomic, strong)  YH_BarrageViewController *barrageViewController;

@property (nonatomic, strong) NSString *uid;
@property (nonatomic, strong) NSString *userName;
@property (nonatomic, strong) NSString *avartar;
@property (nonatomic, strong) NSString *room;
@property (nonatomic, strong) NSString *socketLiveHost;
@property (nonatomic, assign) NSInteger socketLivePort;
@property (nonatomic, assign) id<YH_SocketServiceDelegate> delegate;
@property (nonatomic, strong) NSArray *addressList;


- (BOOL)connect;

//- (BOOL)connectToHost:(NSString*)host onPort:(uint16_t)port;

- (BOOL)writeDataWithParams:(NSDictionary *)params tag:(long)tag;

- (AFHTTPRequestOperation *)barrageList:(NSDictionary *)parameters completionBlock:(ArrayBlock)block;//弹幕服务器地址请求

//登录
- (void)loginToServer;
//发消息
- (void)sendMessage:(NSString *)msg;
//用户点赞
- (void)userPraise;
//结束播放 //只有推流能调用
- (void)endPaly:(NSString *)videoLen;
//登出
-(void)logout;

//手动释放timer
- (void)reset;

@end