Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
namespace Ratchet\WebSocket;
3
use Ratchet\AbstractConnectionDecorator;
4
use Ratchet\RFC6455\Messaging\DataInterface;
5
use Ratchet\RFC6455\Messaging\Frame;
6
 
7
/**
8
 * {@inheritdoc}
9
 * @property \StdClass $WebSocket
10
 */
11
class WsConnection extends AbstractConnectionDecorator {
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function send($msg) {
16
        if (!$this->WebSocket->closing) {
17
            if (!($msg instanceof DataInterface)) {
18
                $msg = new Frame($msg);
19
            }
20
 
21
            $this->getConnection()->send($msg->getContents());
22
        }
23
 
24
        return $this;
25
    }
26
 
27
    /**
28
     * @param int|\Ratchet\RFC6455\Messaging\DataInterface
29
     */
30
    public function close($code = 1000) {
31
        if ($this->WebSocket->closing) {
32
            return;
33
        }
34
 
35
        if ($code instanceof DataInterface) {
36
            $this->send($code);
37
        } else {
38
            $this->send(new Frame(pack('n', $code), true, Frame::OP_CLOSE));
39
        }
40
 
41
        $this->getConnection()->close();
42
 
43
        $this->WebSocket->closing = true;
44
    }
45
}