GatewayworkerTools.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\common\library;
  3. use \GatewayClient\Gateway;
  4. /**
  5. * gateway绑定接口
  6. */
  7. class GatewayworkerTools
  8. {
  9. /**
  10. * 直播间中发送大礼物,全服通告
  11. */
  12. public static function sendBigGiftInParty($sender, $receiver, $partyInfo, $giftUserParty)
  13. {
  14. $messageData = [
  15. 'type' => 'bigGiftNotice',
  16. 'data' => [
  17. 'party_info' => [
  18. 'party_id' => $partyInfo['id'],
  19. 'room_type' => $partyInfo['room_type'],
  20. 'party_name' => $partyInfo['party_name']
  21. ],
  22. 'notice_info' => [
  23. 'sender' => $sender,
  24. 'receiver' => $receiver,
  25. 'gift_num' => $giftUserParty['number'],
  26. 'gift_name' => $giftUserParty['gift_name'],
  27. 'gift_image' => $giftUserParty['gift_gif_image'],
  28. 'value' => $giftUserParty['value'],
  29. ]
  30. ]
  31. ];
  32. $Gateway = new Gateway();
  33. $Gateway::$registerAddress = '127.0.0.1:2345';
  34. $Gateway::sendToAll(json_encode($messageData));
  35. }
  36. /**
  37. * 直播间中发送礼物,本房间飘屏
  38. */
  39. public static function sendGiftInParty($sender, $receiver, $partyInfo, $giftUserParty)
  40. {
  41. $aData = [
  42. 'code' => 'party',
  43. 'data' => [
  44. 'cmd' => 'send_gift_in_party',
  45. 'content' => [
  46. 'party_info' => [
  47. 'party_id' => $partyInfo['id'],
  48. 'room_type' => $partyInfo['room_type'],
  49. 'party_name' => $partyInfo['party_name']
  50. ],
  51. 'notice_info' => [
  52. 'sender' => $sender,
  53. 'receiver' => $receiver,
  54. 'gift_num' => $giftUserParty['number'],
  55. 'gift_name' => $giftUserParty['gift_name'],
  56. 'gift_image' => $giftUserParty['gift_gif_image']
  57. ]
  58. ]
  59. ]
  60. ];
  61. Gateway::sendToGroup($partyInfo['id'],json_encode($aData));
  62. }
  63. // 注意除了不支持sendToCurrentClient和closeCurrentClient方法
  64. // Gateway::sendToAll($data);
  65. // Gateway::sendToClient($client_id, $data);
  66. // Gateway::closeClient($client_id);
  67. // Gateway::isOnline($client_id);
  68. // Gateway::bindUid($client_id, $uid);
  69. // Gateway::isUidOnline($uid);
  70. // Gateway::getClientIdByUid($uid);
  71. // Gateway::unbindUid($client_id, $uid);
  72. // Gateway::sendToUid($uid, $data);
  73. // Gateway::joinGroup($client_id, $group);
  74. // Gateway::sendToGroup($group, $data);
  75. // Gateway::leaveGroup($client_id, $group);
  76. // Gateway::getClientCountByGroup($group);
  77. // Gateway::getClientSessionsByGroup($group);
  78. // Gateway::getAllClientCount();
  79. // Gateway::getAllClientSessions();
  80. // Gateway::setSession($client_id, $session);
  81. // Gateway::updateSession($client_id, $session);
  82. // Gateway::getSession($client_id);
  83. }