Extending a new network component

A place to request and discuss new engine features / functionality

Extending a new network component

Postby lucbr » Tue Dec 09, 2014 2:29 am

Hello!

Since neither socket.io (current version in ige) nor net.io are highly scalable (by default) as SocketCluster (http://socketcluster.io), I was wondering how tough would it be to create a IgeSocketClusterComponent? All I have to do is to implement the following interfaces? Do I need to know anything more to extend this network component?

Code: Select all

var IgeSocketClusterComponent = IgeEventingClass.extend([
  {extension: IgeTimeSyncExtension, overwrite: false}
], {
  classId: 'IgeSocketClusterComponent',
  componentId: 'network',

  init: function (entity, options) {
   
    // ...
   
    if (ige.isServer) {
      this.implement(IgeSocketCusterServer);   
      //...
    }

    if (ige.isClient) {
      this.implement(IgeSocketClusterClient);   
      //...
    }

    // ...
  },

  /**
   * Gets / sets debug flag that determines if debug output
   * is logged to the console.
   * @param {Boolean=} val
   * @return {*}
   */
  debug: function (val) {
   
  },

  /**
   * Gets / sets the maximum number of debug messages that
   * should be allowed to be output to the console before
   * debugging is automatically turned off. This is useful
   * if you want to sample a certain number of outputs and
   * then automatically disable output so your console is
   * not flooded.
   * @param {Number=} val Number of debug messages to allow
   * to be output to the console. Set to zero to allow
   * infinite amounts.
   * @return {*}
   */
  debugMax: function (val) {
   
  }
});

if (typeof(module) !== 'undefined' && typeof(module.exports) !== 'undefined') { module.exports = IgeSocketClusterComponent; }



Code: Select all
var IgeSocketCusterServer = {
 
  /**
   * Starts the network for the server.
   * @param {*} data The port to listen on.
   * @param {Function=} callback A callback method to call once the
   * network has started.
   */
  start: function (data, callback) {

  },

  /**
   * Sets a network command and optional callback. When a network command
   * is received by the server, the callback set up for that command will
   * automatically be called and passed the data from the incoming network
   * packet.
   * @param {String} commandName The name of the command to define.
   * @param {Function=} callback A function to call when the defined network
   * command is received by the network.
   * @return {*}
   */
  define: function (commandName, callback) {

  },

  /**
   * Adds a client to a room by id. All clients are added to room id
   * "ige" by default when they connect to the server.
   * @param {String} clientId The id of the client to add to the room.
   * @param {String} roomId The id of the room to add the client to.
   * @returns {*}
   */
  clientJoinRoom: function (clientId, roomId) {

  },
 
  /**
   * Removes a client from a room by id. All clients are added to room id
   * "ige" by default when they connect to the server and you can remove
   * them from it if your game defines custom rooms etc.
   * @param {String} clientId The id of the client to remove from the room.
   * @param {String} roomId The id of the room to remove the client from.
   * @returns {*}
   */
  clientLeaveRoom: function (clientId, roomId) {

  },

  /**
   * Removes a client from all rooms that it is a member of.
   * @param {String} clientId The client id to remove from all rooms.
   * @returns {*}
   */
  clientLeaveAllRooms: function (clientId) {

  },

  /**
   * Gets the array of room ids that the client has joined.
   * @param clientId
   * @returns {Array} An array of string ids for each room the client has joined.
   */
  clientRooms: function (clientId) {

  },
 
  /**
   * Returns an associative array of all connected clients
   * by their ID.
   * @param {String=} roomId Optional, if provided will only return clients
   * that have joined room specified by the passed roomId.
   * @return {Array}
   */
  clients: function (roomId) {
 
  },

  /**
   * Returns the socket associated with the specified client id.
   * @param {String=} clientId
   * @return {*}
   */
  socket: function (clientId) {
  },

  /**
   * Gets / sets the current flag that determines if client connections
   * should be allowed to connect (true) or dropped instantly (false).
   * @param {Boolean} val Set to true to allow connections or false
   * to drop any incoming connections.
   * @return {*}
   */
  acceptConnections: function (val) {

  },

  /**
   * Sends a message over the network.
   * @param {String} commandName
   * @param {Object} data
   * @param {*=} clientId If specified, sets the recipient socket id or a array of socket ids to send to.
   */
  send: function (commandName, data, clientId) {
 
  },

  /**
   * Sends a network request. This is different from a standard
   * call to send() because the recipient code will be able to
   * respond by calling ige.network.response(). When the response
   * is received, the callback method that was passed in the
   * callback parameter will be fired with the response data.
   * @param {String} commandName
   * @param {Object} data
   * @param {Function} callback
   */
  request: function (commandName, data, callback) {
 
  },

  /**
   * Sends a response to a network request.
   * @param {String} requestId
   * @param {Object} data
   */
  response: function (requestId, data) {
 
  },

  /**
   * Generates a new 16-character hexadecimal unique ID
   * @return {String}
   */
  newIdHex: function () {
   
  },

  /**
   * Determines if the origin of a request should be allowed or denied.
   * @param origin
   * @return {Boolean}
   * @private
   */
  _originIsAllowed: function (origin) {
    // put logic here to detect whether the specified origin is allowed.
    return true;
  },

  /**
   * Called when the server receives a client connection request. Sets
   * up event listeners on the socket and sends the client the initial
   * networking data required to allow network commands to operate
   * correctly over the connection.
   * @param {Object} socket The client socket object.
   * @private
   */
  _onClientConnect: function (socket) {

  },

  /**
   * Called when the server receives a network message from a client.
   * @param {Object} data The data sent by the client.
   * @param {String} clientId The client socket id.
   * @private
   */
  _onClientMessage: function (data, clientId) {
 
  },
 
  _onRequest: function (data, clientId) {
   
  },

  _onResponse: function (data, clientId) {
 
  },

  /**
   * Called when a client disconnects from the server.
   * @param {Object} data Any data sent along with the disconnect.
   * @param {Object} socket The client socket object.
   * @private
   */
  _onClientDisconnect: function (data, socket) {
   
  }
};


Code: Select all
var IgeSocketClusterClient = {

  /**
   * Gets the current socket id.
   * @returns {String} The id of the socket connection to the server.
   */
  id: function () {
  },
 
  /**
   * Starts the network for the client.
   * @param {*} url The game server URL.
   * @param {Function=} callback A callback method to call once the
   * network has started.
   */
  start: function (url, callback) {
   
  },

  stop: function () {
   
  },

  /**
   * Gets / sets a network command and callback. When a network command
   * is received by the client, the callback set up for that command will
   * automatically be called and passed the data from the incoming network
   * packet.
   * @param {String} commandName The name of the command to define.
   * @param {Function} callback A function to call when the defined network
   * command is received by the network.
   * @return {*}
   */
  define: function (commandName, callback) {

  },

  /**
   * Sends a network message with the given command name
   * and data.
   * @param commandName
   * @param data
   */
  send: function (commandName, data) {
 
  },

  /**
   * Sends a network request. This is different from a standard
   * call to send() because the recipient code will be able to
   * respond by calling ige.network.response(). When the response
   * is received, the callback method that was passed in the
   * callback parameter will be fired with the response data.
   * @param {String} commandName
   * @param {Object} data
   * @param {Function} callback
   */
  request: function (commandName, data, callback) {

  },

  /**
   * Sends a response to a network request.
   * @param {String} requestId
   * @param {Object} data
   */
  response: function (requestId, data) {
 
  },

  /**
   * Generates a new 16-character hexadecimal unique ID
   * @return {String}
   */
  newIdHex: function () {
   
  },

  _onRequest: function (data) {
 
  },

  _onResponse: function (data) {
 
  },

  /**
   * Called when the network connects to the server.
   * @private
   */
  _onConnectToServer: function () {
  },

  /**
   * Called when data from the server is received on the client.
   * @param data
   * @private
   */
  _onMessageFromServer: function (data) {
 
  },

  /**
   * Called when the client is disconnected from the server.
   * @param data
   * @private
   */
  _onDisconnectFromServer: function (data) {
 
  },

  /**
   * Called when the client has an error with the connection.
   * @param {Object} data
   * @private
   */
  _onError: function (data) {
  }
};

lucbr
 
Posts: 27
Joined: Fri Oct 25, 2013 3:26 am

Return to New Feature Discussion

Who is online

Users browsing this forum: No registered users and 1 guest
cron