mirror of
https://github.com/socketio/socket.io-client-cpp.git
synced 2026-06-10 12:15:44 +00:00
Merge branch 'multiplex' of https://github.com/socketio/socket.io-client-cpp into multiplex
This commit is contained in:
commit
be858b146b
@ -24,12 +24,14 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->setupUi(this);
|
||||
connect(this,SIGNAL(RequestAddListItem(QListWidgetItem*)),this,SLOT(AddListItem(QListWidgetItem*)));
|
||||
connect(this,SIGNAL(RequestToggleInputs(bool)),this,SLOT(ToggleInputs(bool)));
|
||||
_io->set_socket_open_listener(std::bind(&MainWindow::OnConnected,this,std::placeholders::_1));
|
||||
_io->set_socket_close_listener(std::bind(&MainWindow::OnFailed,this));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
_io->socket()->off_all();
|
||||
_io->socket()->clear_listeners();
|
||||
_io->socket()->off_error();
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -107,9 +109,6 @@ void MainWindow::NicknameAccept()
|
||||
BIND_EVENT(sock,"typing",std::bind(&MainWindow::OnTyping,this,_1,_2,_3,_4));
|
||||
BIND_EVENT(sock,"stop typing",std::bind(&MainWindow::OnStopTyping,this,_1,_2,_3,_4));
|
||||
BIND_EVENT(sock,"login",std::bind(&MainWindow::OnLogin,this,_1,_2,_3,_4));
|
||||
sock->set_connect_listener(std::bind(&MainWindow::OnConnected,this));
|
||||
|
||||
sock->set_close_listener(std::bind(&MainWindow::OnFailed,this));
|
||||
_io->connect("ws://localhost:3000");
|
||||
}
|
||||
}
|
||||
@ -230,7 +229,7 @@ void MainWindow::OnLogin(std::string const& name,message::ptr const& data,bool h
|
||||
Q_EMIT RequestAddListItem(item);
|
||||
}
|
||||
|
||||
void MainWindow::OnConnected()
|
||||
void MainWindow::OnConnected(std::string const& nsp)
|
||||
{
|
||||
QByteArray bytes = m_name.toUtf8();
|
||||
std::string nickName(bytes.data(),bytes.length());
|
||||
|
||||
@ -45,7 +45,7 @@ private:
|
||||
void OnTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
|
||||
void OnStopTyping(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
|
||||
void OnLogin(std::string const& name,message::ptr const& data,bool hasAck,message::ptr &ack_resp);
|
||||
void OnConnected();
|
||||
void OnConnected(std::string const& nsp);
|
||||
void OnClosed(client::close_reason const& reason);
|
||||
void OnFailed();
|
||||
void ShowLoginDialog();
|
||||
|
||||
@ -31,6 +31,7 @@ typedef enum MessageFlag
|
||||
NSMutableSet *_typingUsers;
|
||||
NSString* _name;
|
||||
NSInteger _userCount;
|
||||
NSTimer* _inputTimer;
|
||||
}
|
||||
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *typingLabel;
|
||||
@ -139,7 +140,7 @@ void OnLogin(CFTypeRef ctrl, string const& name, sio::message::ptr const& data,
|
||||
}
|
||||
}
|
||||
|
||||
void OnConnected(CFTypeRef ctrl)
|
||||
void OnConnected(CFTypeRef ctrl,std::string nsp)
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[((__bridge CRViewController*)ctrl) onConnected];
|
||||
@ -181,6 +182,7 @@ void OnClose(CFTypeRef ctrl,sio::client::close_reason const& reason)
|
||||
|
||||
-(void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
_io->set_socket_open_listener(std::bind(&OnConnected, (__bridge CFTypeRef)self,std::placeholders::_1));
|
||||
_io->set_close_listener(std::bind(&OnClose, (__bridge CFTypeRef)self, std::placeholders::_1));
|
||||
_io->set_fail_listener(std::bind(&OnFailed, (__bridge CFTypeRef)self));
|
||||
}
|
||||
@ -204,8 +206,8 @@ void OnClose(CFTypeRef ctrl,sio::client::close_reason const& reason)
|
||||
-(void)viewDidDisappear:(BOOL)animated
|
||||
{
|
||||
_io->socket()->off_all();
|
||||
_io->socket()->set_connect_listener(nullptr);
|
||||
_io->socket()->set_close_listener(nullptr);
|
||||
_io->set_open_listener(nullptr);
|
||||
_io->set_close_listener(nullptr);
|
||||
_io->close();
|
||||
}
|
||||
|
||||
@ -336,6 +338,29 @@ void OnClose(CFTypeRef ctrl,sio::client::close_reason const& reason)
|
||||
}
|
||||
}
|
||||
|
||||
-(void) inputTimeout
|
||||
{
|
||||
_inputTimer = nil;
|
||||
_io->socket()->emit("stop typing", "");
|
||||
}
|
||||
|
||||
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
||||
{
|
||||
if(textField == self.messageField)
|
||||
{
|
||||
if(_inputTimer.valid)
|
||||
{
|
||||
[_inputTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
|
||||
}
|
||||
else
|
||||
{
|
||||
_io->socket()->emit("typing", "");
|
||||
_inputTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(inputTimeout) userInfo:nil repeats:NO];
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return [_receivedMessage count];
|
||||
@ -375,22 +400,6 @@ void OnClose(CFTypeRef ctrl,sio::client::close_reason const& reason)
|
||||
}
|
||||
}
|
||||
|
||||
-(void)textFieldDidBeginEditing:(UITextField *)textField
|
||||
{
|
||||
if(textField == self.messageField)
|
||||
{
|
||||
_io->socket()->emit("typing", "");
|
||||
}
|
||||
}
|
||||
|
||||
-(void)textFieldDidEndEditing:(UITextField *)textField
|
||||
{
|
||||
if(textField == self.messageField)
|
||||
{
|
||||
_io->socket()->emit("stop typing", "");
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)textFieldShouldReturn:(UITextField *)textField
|
||||
{
|
||||
if (textField == self.nickName) {
|
||||
@ -401,7 +410,6 @@ void OnClose(CFTypeRef ctrl,sio::client::close_reason const& reason)
|
||||
using std::placeholders::_3;
|
||||
using std::placeholders::_4;
|
||||
socket::ptr socket = _io->socket();
|
||||
socket->set_connect_listener(std::bind(&OnConnected, (__bridge CFTypeRef)self));
|
||||
|
||||
socket->on("new message", std::bind(&OnNewMessage, (__bridge CFTypeRef)self, _1,_2,_3,_4));
|
||||
socket->on("typing", std::bind(&OnTyping, (__bridge CFTypeRef)self, _1,_2,_3,_4));
|
||||
|
||||
@ -217,7 +217,10 @@ void set_##__FIELD__(__TYPE__ const& l) \
|
||||
m_error_listener = nullptr;
|
||||
}
|
||||
|
||||
socket::impl::impl(client_impl *client,std::string const& nsp):m_client(client),m_nsp(nsp)
|
||||
socket::impl::impl(client_impl *client,std::string const& nsp):
|
||||
m_client(client),
|
||||
m_nsp(nsp),
|
||||
m_connected(false)
|
||||
{
|
||||
NULL_GUARD(client);
|
||||
if(m_client->opened())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user