2013-07-16 64 views

回答

7

:與在鍵值存儲中一樣,鍵對象是您用來管理和監視GoInstant中的值的界面。您應該將它們用於CRUD(創建,讀取,更新刪除)。

重要的例子:

// We create a new key using our room object 
var movieName = yourRoom.key(‘movieName’); 

// Prepare a handler for our `on` set event 
function setHandler(value) { 
    console.log(‘Movie has a new value’, value); 
} 

// Now when the value of our key is set, our handler will fire 
movieName.on(‘set’, setHandler); 

// Ready, `set`, GoInstant :) 
movieName.set('World War Z', function(err) { 
    if (!err) alert('Movie set successfully!') 
} 

頻道:代表全雙工通訊接口。設想一個多客戶端發佈/訂閱系統。頻道不存儲數據,您無法從頻道檢索郵件,只能收到該郵件。您應該使用它來在共享會話的客戶端之間傳播事件。

通道例如:

var mousePosChannel = yourRoom.channel('mousePosChannel'); 

// When the mouse moves, broadcast the mouse co-ordinates in our channel 
$(window).on('mousemove', function(event) { 
    mousePosChannel.message({ 
    posX: event.pageX, 
    posY: event.pageY 
    }); 
}); 

// Every client in this session can listen for changes to 
// any users mouse location 
mousePosChannel.on('message', function(msg) { 
    console.log('A user in this room has moved there mouse too', msg.posX, msg.posY); 
}) 

你可以找到的官方文檔在這裏:

重點:https://developers.goinstant.net/v1/key/index.html

頻道:https://developers.goinstant.net/v1/channel/index.html