im在解析LiveQuery时遇到问题,正如我看到的很多人那样。 现在,从日志看来,我设法订阅了“ ParseLiveQuery”
但是当我更改值,创建新行并更新back4app仪表板中的relevent属性时: 没发生
1.server正在运行,并显示客户端连接 2.app控制台收到一条日志,该日志显然显示我已成功订阅 3.我更改了仪表板中的属性
然后... 没发生
请帮助
这是我的解析服务器代码:
ParseServer node.js代码
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var path = require('path');
var databaseUri = process.env.DATABASE_URI || process.env.MONGODB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri ,
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID ,
masterKey: process.env.MASTER_KEY , //Add your master key here. Keep it secret!
serverURL: process.env.SERVER_URL || 'http://localhost:1323/parse', // Don't forget to change to https if needed
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var app = express();
// Serve static assets from the /public folder
app.use('/public', express.static(path.join(__dirname, '/public')));
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a website. Please star the parse-server repo on GitHub!');
});
// There will be a test page available on the /test path of your server url
// Remove this before launching your app
app.get('/test', function(req, res) {
res.sendFile(path.join(__dirname, '/public/test.html'));
});
var port = process.env.PORT || 1323;
var httpServer = require('http').createServer(app);
httpServer.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
// This will enable the Live Query real-time server
//ParseServer.createLiveQueryServer(httpServer);
var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer, {
appId: APP_ID',
masterKey: MASTER_KEY,
serverURL: 'http://localhost:1323/parse',
radisUrl:api.radisUrl,
classNames:['Comments'],
keyPairs: {
"javascriptKey": JAVA_KEY,
"clientKey": "CLIENT_KRY"
},
websocketTimeout: 10 * 1000,
cacheTimeout: 60 * 600 * 1000,
logLevel: 'VERBOSE',
});
api.liveQuery = parseLiveQueryServer
//parseLiveQueryServer()
应用代码:
class Comment:PFObject,PFSubclassing {
static func parseClassName() -> String {
return "Comment"
}
}
var client:Client!
var subscription: Subscription<Comment>?
client = Client(server: "http://localhost:1323/parse", applicationId: app_id, clientKey: client_key)
client.shouldPrintWebSocketTrace = true
let query: PFQuery<Comment> = PFQuery<Comment>(className: "Comments").whereKey("NeedUpdate", equalTo: true)
subscription = client.subscribe(query).handleEvent({ (comment, event) in
print("event !")
})
在运行我的应用程序时,我收到此日志: (我更改了键值(clientKey,appid)
2019-07-23 17:51:30.060457 + 0300 ParseLiveTest [90973:4911897] ParseLiveQuery:发送消息:{“ sessionToken”:“”,“ op”:“ connect”,“ applicationId”:“ applicationId”, “ clientKey”:“ clientKey”} 2019-07-23 17:51:30.063077 + 0300 ParseLiveTest [90973:4911909] ParseLiveQuery:收到消息:{“ op”:“ connected”,“ clientId”:“ f96ce095-45d8-476b-8be9-dd86b1a88d9f”} 2019-07-23 17:51:30.064071 + 0300 ParseLiveTest [90973:4911909] ParseLiveQuery:发送消息:{“ op”:“ subscribe”,“ query”:{“ where”:{“ NeedUpdate”:true},“ className“:”评论“},” requestId“:1} 2019-07-23 17:51:30.064920 + 0300 ParseLiveTest [90973:4911909] ParseLiveQuery:收到消息:{“ op”:“已订阅”,“ clientId”:“ f96ce095-45d8-476b-8be9-dd86b1a88d9f”,“ requestId” “:1}
我也尝试在我的Appdelegte中设置订阅协议: 而所有进入日志的是“ didSubscribe” 从方法中:
func didSubscribe(toQuery query: PFQuery<Comment>, inClient client: Client
完整代码如下:
client.subscribe(query, handler: self)
extension AppDelegate: SubscriptionHandling {
func didReceive(_ event: Event<Comment>, forQuery query: PFQuery<Comment>, inClient client: Client) {
print("didReceive")
}
func didEncounter(_ error: Error, forQuery query: PFQuery<Comment>, inClient client: Client) {
print("didEncounter")
}
func didSubscribe(toQuery query: PFQuery<Comment>, inClient client: Client) {
print("didSubscribe")
}
func didUnsubscribe(fromQuery query: PFQuery<Comment>, inClient client: Client) {
print("didUnsubscribe")
}
typealias PFObjectSubclass = Comment
}