初始化代码
This commit is contained in:
17
vendor/topthink/think-swoole/src/contract/ResetterInterface.php
vendored
Normal file
17
vendor/topthink/think-swoole/src/contract/ResetterInterface.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace think\swoole\contract;
|
||||
|
||||
use think\Container;
|
||||
use think\swoole\Sandbox;
|
||||
|
||||
interface ResetterInterface
|
||||
{
|
||||
/**
|
||||
* "handle" function for resetting app.
|
||||
*
|
||||
* @param Container $app
|
||||
* @param Sandbox $sandbox
|
||||
*/
|
||||
public function handle(Container $app, Sandbox $sandbox);
|
||||
}
|
||||
39
vendor/topthink/think-swoole/src/contract/rpc/ParserInterface.php
vendored
Normal file
39
vendor/topthink/think-swoole/src/contract/rpc/ParserInterface.php
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace think\swoole\contract\rpc;
|
||||
|
||||
use think\swoole\rpc\Protocol;
|
||||
|
||||
interface ParserInterface
|
||||
{
|
||||
|
||||
const EOF = "\r\n\r\n";
|
||||
|
||||
/**
|
||||
* @param Protocol $protocol
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encode(Protocol $protocol): string;
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return Protocol
|
||||
*/
|
||||
public function decode(string $string): Protocol;
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function decodeResponse(string $string);
|
||||
|
||||
/**
|
||||
* @param mixed $result
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encodeResponse($result): string;
|
||||
}
|
||||
42
vendor/topthink/think-swoole/src/contract/websocket/HandlerInterface.php
vendored
Normal file
42
vendor/topthink/think-swoole/src/contract/websocket/HandlerInterface.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\swoole\contract\websocket;
|
||||
|
||||
use Swoole\Websocket\Frame;
|
||||
use think\Request;
|
||||
|
||||
interface HandlerInterface
|
||||
{
|
||||
/**
|
||||
* "onOpen" listener.
|
||||
*
|
||||
* @param int $fd
|
||||
* @param Request $request
|
||||
*/
|
||||
public function onOpen($fd, Request $request);
|
||||
|
||||
/**
|
||||
* "onMessage" listener.
|
||||
* only triggered when event handler not found
|
||||
*
|
||||
* @param Frame $frame
|
||||
*/
|
||||
public function onMessage(Frame $frame);
|
||||
|
||||
/**
|
||||
* "onClose" listener.
|
||||
*
|
||||
* @param int $fd
|
||||
* @param int $reactorId
|
||||
*/
|
||||
public function onClose($fd, $reactorId);
|
||||
}
|
||||
29
vendor/topthink/think-swoole/src/contract/websocket/ParserInterface.php
vendored
Normal file
29
vendor/topthink/think-swoole/src/contract/websocket/ParserInterface.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace think\swoole\contract\websocket;
|
||||
|
||||
use Swoole\WebSocket\Frame;
|
||||
|
||||
interface ParserInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Encode output payload for websocket push.
|
||||
*
|
||||
* @param string $event
|
||||
* @param mixed $data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function encode(string $event, $data);
|
||||
|
||||
/**
|
||||
* Input message on websocket connected.
|
||||
* Define and return event name and payload data here.
|
||||
*
|
||||
* @param Frame $frame
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function decode($frame);
|
||||
}
|
||||
61
vendor/topthink/think-swoole/src/contract/websocket/RoomInterface.php
vendored
Normal file
61
vendor/topthink/think-swoole/src/contract/websocket/RoomInterface.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace think\swoole\contract\websocket;
|
||||
|
||||
interface RoomInterface
|
||||
{
|
||||
/**
|
||||
* Rooms key
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
public const ROOMS_KEY = 'rooms';
|
||||
|
||||
/**
|
||||
* Descriptors key
|
||||
*
|
||||
* @const string
|
||||
*/
|
||||
public const DESCRIPTORS_KEY = 'fds';
|
||||
|
||||
/**
|
||||
* Do some init stuffs before workers started.
|
||||
*
|
||||
* @return RoomInterface
|
||||
*/
|
||||
public function prepare(): RoomInterface;
|
||||
|
||||
/**
|
||||
* Add multiple socket fds to a room.
|
||||
*
|
||||
* @param int fd
|
||||
* @param array|string rooms
|
||||
*/
|
||||
public function add(int $fd, $rooms);
|
||||
|
||||
/**
|
||||
* Delete multiple socket fds from a room.
|
||||
*
|
||||
* @param int fd
|
||||
* @param array|string rooms
|
||||
*/
|
||||
public function delete(int $fd, $rooms);
|
||||
|
||||
/**
|
||||
* Get all sockets by a room key.
|
||||
*
|
||||
* @param string room
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClients(string $room);
|
||||
|
||||
/**
|
||||
* Get all rooms by a fd.
|
||||
*
|
||||
* @param int fd
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRooms(int $fd);
|
||||
}
|
||||
Reference in New Issue
Block a user