Example #1
0
    redis.on( 'message', function ( channel, payload ) {
        var _id = pattern2id( channel )
        var subscription = self.subscriptions[ _id ]

        if ( ! subscription ) {
            return self.emit( 'error', new Error(
                'Received a redis message and such subscription does not exist'
            ))
        }

        // dispatch to subscription
        subscription.emit( 'payload', payload )
    })
Example #2
0
WSServer.prototype.getSubscription = function ( pattern ) {
    var self = this
    var _id = pattern2id( pattern )

    debug( "Gathering subscription for id %s", _id )

    if ( this.subscriptions[ _id ] ) {
        return this.subscriptions[ _id ]
    }

    // seems there's not a subscription, lets create one
    var subscription = new Subscription( pattern )
    subscription.attachServer( self )
    self.subscriptions[ subscription.id ] = subscription

    subscription.on( 'destroy', function () {
        subscription.deattachServer( self )
        delete self.subscriptions[ subscription.id ]
    })

    return subscription
}
Example #3
0
 .spread(function ( rcvdSubscriptionId, rcvdPayload ) {
     expect( rcvdSubscriptionId ).to.be.equal( pattern2id( pattern ) )
     expect( rcvdPayload ).to.be.equal( JSON.stringify( payload ) )
 })