I am using Laravel 5.4 PHP framework to build a simple chat app.
I am using Frozenmountain's WebSync on demand for signalling and based on their docs, I need to use a PHP proxy class in order to become able to ensure the user is authenticated and/or manipulate the messages in the middle:
According to their docs, I need to implement something like this:
require_once '../../PHP/Core/Proxy.php';
function callback(&$messages)
{
foreach ($messages as &$message)
{
// do something with the message!
//
// a simple example is to upper-case the "text"
// property in the data payload, so if you publish
// something like:
//
// data: {
// text: "Hello world!"
// }
//
// ... we want to modify the payload to look like:
//
// data: {
// text: "HELLO WORLD!"
// }
//
if(isset($message['data']))
{
// upper-case the text value
$message['data']['text'] = strtoupper($message['data']['text']);
}
}
}
// pass a private key as the 2nd parameter to use that key instead of the incoming request's key
Proxy::invoke('callback', null, 'http://' . $_SERVER['SERVER_NAME'] . '/request.ashx');
Now, This is what I have in my web.php where I define the routes:
Route::post('chatProxy','DbController@chatProxy' );
So I created a function inside the DbController called chatProxy:
public function chatProxy(GetOpenChatRequest $request)
{
function callbackFunction(&$messages) {
foreach ($messages as &$message) {
if(isset($message['data']))
{
// upper-case the text value
$message['data']['text'] = strtoupper($message['data']['text']);
}
}
}
Proxy::invoke('callbackFunction', 'myPrivateKeyGoesHere', 'http://ift.tt/2wh4uqz');
}
I tried putting function callbackFunction inside the function chatProxy itself as well as outside but it keeps complaining that:
(1/1) FatalThrowableError Call to undefined function callbackFunction()
I used $this->callBackFunction as well as self::callBackFunction but it didn't resolve anything..
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire