Copy {
"appId": 'my_app_id',
"masterKey": 'my_master_key',
// ...
"liveQuery": {
"classNames": ['Test', 'TestAgain'] // Live Query 要支援的 Class
}
}
Copy // 原本 Express
let httpServer = require('http').createServer(app);
httpServer.listen(port);
// 新增 Live Query Server
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);
LiveQuery 服務器的 ws protocol 會沿用 http(s)Server 監聽的主機名和端口。例如,如果 http(s)Sever 正在偵聽 localhost:8080,則 LiveQuery 服務器的 ws protocol 為 ws://localhost:8080/
Copy dependencies {
compile 'com.parse:parse-livequery-android:1.0.4'
}
Copy ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class);
ParseLiveQueryClient parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient();
SubscriptionHandling<ParseObject> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);
Copy subscriptionHandling.handleEvents(new SubscriptionHandling.HandleEventsCallback<ParseObject>() {
@Override
public void onEvents(ParseQuery<ParseObject> query, SubscriptionHandling.Event event, ParseObject object) {
// HANDLING all events
}
})
Copy subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, new SubscriptionHandling.HandleEventCallback<ParseObject>() {
@Override
public void onEvent(ParseQuery<ParseObject> query, ParseObject object) {
// HANDLING create events
}
})
Copy let myQuery = Message.query()!.where(....)
let subscription: Subscription<Message> = Client.shared.subscribe(myQuery)
Copy subscription.handleEvent { query, event in
// HANDLING all events
}
Copy subscription.handle(Event.created) { query, object in
// HANDLING create events
}