public function onCall(Conn $from, $callId, $topic, array $params) { echo 'Received data from ' . $from->resourceId . "\n"; if ($topic->getId() == 'api.call') { if (!isset($params['id']) || !is_int($params['id'])) { var_dump($params); $from->callError($callId, $topic, 'Bad request: invalid call id'); return; } // Handle HTTP headers if (isset($params['http_headers']) && is_array($params['http_headers'])) { if (isset($params['http_headers']['Accept-Language'])) { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = $params['http_headers']['Accept-Language']; } } try { if (isset($params['groupped']) && $params['groupped'] == true) { $resp = $this->_handleRequestGroup($from, $params['data']); } else { $resp = $this->_handleRequest($from, $params['data']); } } catch (Exception $e) { $errMsg = $e->getMessage(); $resp = new ApiResponse(); $resp->setSuccess(false); $resp->setValue($errMsg); $resp->setChannel(2, $errMsg); } $resp->setId($params['id']); $respData = $resp->generateArray(); echo 'Sending data to ' . $from->resourceId . "\n"; $from->callResult($callId, $respData); } else { $from->callError($callId, $topic, 'Bad request: unsupported topic "' . $topic->getId() . '"'); } }