基于socket.io即时通讯IM实现,webRTC实现视频通话

Socket.io-FLSocketIM-iOS

基于Socket.io iOS即时通讯客户端 iOS IM Client based on Socket.io
iOS 代码地址:https://github.com/fengli12321/Socket.io-FLSocketIM-iOS
服务器端代码实现参照:https://github.com/githuanl/node.js-socket.io-server
安卓端代码实现参照:https://github.com/githuanl/socket.io-android-

实现功能

  1. 文本发送
  2. 图片发送(从相册选取,或者拍摄)
  3. 短视频
  4. 语音发送
  5. 视频通话
  6. 其他一些效果(类似QQ底部tabBar,短视频拍摄等)
  7. 功能扩展中。。。。。

先看看实际效果

文字.gif

图片.gif

定位.gif

语音.gif

IMG_1227.PNG

使用技术

一、socket.io

github地址

socket.io是该项目实现即时通讯关键所在,非常强大;
Socket.io将Websocket和轮询 (Polling)机制以及其它的实时通信方式封装成了通用的接口,并且在服务端实现了这些实时机制的相应代码。

先上代码

1.创建socket连接,通过单例管理类FLSocketManager实现
- (void)connectWithToken:(NSString *)token success:(void (^)())success fail:(void (^)())fail {


    NSURL* url = [[NSURL alloc] initWithString:BaseUrl];

    /**
     log 是否打印日志
     forceNew      这个参数设为NO从后台恢复到前台时总是重连,暂不清楚原因
     forcePolling  是否强制使用轮询
     reconnectAttempts 重连次数,-1表示一直重连
     reconnectWait 重连间隔时间
     connectParams 参数
     forceWebsockets 是否强制使用websocket, 解释The reason it uses polling first is because some firewalls/proxies block websockets. So polling lets socket.io work behind those.
     来源:https://github.com/socketio/socket.io-client-swift/issues/449
     */
    SocketIOClient* socket;
    if (!self.client) {
        socket = [[SocketIOClient alloc] initWithSocketURL:url config:@{@"log": @NO, @"forceNew" : @YES, @"forcePolling": @NO, @"reconnectAttempts":@(-1), @"reconnectWait" : @4, @"connectParams": @{@"auth_token" : token}, @"forceWebsockets" : @NO}];
    }
    else {
        socket = self.client;
        socket.engine.connectParams = @{@"auth_token" : token};
    }


    // 连接超时时间设置为15秒
    [socket connectWithTimeoutAfter:15 withHandler:^{

        fail();
    }];

    // 监听一次连接成功
    [socket once:@
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值