add pause test
[brisk.git] / web / xynt_test01.php
1 <?php
2
3 $transs = array( "iframe", "xhr", "htmlfile" );
4 if (!isset($f_trans))
5     $f_trans = $transs[0];
6
7 if (!isset($f_test))
8     $f_test = 1;
9
10
11 function mop_flush()
12 {
13     for ($i = 0; $i < ob_get_level(); $i++)
14         ob_end_flush();
15     ob_implicit_flush(1);
16     flush();
17 }
18
19 $escpush_from = array("\\", "\"");
20 $escpush_to   = array("\\\\", "\\\"");
21 function escpush($s)
22 {
23     GLOBAL $escpush_from, $escpush_to;
24
25     return str_replace($escpush_from, $escpush_to, $s);
26 }
27
28 if ($isstream == "true") {
29
30     require_once("Obj/transports.phh");
31
32
33     if (isset($transp) && $transp == "xhr") {
34         $transp = new Transport_xhr();
35     }
36     else if (isset($transp) && $transp == "htmlfile") {
37         $transp = new Transport_htmlfile();
38     }
39     else {
40         $transp = new Transport_iframe();
41     }
42     $header_out = array();
43
44     $init_string = "";
45     for ($i = 0 ; $i < 4096 ; $i++) {
46         if (($i % 128) == 0)
47             $init_string .= " ";
48         else
49             $init_string .= chr(mt_rand(65, 90));
50     }
51
52     $body = $transp->init("plain", $header_out, $init_string, "", "0");
53
54     foreach ($header_out as $key => $value) {
55         header(sprintf("%s: %s", $key, $value));
56     }
57     print($body);
58     mop_flush();
59
60     switch ($f_test) {
61     case 1:
62         // from 1 to 9 into the innerHTML and than close
63         for ($i = 1 ; $i < 10 ; $i++) {
64             $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
65             print($chunk);
66             mop_flush();
67             sleep(1);
68         }
69         break;
70     case 2:
71         // from 1 to 9 with 60 secs after 8, the client js api must restart stream after 12 secs
72         for ($i = 1 ; $i < 10 ; $i++) {
73             $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
74             print($chunk);
75             mop_flush();
76             sleep(1);
77             if ($i == 8)
78                 sleep(60);
79         }
80         break;
81     case 3:
82         // from 1 to 9 into the innerHTML and than close
83         for ($i = 1 ; $i < 10 ; $i++) {
84             if ($i != 5) {
85                 $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
86             }
87             else {
88                 $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';|sleep(gst,3000);", $i));
89             }
90             print($chunk);
91             mop_flush();
92             sleep(1);
93         }
94         break;
95     }
96     exit;
97 }
98 ?>
99 <html>
100 <head>
101 <title>XYNT TEST01</title>
102 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
103 <script type="text/javascript" src="xynt-streaming.js"></script>
104 <script type="text/javascript" src="commons.js"></script>
105
106 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
107
108 <script type="text/javascript"><!--
109      var sess = "for_test";
110      var stat = "";
111      var subst = "";
112      var gst = new globst();
113      window.onload = function() {
114
115      xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", null /* console */, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true&f_test=<?php echo "$f_test";?>', function(com){eval(com);});
116      /*     xstm.hbit_set(heartbit); */
117      xstm.start();
118  }
119  //-->
120 </script>
121 </head>
122 <body>
123 <div>
124 <?php
125
126 $desc = array( "Semplice: da 1 a 9 ogni secondo, poi ricomincia.",
127                "Restart: da 1 a 8 ogni secondo, pausa 16 secondi, poi ricomincia.",
128                "Pausa: da 1 a 5 ogni secondo, pausa 3 secondi, e poi 8 e 9 ogni secondo, e poi ricomincia.");
129
130
131 printf("<table>");
132 for ($test = 1 ; $test <= 3 ; $test++) {
133     printf("<tr>");
134     foreach ($transs as $trans) {
135         printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d\">Test %s %02d</a></td>", $trans, $test, $trans, $test);
136     }
137     printf("</tr>\n");
138 }
139 printf("</table>");
140 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
141 ?>
142 </div>
143 <div>
144 <b>Descrizione</b>: <?php echo $desc[$f_test - 1]; ?>
145 </div>
146 <div>
147 <b>Counter</b>: <span id="container">
148 BEGIN
149 </span>
150 </div>
151 </body>
152 </html>