2013-07-16 2 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!') 
} 

채널 : 전이중 메시징 인터페이스를 나타냅니다. 다중 클라이언트 pub/sub 시스템을 상상해보십시오. 채널은 데이터를 저장하지 않으며 채널에서 메시지를 검색 할 수 없으며 수신 만 할 수 있습니다. 세션을 공유하는 클라이언트간에 이벤트를 전파하려면이를 사용해야합니다.

채널 예 :

키 :

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

관련 문제