| 1: | <?php
|
| 2: |
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: |
|
| 15: | class SocketOutput extends \Sphp\tools\Component {
|
| 16: |
|
| 17: | private $url = '';
|
| 18: |
|
| 19: | public function fu_setURL($param) {
|
| 20: | $this->url = $param;
|
| 21: | }
|
| 22: |
|
| 23: | protected function onjsrender() {
|
| 24: | $protocol = "ws";
|
| 25: | $this->setAttributeDefault('style', 'style="overflow-y: scroll; height: 500px; max-height: 500px;');
|
| 26: | $this->setAttributeDefault('class', 'text-wrap');
|
| 27: | addHeaderJSCode($this->name , 'window["'. $this->name .'"] = {wsobj: null, onopen: function(){}}; window["callNativeGate"] = function (ctrl,evt="",evtp="",data={}){
|
| 28: | $("#'. $this->name .'").html(\'\');
|
| 29: | window["'. $this->name .'"]["wsobj"].callProcessNativeGate(ctrl,evt,evtp,data);
|
| 30: | };
|
| 31: | ');
|
| 32: | if (\SphpBase::sphp_request()->server('HTTPS') == 1) $protocol = "wss";
|
| 33: | if ($this->url == '')
|
| 34: |
|
| 35: | $this->url = SphpBase::sphp_request()->server('HTTP_HOST') ;
|
| 36: | addHeaderJSFunctionCode("ready", "socketnative", 'frontobj.websockethost = "'. $this->url .'"; frontobj.getSphpSocket(function(wsobj1){
|
| 37: | window["'. $this->name . '"]["wsobj"] = wsobj1;
|
| 38: | window["'. $this->name . '"]["onopen"]();
|
| 39: | frontobj.onwsmsg = function(msg){
|
| 40: | $("#'. $this->name .'").append(\'<p>\' + msg + \'</p>\').scrollTop($("#'. $this->name .'").prop(\'scrollHeight\'));
|
| 41: | };
|
| 42: | });');
|
| 43: | }
|
| 44: |
|
| 45: | }
|
| 46: | |