Autorização de canal privado do Pusher com o Parse

// No cliente (navegador)

Pusher.authorizers.parse = function (socketId, callback) {
var pusherData = {
socket id: socketId,
nome do canal : this.channel.name
};
Parse.Cloud.run (‘authorizePusherChannel’, pusherData, {
sucesso: função (resultado) {
retorno de chamada (falso, JSON.parse (resultado));
},
erro: função (erro) {
retorno de chamada (verdadeiro, erro);
}
} );
};

// No Parse Cloud Code
Parse.Cloud.define (‘authorizePusherChannel’, function (request, response) {
if (! Request.user) {response.error (‘User should be autenticated.’);}
Var pusherAppKey = ‘your -pusher-app-key ‘;
var pusherAppSecret =’ your-pusher-app-secret ‘;
var stringToSign = request.params.socket id +’: ‘+ request.params.channel name;
var authToken = pusherAppKey +’: ‘ + crypto.createHmac (‘sha256’, pusherAppSecret) .update (stringToSign) .digest (‘hex’);
response.success (JSON.stringify ({auth: authToken}));
});