[Opa] Network.channel

Mads Jensen mads379 at gmail.com
Thu Aug 18 10:35:13 EDT 2011


Hi Adam,

Lets say you wanted to extend the Chat example with the possibility to
create new
named chat rooms. Once a user has created such a chat-room other users could
join it and the messages would be broadcasted to everyone in that chatroom.

Currently I have something like this but I don't know if I'm on the
right track. At least
the message_recieved function never seems to get executed.

MyModule = {{

	user_state = UserContext.make({none}: option(....))
	
	get_state() = .....

	create(name: string) =
	(
		channel = Network.cloud(name): Network.network(message)
		do UserContext.change(( _ -> { some = { .. some info .. channel =
channel }}), user_state)
		do Client.goto("view/{name")
	)

	join(name: string, user: user ) =
	(
		channel = Network.cloud(name): Network.network(message)
		do Network.broadcast({ joining = user},channel)
		do UserContext.change(( _ -> { some = { .. some info .. channel =
channel }}), user_state)
		Client.goto("view/{name")
	)
}}

@client when_ready(name,color): void = (
	channel  = Option.get(MyModule.get_state()).channel
	...
	do Network.observe(message_recieved, channel)
	Board.prepare(Board.create())
)

@client message_recieved(msg: message) = ....

// the function that is invoked when urls matching "view/{name}"
view(name: string) =
(
	Resource.styled_page("Chess", style,
		<div onready={_ -> when_ready(name,color) }>
			{Template.parse(Template.default,
@static_content("resources/board.xmlt")()) |>
Template.to_xhtml(Template.default, _)}
		</div>
	)
)


More information about the Opa mailing list