Skip to content

Commit

Permalink
Merge pull request #2 from adrianceding/master
Browse files Browse the repository at this point in the history
增加onclose onconnect回调
  • Loading branch information
walkor authored Aug 9, 2017
2 parents 644341d + f50b256 commit 23a2ccb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ class Client
*/
public static $onMessage = null;

/**
* onConnect
* @var callback
*/
public static $onConnect = null;

/**
* onClose
* @var callback
*/
public static $onClose = null;

/**
* Connction to channel server.
* @var TcpConnection
Expand Down Expand Up @@ -129,6 +141,9 @@ public static function onRemoteClose()
self::$_remoteConnection = null;
self::clearTimer();
self::$_reconnectTimer = Timer::add(1, 'Channel\Client::connect', array(self::$_remoteIp, self::$_remotePort));
if (self::$onClose) {
call_user_func(Client::$onClose);
}
}

/**
Expand All @@ -143,6 +158,10 @@ public static function onRemoteConnect()
self::subscribe($all_event_names);
}
self::clearTimer();

if (self::$onConnect) {
call_user_func(Client::$onConnect);
}
}

/**
Expand Down

0 comments on commit 23a2ccb

Please sign in to comment.