我最近在我的laravel
安装上安装了Ratchet,以便通过套接字启用推送服务。
这就是我的SocketController类的样子(注意:它不会扩展控制器)
class SocketController implements WampServerInterface
{
/**
* A lookup of all the topics clients have subscribed to
*/
protected $subscribedTopics = array();
public function onSubscribe(ConnectionInterface $conn, $topic) {
echo"\n SUBSCRING TOPIC: $topic";
echo " hi \n";
try {
JWTAuth::parseToken("okay");
} catch (TokenExpiredException $e) {
echo "hi" ;
} catch (TokenInvalidException $e) {
echo "hi" ;
} catch (JWTException $e) {
echo "hi" ;
}
catch(\Exception $q){
echo $q;
}
$this->subscribedTopics[$topic->getId()] = $topic;
}
/**
* @param string JSON'ified string we'll receive from ZeroMQ
*/
public function onBlogEntry($entry) {
$entryData = json_decode($entry, true);
// If the lookup topic object isn't set there is no one to publish to
if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
return;
}
$topic = $this->subscribedTopics[$entryData['category']];
// re-send the data to all the clients subscribed to that category
$topic->broadcast(rand(5,666666));
}
public function onUnSubscribe(ConnectionInterface $conn, $topic) {
}
public function onOpen(ConnectionInterface $conn) {
echo"open";
}
public function onClose(ConnectionInterface $conn) {
echo "close";
}
/* The rest of our methods were as they were, omitted from docs to save space */
/**
* If there is an error with one of the sockets, or somewhere in the application where an Exception is thrown,
* the Exception is sent back down the stack, handled by the Server and bubbled back up the application through this method
* @param ConnectionInterface $conn
* @param \Exception $e
* @throws \Exception
*/
function onError(ConnectionInterface $conn, \Exception $e)
{
// TODO: Implement onError() method.
}
/**
* An RPC call has been received
* @param \Ratchet\ConnectionInterface $conn
* @param string $id The unique ID of the RPC, required to respond to
* @param string|Topic $topic The topic to execute the call against
* @param array $params Call parameters received from the client
*/
function onCall(ConnectionInterface $conn, $id, $topic, array $params)
{
// TODO: Implement onCall() method.
}
/**
* A client is attempting to publish content to a subscribed connections on a URI
* @param \Ratchet\ConnectionInterface $conn
* @param string|Topic $topic The topic the user has attempted to publish to
* @param string $event Payload of the publish
* @param array $exclude A list of session IDs the message should be excluded from (blacklist)
* @param array $eligible A list of session Ids the message should be send to (whitelist)
*/
function onPublish(ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible)
{
// TODO: Implement onPublish() method.
}
我正在使用JWT库,只是为了检查,有行
JWTAuth::parseToken("okay");
但该行会引发错误:
例外' RuntimeException'有消息'没有外观根 。组'
如何将JWT auth包含在我自己的课程中?