Example #1
0
io.on( 'connection', function ( socket ) {

    console.log( 'user connected ' + socket.id );


    Util.each( User.s, function ( user, id ) {
        debug( 'emiting knowledge of user ' + id + ' to user ' + socket.id );
        socket.emit( 'user.register', id );
    });

    var user = new User( socket.id );

    user.register();
    io.emit( 'user.register', socket.id );
    debug('user registered: ',user);
    user.socket = socket;
    socket.user = user;


    socket.on( 'disconnect', function () {
        io.emit( 'user.unregister', socket.id );
        console.log( 'user disconnected ' + socket.id );
        user.unregister();
    });

});
Example #2
0
	handle: function ( handler ) {
		var promise = this;

		if ( Util.is.instanceof( Promise.Handler, handler ) ) {
			handler.handle( promise );
		} else {
			Util.each( this.handlers, function( handler, i ) {
				handler.handle( promise );
			});
		}

		return this;
	},
Example #3
0
	extend: function ( a, b, c ) {
		var i, context,
			methods = {},
			al = arguments.length;

		// API cases detection

			// .extend( name, fn, context )
			if (
				( al === 2 || al === 3 ) &&
				a && typeof a === 'string' &&
				b && typeof b === 'function'
			) {

				methods[ a ] = b;
				context = c;

			} else

			// .extend( { name: fn, ... }, context )
			if (
				( al === 1 || al === 2 ) &&
				a && typeof a === 'object'
			) {

				context = b;

				Util.each( a, function ( fn, k ) {
					if ( typeof fn == 'function' ) {
						methods[ k ] = fn;
					} else {
						throw new TypeError("Only functions are allowed as method");
					}
				});

			} else

			// .extend( context, [ 'methodName', ... ] )
			if (
				al === 2 &&
				a && typeof a === 'object' &&
				b && typeof b === 'object'
			) {

				context = a;

				Util.each( b, function ( k, i ) {
					if ( typeof a[ k ] == 'function' ) {
						methods[ k ] = a[ k ];
					} else {
						throw new TypeError("Only functions are allowed as method");
					}
				});

			} else

				throw new TypeError("You didn't follow API allowed cases");

		// Instance methods extending

			for( i in methods ) {
				this._proxyMethod( i, methods[ i ], context || this );
			}

		return this;
	},