<?
namespace cab\system;
class i_ws
{

 public static function send_monitor_mess_to_WS($group,$arr_mess)
 {
     if (isset(ACCOUNTS()->tree[$group])) $arr_groups=ACCOUNTS()->tree[$group]->get_arr_parent(['not_int'=>1]);
     $result=static::send_mess_to_WS($arr_groups,$arr_mess);
     return($result) ;
 }

 public static function send_mess_to_WS($arr_groups,$arr_mess,$options=[])
 {   //set_time_point('send_mess_to_WS - start') ;
     //ob_start() ;
     //trace() ;
     //$text=ob_get_clean() ;
     //LOG_JSON()->reg('send_mess_to_WS',$text);
     $arr_mess['host']=_MAIN_DOMAIN ;
     $arr_mess['uid']=($options['uid'])?:ENGINE()->generate_UID() ;
     if (is_array($arr_groups))
     {
         if (sizeof($arr_groups)) foreach ($arr_groups as $id=>$group_id) $arr_groups[$id]=(string)$group_id ;
     }
     else
     {  $group_id=(int)$arr_groups ;
        $arr_groups=[] ;
        $arr_groups[0]=(string)$group_id ;
     }
     $data=[];
     $data['Recipients']=$arr_groups;
     $data['data']=$arr_mess;
     if ($options['account_id']) $data['account_id']=$options['account_id'];

     $text_json=json_encode($data,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
     $result=IO()->doPut_v2(_MAIN_PROTOCOL,$GLOBALS['LS_WS_address_port'],'/'.$GLOBALS['LS_WS_send_message_URL'],'',$text_json,['timeout'=>0,'connect_timeout'=>2]) ;
     set_time_point('send_mess_to_WS - end') ;
     return($result) ;
 }
}

?>
