Completed
Pull Request — master (#243)
by Дмитрий
05:05
created

SimpleRequest::run()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 46
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
cc 1
eloc 5
c 3
b 2
f 0
nc 1
nop 0
dl 0
loc 46
rs 8.9411
1
<?php
2
namespace PHPDaemon\SockJS\Examples;
3
4
use PHPDaemon\Core\Daemon;
5
use PHPDaemon\Core\Debug;
6
use PHPDaemon\HTTPRequest\Generic;
7
8
class SimpleRequest extends Generic
9
{
10
    /**
11
     * Called when request iterated.
12
     * @return integer Status.
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
13
     */
14
    public function run()
15
    {
16
        $this->header('Content-Type: text/html');
17
        ?>
18
        <!DOCTYPE html>
19
        <html>
20
        <head>
21
            <title>SockJS test page</title>
22
            <script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
23
        </head>
24
        <body>
25
        <script type="text/javascript">
26
            var sock, logElem;
27
28
            function addLog(msg) {
29
                logElem.innerHTML = msg + '<br />' + logElem.innerHTML;
30
            }
31
32
            function create() {
33
                logElem = document.getElementById('log');
34
                sock = new SockJS('http://' + document.domain + ':8068/sockjs/');
35
                sock.onopen = function () {
36
                    addLog('SockJS opened');
37
                }
38
                sock.onmessage = function (e) {
39
                    addLog('<<< : ' + e.data);
40
                }
41
                sock.onclose = function () {
42
                    addLog('closed');
43
                }
44
            }
45
46
            function send(data) {
47
                sock && sock.send(data);
48
                addLog('>>> : ' + data);
49
            }
50
        </script>
51
52
        <button onclick="create();">Create SockJS</button>
53
        <button onclick="send('ping');">Send ping</button>
54
        <button onclick="sock && sock.close();">Close SockJS</button>
55
        <div id="log" style="width:300px; height: 300px; border: 1px solid #999999; overflow:auto;"></div>
56
        </body>
57
        </html>
58
        <?php
59
    }
60
}
61