[Seaside] How to learn about Comet in Seaside?

cdrick cdrick65 at gmail.com
Sat Jun 14 12:22:59 UTC 2008


Hi Nick and welcome :)

2008/6/14 Nick Smith <life2point0 at gmail.com>:
>
> Hi, I'm new to Smalltalk and Seaside and must say I'm enjoying learning both
> immensely.  I've worked my through 'Squeak by Example' and 'An Introduction
> to Seaside' and would like now like to implement Comet style 'server push'
> in a web app.

You should have a closer look at CTChat, and CTCounter and CTSession.

To run the examples (I don't know if you did), you have to run a web
listener so that the connection is always open to push information. So
instead of using one of the WAKom, you run WAListener startOn: 8888.
Then you browse to localhost:8888/seaside/browse and you should see
comet exemples.

>
> Problem is I can't find any documentation anywhere, so I've tried to figure
> it out by browsing the Comet classes and method comments (in Damien Cassou's
> latest web imagine... the tools in here are fantastic) but I'm probably not
> experienced enough to understand just by reading code.
>
> Any pointers to notes, blog posts or docs. would be really appreciated.

Comet is not really tested and used I guess. I cannot help here too
much. Just look closer at CTChat and CTCounter especially class side.
You need to have a class instance variable name pusher that is
initialized (lazily) with a CTPusher. Then in you render method, you
need to render at the end the script that does the magic (see in both
renderContentOn:).

	html script: (html comet
		pusher: self pusher;
		connect)

I think that's nearly all. Don't forget to use a CTSession. Initialize
properly the app (see examples). Here is the one for the chat:

initialize
	| application |
	application := self registerAsApplication: 'comet/chat'.
	application preferenceAt: #sessionClass put: CTChatSession.
	application addLibrary: SULibrary; addLibrary: CTLibrary

Last point, to udpate in other browsers, you need a to use self pucher
javascript: [:aScript |], like:

CTChat>>push: aString with: aBlock
	self pusher javascript: [ :script |
		script element id: 'messages'; insertTop: [ :html |
			self renderMessage: aBlock class: aString on: html ] ]

CTCounter>>update: anAspect
	"Update the number in all connected web browser. Only the first 4
lines are really needed, the rest adds some eye-candy and can simply
be removed if not needed."

	self pusher javascript: [ :script |
		script element
			id: 'count';
			update: self model count.
...
hth

Cédrick

ps: to Lukas and others, couldn't we have a class CTComponent to be
the common superclass of Comet apps. It could have pusher class inst
var and its accessor. Also, we could maybe get rid of having to write
:
html script: (html comet
		pusher: self pusher;
		connect)


More information about the seaside mailing list