Skip to content

realtime app chatofpomelo

fantasyni edited this page May 3, 2014 · 2 revisions

Overview

Pomelo is a fast, scalable game server framework for node.js. It provides the basic development framework and many related components, including libraries and tools. Pomelo is also suitable for real-time web applications; its distributed architecture makes pomelo scale better than other real-time web frameworks.
With Bearcat, developing real-time app with pomelo will be easier, faster and more maintainable.

Let's start our Bearcat in action tutorial series -- realtime app chatofpomelo

Warm up

Pomelo abstracts handler that handles client request and remote that handles remote rpc calls, both of these can be wrapped into simple POJOs, and then become simple, reuseable and maintainable.

Setup package.json and context.json

add bearcat to package.json

"bearcat": "~0.1.0"

add context.json

{
	"name": "chatofpomelo-websocket-bearcat",
	"beans": []
}

Add bearcat to app.js

var contextPath = require.resolve('./context.json');
var bearcat = Bearcat.createApp([contextPath]);

bearcat.start(function() {
	app.set('bearcat', bearcat);
	// start app
	app.start();
});

Wrap handler and remote

gateHandler.js

module.exports = function(app) {
	var bearcat = app.get('bearcat');
	return bearcat.getBean({
		id: "gateHandler",
		func: Handler,
		args: [{
			name: "app",
			value: app
		}]
	});
};

var Handler = function(app) {
	this.app = app;
};

chatRemote.js

module.exports = function(app) {
	var bearcat = app.get('bearcat');
	return bearcat.getBean({
		id: "chatRemote",
		func: ChatRemote,
		args: [{
			name: "app",
			value: app
		}]
	});
};

var ChatRemote = function(app) {
	this.app = app;
	this.channelService = app.get('channelService');
};

Just run it

node app.js

the whole repository is chatofpomelo-websocket-bearcat