import { Channel } from './channel' ; const Pusher = require ( 'pusher' ) ; export class PrivateChannel extends Channel { param { any } socket param { any } data return { Promise < any > } join ( socket , data ) { return this . signatureIsValid ( socket , data ) . then ( isValid => { if ( isValid ) { return super . join ( socket , data ) ; } } ) ; } param { any } socket param { any } data return { Promise < boolean > } protected signatureIsValid ( socket , data ) { return new Promise ( ( resolve , reject ) => { this . getSignedToken ( socket , data ) . then ( token => { resolve ( token === data . token ) ; } ) ; } ) ; } param { any } socket param { any } data return { Promise < string > } protected getSignedToken ( socket , data ) { return new Promise ( ( resolve , reject ) => { let token = new Pusher . Token ( socket . echoApp . key , socket . echoApp . secret ) ; resolve ( socket . echoApp . key + ':' + token . sign ( this . getDataToSignForToken ( socket , data ) ) ) ; } ) ; } param { any } socket param { any } data return { string } protected getDataToSignForToken ( socket , data ) { return `${ socket . id }:${ data . channel }` ; } }