/ / Sails.io.js io.socket.get( '/ user'、...)コアにまだ実装されていません - node.js、socket.io、sails.js、sails.io.js

Sails.io.js io.socket.get( '/ user'、...)まだコアに実装されていません - node.js、socket.io、sails.js、sails.io.js

例: assets/js/dependencies/app.io.js with:

io.socket.on("connect", function socketConnected() {
console.debug("This is from the connect: ", io.socket);
console.debug("WebSocket is connected:", io.socket.isConnected());

io.socket.get("/user", function(resData) {
console.debug(resData);
});
});

コンソール

  |>    Now connected to Sails.
___/   For help, see: ....
(using sails.io.js browser SDK @v0.13.7)

app.io.js:3 This is from the connect:  SailsSocket {headers: undefined, eventQueue: Object, isConnecting: false, extraHeaders: Object, hostname: "localhost"…}
app.io.js:4 WebSocket is connected: true
app.io.js:7 Not implemented in core yet    <========= WHY?

注意: io-socket-getドキュメント

なぜ私はこのメッセージを受け取っていますか?

どのようにこれを修正するためのポインターですか?

回答:

回答№1は2

次のような情報が必要です。

  1. Angularのようなjsフレームワークを使用していますか?
  2. Bowerのようなツールで依存関係を管理していますか?
  3. Sailsサーバーはどのように構成されていますか?

何よりも、私はSailsのバックエンドをどのように設定したかを示すことができます:

私の .sailsrc 私は以下のように設定されたフックを持っています

"hooks": {
"csrf": false,
"grunt": false,
"i18n": false,
"pubsub": false,
"session": false,
"sockets": true,
"views": false}

私の中で UserController.js 私はソケット通信を可能にするこの簡単な方法を持っています

enableNtofications: function(req, res){

// checking if the request comes from
// a socket request
if(req.isSocket){

// getting the current logged user
var user = req.user;

// subuscribing the client to model changes
User.subscribe(req, [user.id]);

return res.ok();

} else {
return res.badRequest();
}

},

私のフロントエンドはAngularと ngSails Angularの "sails.io"のラッパーの一種であるモジュール

と私の "UserService.js"で私は何かのように行うことができます

        // waiting for notifications on User
$sails.on("user", function(event) {
if (event) {
// manage the message here...
}
});

ソケットを有効にするためにサーバーメソッドを呼び出す

        // calling the service
return $sails.post("/user/enableNtofications").then(
// ok
function() {},
// ko
function(data) {
console.log("enable notifications KO");
console.log(data.error);
});

( "$ sails"モジュールを注入して正しく設定する必要もあります...)

これがあなたを助けることができると願って