Skip to content

Trinity.js #1

Description

@kingfo

Use Trinity.js

Configuration

trinity.config(
    {
        group: '_group',                                            //当前公共组
        debug: true,                                                //调试开关
        base: 'PATH/TO/YOUR/TRINITY/FLASH/FILE.swf',                //Trintiy Flash 路径
        flash:{
            timeout: 20000,                                         //Flash等待加载最长时间 单位:毫秒(ms)
            params:{                                                //支持部分 Flash 播放参数 [参考这里](http://docs.kissyui.com/docs/html/api/component/flash/practice/flashplayer-parameters.html)
                wmode:'opaque',                                 
                bgcolor:'0xFF0000'
                devicefont:true,
                base:'PATH/TO/YOUR/BASE/URI'
                seamlesstabbing:true
                hasPriority:true        
            }
            attributes:{                                            //除保留的 id 外其他的所有 flash html 元素属性

            }
        }
    }
);

Bootstrapping

trinity.embed(this);

Usage

Local Application Network events (LAP events)

Master Node
trinity.onSWFReady(function(trinity){

});

trinity.onMaster(function(name){

});

trinity.onJoin(function(name){

});
trinity.onMessage(function(msg){

});

trinity.onStatus(function(protocol){

});
trinity.onError(function(protocol){

});
Node
trinity.onSWFReady(function(trinity){

});

trinity.onJoin(function(name){

});
trinity.onMessage(function(msg){

});

trinity.onStatus(function(protocol){

});
trinity.onError(function(protocol){

});

Local Application Network API (LAP API)

Broadcast
// Master
trinity.onStatus(function(protocol){
    alert(protocol.from == trinity.name); //true;
    alert(protocol.getway == trinity.group); //true;
    alert(protocol.type == 0); //true;
    alert(protocol.body == 'hello world!'); //true;
});
trinity.onMessage(function(msg){
    alert(msg == 'hello world!'); // true
});
trinity.fire('hello world!');

// Node
trinity.onMessage(function(msg){
    alert(msg == 'hello world!');// true
});
// Master
trinity.onMessage(function(msg){
    alert(msg == 'hello world!'); // true
});

// Node
trinity.onMessage(function(msg){
    alert(msg == 'hello world!');// true
});
trinity.onStatus(function(protocol){
    alert(protocol.from == trinity.name); //true;
    alert(protocol.getway == trinity.group); //false;
    alert(protocol.type == 0); //true;
    alert(protocol.body == 'hello world!'); //true;
});
trinity.fire('hello world!');
Unicast
// Master
trinity.onStatus(function(protocol){
    alert(protocol.from == trinity.name); //true;
    alert(protocol.getway == trinity.group); //true;
    alert(protocol.type == 0); //true;
    alert(protocol.body == 'hello world!'); //true;
});
trinity.fire('hello world!',NODE_NAME);

// Node
trinity.onMessage(function(msg){
    alert(msg == 'hello world!');
});
// Master
trinity.onMessage(function(msg){
    alert(msg == 'hello world!');
});

// Node
trinity.onStatus(function(protocol){
    alert(protocol.from == trinity.name); //true;
    alert(protocol.getway == trinity.group); //false;
    alert(protocol.type == 0); //true;
    alert(protocol.body == 'hello world!'); //true;
});
trinity.fire('hello world!',trinity.group);
Broadcast or Unicast Error
trinity.fire('hello world!',NODE_NAME);
trinity.onError(function(protocol){
    alert(protocol.body == 'hello world!'); //true;
    alert(protocol.to + ' is unlinked.' );
    //...
});
Storage
// Master only
trinity.setItem('key','value');
trinity.onStorage(function (info,key,oldValue,newValue){

});
trinity.onOpen(function (){

});
trinity.onCreation(function (){

});
trinity.onUncompressError(function (msg){

});
trinity.onFlushError(function (msg,code){

});
trinity.onFlushed(function (){

});
trinity.onPending(function (key){

});
trinity.onNetStatus(function(){

});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions