Commit cb836097 authored by Constantin Jucovschi's avatar Constantin Jucovschi

new sources

parent 3feff1e7
var info_kwarc_sally_comm_core = {
name: 'info_kwarc_sally_comm_core',
defaultElementNamespaceURI: 'http:\/\/kwarc.info\/sally\/comm\/core',
typeInfos: [{
type: 'classInfo',
localName: 'HeartbeatResponse',
propertyInfos: []
}, {
type: 'classInfo',
localName: 'HeartbeatRequest',
propertyInfos: []
}, {
type: 'classInfo',
localName: 'RegisterClientResponse',
propertyInfos: [{
type: 'element',
name: 'sendQueue',
elementName: 'SendQueue',
typeInfo: 'String'
}]
}, {
type: 'classInfo',
localName: 'RegisterClientRequest',
propertyInfos: [{
type: 'element',
name: 'listenQueue',
elementName: 'ListenQueue',
typeInfo: 'String'
}, {
type: 'element',
name: 'schemas',
collection: true,
elementName: 'Schemas',
typeInfo: 'String'
}, {
type: 'element',
name: 'environmentID',
elementName: 'EnvironmentID',
typeInfo: 'String'
}]
}],
elementInfos: [{
elementName: 'HeartbeatResponse',
typeInfo: 'info_kwarc_sally_comm_core.HeartbeatResponse'
}, {
elementName: 'HeartbeatRequest',
typeInfo: 'info_kwarc_sally_comm_core.HeartbeatRequest'
}, {
elementName: 'RegisterClientResponse',
typeInfo: 'info_kwarc_sally_comm_core.RegisterClientResponse'
}, {
elementName: 'RegisterClientRequest',
typeInfo: 'info_kwarc_sally_comm_core.RegisterClientRequest'
}]
};
if (typeof require === 'function') {
module.exports.info_kwarc_sally_comm_core = info_kwarc_sally_comm_core;
}
\ No newline at end of file
var info_kwarc_sally_comm_frames = {
name: 'info_kwarc_sally_comm_frames',
defaultElementNamespaceURI: 'http:\/\/kwarc.info\/sally\/comm\/frames',
typeInfos: [{
type: 'classInfo',
localName: 'ShowSallyFrameMenu',
propertyInfos: [{
type: 'element',
name: 'posx',
elementName: 'posx',
typeInfo: 'Int'
}, {
type: 'element',
name: 'posy',
elementName: 'posy',
typeInfo: 'Int'
}]
}],
elementInfos: [{
elementName: 'ShowSallyFrameMenu',
typeInfo: 'info_kwarc_sally_comm_frames.ShowSallyFrameMenu'
}]
};
if (typeof require === 'function') {
module.exports.info_kwarc_sally_comm_frames = info_kwarc_sally_comm_frames;
}
\ No newline at end of file
var info_kwarc_sally_comm_theo = {
name: 'info_kwarc_sally_comm_theo',
defaultElementNamespaceURI: 'http:\/\/kwarc.info\/sally\/comm\/theo',
typeInfos: [{
type: 'classInfo',
localName: 'OpenTheoWindowRequest',
propertyInfos: [{
type: 'element',
name: 'url',
elementName: 'url',
typeInfo: 'String'
}, {
type: 'element',
name: 'title',
elementName: 'title',
typeInfo: 'String'
}, {
type: 'element',
name: 'posx',
elementName: 'posx',
typeInfo: 'Int'
}, {
type: 'element',
name: 'posy',
elementName: 'posy',
typeInfo: 'Int'
}, {
type: 'element',
name: 'width',
elementName: 'width',
typeInfo: 'Int'
}, {
type: 'element',
name: 'height',
elementName: 'height',
typeInfo: 'Int'
}]
}, {
type: 'classInfo',
localName: 'CloseTheoWindow',
propertyInfos: [{
type: 'element',
name: 'id',
elementName: 'id',
typeInfo: 'String'
}]
}, {
type: 'classInfo',
localName: 'OpenTheoWindowResponse',
propertyInfos: [{
type: 'element',
name: 'id',
elementName: 'id',
typeInfo: 'String'
}]
}],
elementInfos: [{
elementName: 'OpenTheoWindowRequest',
typeInfo: 'info_kwarc_sally_comm_theo.OpenTheoWindowRequest'
}, {
elementName: 'CloseTheoWindow',
typeInfo: 'info_kwarc_sally_comm_theo.CloseTheoWindow'
}, {
elementName: 'OpenTheoWindowResponse',
typeInfo: 'info_kwarc_sally_comm_theo.OpenTheoWindowResponse'
}]
};
if (typeof require === 'function') {
module.exports.info_kwarc_sally_comm_theo = info_kwarc_sally_comm_theo;
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
define (require) ->
require "info_kwarc_sally_comm_frames"
require "jsonix"
context = new Jsonix.Context([ info_kwarc_sally_comm_frames ]);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
createShowSallyFrameMenu = (x, y) ->
{
name :
localPart : "ShowSallyFrameMenu"
namespaceURI : "http://kwarc.info/sally/comm/frames"
value :
"posx" : x,
"posy" : y
}
class Frames
getName : () -> "frames"
marshal : (obj) -> marshaller.marshalString(obj)
unmarshal : (str) -> unmarshaller.unmarshalString(str)
requestOnShowSallyFrames : (x, y) ->
@send(createShowSallyFrameMenu(x, y))
handleMessage : (msg) ->
\ No newline at end of file
# using requirejs makes Jsonix think that it is running from within NodeJS and produces unnecessary errors.
# window.module = {exports : {} }
define (require) ->
require "stomp"
require "jsonix"
xmlns = new RegExp("xmlns(:(\\w+))?=\"http://kwarc.info/sally/comm/([\\w/:.]+)\"");
EventEmitter = require "EventEmitter"
require "info_kwarc_sally_comm_core"
context = new Jsonix.Context([ info_kwarc_sally_comm_core ]);
unmarshaller = context.createUnmarshaller();
marshaller = context.createMarshaller();
createRegisterDocument = (docQueue, envid, schemas) ->
{
name :
localPart : "RegisterClientRequest"
namespaceURI : "http://kwarc.info/sally/comm/core"
value :
"listenQueue" : docQueue,
"environmentID" : envid,
"schemas" : _.map(schemas, (x) -> x.getName())
}
heartBeatResponse =
name :
localPart : "HeartbeatResponse"
namespaceURI : "http://kwarc.info/sally/comm/core"
value : {}
connections = {};
class SallyClient
constructor : (@config, @msgHandler) ->
if connections[config.stompUrl]?
@stompClient = connections[config.stompUrl]
else
@stompClient = Stomp.client(config.stompUrl)
connections[config.stompUrl] = @stompClient
@stompClient.connect(config.stompUser, config.stompPassword, ((frame) ->
@stompClient.connection_div.emit("onConnected");
).bind(@))
register : (@schemas, envid, callback) ->
me = @;
client = @stompClient
if client.connected
return callback();
if not client.connection_div?
client.connection_div = new EventEmitter()
schemaMap = {};
_.each(@schemas, (x) -> schemaMap[x.getName()] = x; );
client.connection_div.on("onConnected", (e) =>
@privateQueue = "editor_tools_"+Math.floor(Math.random()*100000);
@stompClient.subscribe("/queue/"+@privateQueue, (msg) =>
namespace = xmlns.exec(msg.body)[3];
console.log(namespace)
if namespace == "core"
body = unmarshaller.unmarshalString(msg.body)
if body.name.localPart == "HeartbeatRequest"
@send(msg.headers["reply-to"], marshaller.marshalString(heartBeatResponse), null, {"correlation-id" : msg.headers["correlation-id"]})
return;
else
handler = schemaMap[namespace];
body = handler.unmarshal(msg.body)
handler.handleMessage(body, (sendBack) =>
@send(msg.headers["reply-to"], handler.marshal(sendBack), null,
{"correlation-id" : msg.headers["correlation-id"]})
)
)
@send("/queue/sally_register", marshaller.marshalString(createRegisterDocument(@privateQueue, envid, schemas)), (msg) =>
sally_queue = msg.value.sendQueue;
_.each schemas, (x) =>
x.send = (msg, callback, headers) =>
me.send(sally_queue, x.marshal(msg), callback, headers);
callback();
)
)
send : (destination, msg, callback, headers) ->
if callback?
corrid = Math.random();
queue_post = "/temp-queue/editor_exchange"+corrid;
sub = @stompClient.subscribe(queue_post, (msg) =>
body = unmarshaller.unmarshalString(msg.body)
if callback(body, msg) == true
return;
@stompClient.unsubscribe(corrid);
, {"id" : corrid})
headers ?= {};
headers["reply-to"] = queue_post;
headers["correlation-id"] = corrid;
console.log("sending to ", destination, " msg ", msg)
@stompClient.send(destination, headers, msg.toString())
define (require) ->
require "info_kwarc_sally_comm_theo"
require "jsonix"
uniqueId = (length=8) ->
id = ""
id += Math.random().toString(36).substr(2) while id.length < length
id.substr 0, length
openedWindows = {}
context = new Jsonix.Context([ info_kwarc_sally_comm_theo ]);
marshaller = context.createMarshaller();
unmarshaller = context.createUnmarshaller();
class Theo
getName : () -> "theo"
marshal : (obj) -> marshaller.marshalString(obj)
unmarshal : (str) -> unmarshaller.unmarshalString(str)
handleMessage : (msg, sendBack) ->
if (msg.name.localPart == "OpenTheoWindowRequest")
id = @showTheoWindow(msg.value.url, msg.value.title, msg.value.posx, msg.value.posy, msg.value.width, msg.value.height)
sendBack {
name :
localPart : "OpenTheoWindowResponse"
namespaceURI : "http://kwarc.info/sally/comm/theo"
value :
"id" : id,
}
if (msg.name.localPart == "CloseTheoWindow")
id = msg.value.id
if openedWindows[id]?
openedWindows[id]
showTheoWindow : (url, title, posx, posy, width="auto", height="auto") ->
frame = $("<iframe>").attr("src", url).css("width", "100%").attr("frameborder", 0).attr("marginwidth", 0).attr("marginheight", 0).css("height", height);
dv = $("<div>").append(frame).css("overflow", "hidden").css("padding-left", "0px").css("padding-right", "0px");
id = uniqueId()
$(dv).dialog({
title: title
height : height,
width : width,
position : [posx, posy],
resize: (e, ui) ->
frame.css("height", "100%")
close : () ->
delete openedWindows[id]
$(dv).dialog( "destroy" );
});
openedWindows[id] = dv;
id
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment