Robert Krahn Aug 19, 2013
Lively2Lively Messaging System
13
Motivation
Thus [Smalltalk's] semantics are a bit like having thousands and thousands of computers all hooked together by a very fast network. Alan Kay, The Early History Of Smalltalk
Simple yet powerful metaphor, can we scale it beyond the image level?
13
Goals
■ OO-style messaging for Lively Web □ Lively worlds (and other participants in Lively Web) should be able to communicate □ Pure message-based communication □ Network abstraction but not complete transparency, i.e. separated JS address spaces □ Dynamic: Participants join and leave, change state and behavior □ doesNotUnderstand
13
Goals (continued)
■ Base layer for other collaboration mechanisms □ Multi-user awareness (session tracking) □ Synchronization services □ Audio/video connections
■ Reliable □ Automatically recover from network failures
■ Efficient connection for service consumption □ Data streaming □ Peer-to-peer connections, no server bottleneck
■ Leightweight □ Make it easy to connect and extend the network and its services
13
Lively2Lively
■ Session tracking □ Participants can register to become discoverable message receivers □ Optional (not every participant needs registration)
■ Messaging framework □ Establishes a network of Lively worlds and other participants and services □ Message format (protocol) □ Should eventually support different transportation layers (WebSockets, WebRTC, HTTP) □ Not restricted to Lively/JavaScript(!) □ Participants need to support a transportation layer and know message format (slide 13)
13
Lively2Lively Client Interface
// if not disabled a session gets established on world load
session = lively.net.SessionTracker.getSession();
// all the sessions in LivelyWeb that we know of
session.getUserInfo(inspect);
// loopback: send a message to myself
session.sendTo(session.sessionId, 'askFor', {bar: 23}, inspect);
// what services are provided by this session?
session.sendTo(session.sessionId, 'reportServices', null, inspect);
// what services are provided by my tracker?
session.sendTo(session.trackerId, 'reportServices', {}, inspect);
// how to implement a new message
// 1) messageNotUnderstood
session.sendTo(session.sessionId, 'foobar', {}, show);
// 2) Implement service
lively.net.SessionTracker.registerActions({
foobar: function(msg, session) {
session.answer(msg, 'Howdy!');
}
})
// 3) message responds successfully
session.sendTo(session.sessionId, 'foobar', {}, show);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
13
Interface for non-Lively environments
reset
source code
# This starts an external nodejs process that sends a message to this Lively
# session. This is an example of how a system outside of LivelyWeb can connect
# to it.
# Note that any kind of environment/language can be used, not just JS. The
# requirements for communication are: 1) websocket support, 2) knowledge
# of the lively-json websocket format (see slide 13).
node nodejs2lively.example.js "client-session:35950F90-79E6-43B4-9FC5-FDE564B88B31"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
13
Architectural Overview
■ Infrastructure/Network ■ Session tracking ■ Rules for message dispatch and routing ■ Message protocol ■ Services (message -> method)
13
Infrastructure/Network
■ Currently only websockets ■ WebRTC support soon ■ For reliability maybe HTTP fallback necessary (socket.io) ■ The network layer is hidden by default □ Users only need to specify receiver, selector, arguments of message
13
Infrastructure/Network (Message Forwarding)
■ Transparent routing via HTTP/WebSockets
13
Infrastructure/Network (Peer-to-Peer)
■ Real peer-to-peer connections via WebRTC (coming soon)
13
Session Tracking
■ Participants can register with unique id □ Become discoverable and can receive messages ■ Participants can implement tracker behavior
Who is online?
unknown
http://lively-web.org/users/robertkrahn/2013-08-17_Lively2Lively.html 1:33 PM 8/19/13 client-session:EDA4666E-1454-48DB-A344-4E7FBF4D534A
http://lively-web.org/users/Dan/binomial-wedge.html 3:54 PM 8/9/13 client-session:7029528B-3DF8-4C50-A92E-CD779F894361
http://lively-web.org/users/Dan/QBF2B.html 4:49 PM 8/9/13 client-session:8D873406-2A70-477E-B874-0C14382CFA42
http://lively-web.org/users/Dan/FabBrowser.html 12:25 PM 8/14/13 client-session:C76EDBA4-9730-4A05-97EB-94B94A178663
http://lively-web.org/blank.html 3:22 PM 8/16/13 client-session:05FDEEB0-0E7E-46A1-8BC9-C9DE3BF0809E
http://lively-web.org/blank.html 2:11 PM 8/19/13 client-session:3A1676EA-8CF8-4FD4-A632-CCC6A912DDDB
http://www.lively-web.org/users/Dan/Fab1.html 4:50 PM 8/9/13 client-session:09A160A9-5DEF-43B8-BDF5-8BA7090682B5
http://lively-web.org/users/Dan/Fab1.html 3:06 PM 8/9/13 client-session:F0E4FCBF-2399-449E-BE2B-8013ED91E8A6
robertkrahn
http://lively-web.org/users/robertkrahn/2013-08-17_Lively2Lively.html 10:36 PM 8/19/13 client-session:2769F35D-0309-42AB-B24A-E46942D66C2A
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
13
Message Routing
13
Message Protocol (lively-json)
message = {
// REQUIRED selector for service lookup. By convention action gets
// postfixed with "Result" for response messages
action: STRING,
// REQUIRED target of the message
target: UUID,
// OPTIONAL arguments
data: OBJECT,
// OPTIONAL identifier of the message
messageId: UUID,
// OPTIONAL sender of the message
sender: UUID,
// OPTIONAL identifier of a message that this message answers
inResponseTo: UUID,
// OPTIONAL if message is an answer. Can be interpreted by the receiver as
// a streaming response. Lively participants (tracker and clients) will
// trigger data bindings and fire callbacks for a message for every streaming
// response
expectMoreResponses: BOOL,
// EXPERIMENTAL UUIDs of trackers/sessions handlers that forwarded this
// message
route: ARRAY
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
the essential part
13
Services
// this is server code:
util._extend(require("./LivelyServices").services, {
serverSayHello: function(sessionServer, connection, msg) {
connection.send({
action: msg.action + 'Result',
inResponseTo: msg.messageId,
data: 'Hello!'});
}
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
■ New server service:
// this is client code
var sess = lively.net.SessionTracker.getSession();
sess.sendTo(sess.trackerId, 'serverSayHello', {}, show);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
■ New Lively world service:
lively.net.SessionTracker.registerActions({
foobar: function(msg, session) {
session.answer(msg, 'Howdy!');
}
})
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
13
Next steps
■ Explore usage for collaborative applications □ Worlds as: service providers, workers, PartsBins, ...objects □ "Teach" other worlds/objects new behaviors --> modularization! □ Decentralized behaviors and state? PartsBin in the "cloud" ■ Is it possible to integrate JS and network address space? □ Receiver search and match ($morph? broadcasting? object matching?) ■ Underlaying mechanism for a synchronization framework?