kefu/server/lib/Gateway.php

50 lines
1.1 KiB
PHP

<?php
namespace server\lib;
class Gateway{
protected static $_worker = null;
/**
* 设置实例
*/
public static function setGateway($worker_instance)
{
self::$_worker = $worker_instance;
}
/**
* 向某个客户端连接发送消息
*/
public static function sendToClient($clientId, $message){
if(self::$_worker->isEstablished($clientId)){
self::$_worker->push($clientId,$message);
}else{
echo "客服端ID不存在---[".$clientId.']'.PHP_EOL;
}
}
public static function sendToGroup(){
//
}
public static function sendToAll($message,$curClientId = null){
foreach (self::$_worker->connections as $item)
{
if ($curClientId != $item)
{
self::$_worker->push($item,$message);
}
}
}
public static function closeClient($clientId){
self::$_worker->close($clientId,true);
}
public static function sendByTask($data){
self::$_worker->task($data);
}
}