まず、JDare/ClankBundle を使用して、これらの指示に従ってクライアント側から関数を呼び出しています https://github.com/JDare/ClankBundle/blob/master/Resources/docs/RPCSetup.md
コンソールでこのエラーが発生し続けます「RPCエラー[オブジェクトオブジェクト]未定義」
notify_func 関数のスペルを間違えても問題ないことに気付きました。それでも同じエラーがスローされます。何が間違っているのかわかりませんが、そもそも関数が見つからないと思いますか?
これはクライアント側です (Twig)
Websocket は正常に接続します
<script type="text/javascript">
var myClank = Clank.connect('ws://localhost:9999');
myClank.on("socket/connect", function(session){
alertify.success("Connected to websocket server");
//this will call the server side function "Sample::addFunc"
session.call("notify/notify_func",[2,5])
.then( //using "then" promises.
function(result) //the function for a valid result
{
alertify.log("RPC Valid! "+result);
},
function(error, desc) // the function to handle an error
{
alertify.log("RPC Error"+" "+error+" "+desc);
}
);
});
myClank.on("socket/disconnect", function(error){
alertify.error("Disconnect for "+error.reason+" with code "+error.code);
});
</script>
これはサーバー側です
<?php
namespace Gabriel\NotificationsBundle\RPC;
use Ratchet\ConnectionInterface as Conn;
class PostCommentNotificationService
{
public function notifyFunc(Conn $conn,$params)
{
return array("result"=>array_sum($params));
}
}
これが構成です
#services.yml
services:
notifications.newcommentpost:
class: Gabriel\NotificationsBundle\RPC\PostCommentNotificationService
#config.yml
# Clank Configuration
clank:
web_socket_server:
port: 9999 #The port the socket server will listen on
host: localhost #(optional) The host ip to bind to
rpc:
-
name: "notify" #Important! this is the network namespace used to match calls to this service!
service: "notifications.newcommentpost" #The service id.