未从pubnub获取发布消息,但在pubnub历史记录响应中显示。
案例: 在下面提到的发布响应后,没有从设备端获取发布消息。但是在pubnub历史响应中显示设备消息。
{
:code=>200,
:operation=>:publish,
:client_request=>#<URI::HTTP http://pubsub.pubnub.com/publish/pub-c-****-37d32e2a1d43/sub-c-***-0619f8945a4f/0/broadcast_57c05de753545020a5000000/0/%7B%22channelType%22%3A%222%22%2C%22PublisherId%22%3A%22577e0cfc69702d11fb010000%22%2C%22listener_count%22%3A%225%22%2C%22totalLikeCount%22%3A%220%22%2C%22chat_id%22%3A%2257c05fe5535450232b040000%22%2C%22created_at%22%3A%222016-08-26T15%3A27%3A33.548Z%22%2C%22pubnub_timestamp%22%3Anull%2C%22text%22%3A%22samar_us7%40yopmail.com%20has%20join%20broadcast.%22%2C%22type%22%3A%22JoinUser%22%2C%22user%22%3A%7B%22bio%22%3Anull%2C%22country%22%3A%22US%22%2C%22email%22%3A%22samar_us7%40yopmail.com%22%2C%22initial_sync_done%22%3Atrue%2C%22is_syncing%22%3Afalse%2C%22two_years_sync_done%22%3Atrue%2C%22account_type%22%3A%22SPTProductUnknown%22%2C%22name%22%3A%22samar_us7%40yopmail.com%22%2C%22platform_id%22%3A%22samar_us7%22%2C%22platform_url%22%3A%22https%3A%2F%2Fopen.spotify.com%2Fuser%2Fsamar_us7%22%2C%22user_id%22%3A%22577e0cfc69702d11fb010000%22%2C%22listeners_count%22%3A2%2C%22lyric%22%3A%22Rebirth%20of%20Cool%22%2C%22profile_picture_url%22%3A%22http%3A%2F%2F192.168.1.64%3A3000%2Fassets%2Fuser_profile_small_cover_image.png%22%2C%22likes%22%3A0%2C%22followers%22%3A2%2C%22following%22%3A0%2C%22broadcasts%22%3A104%2C%22broadcast_listeners_count%22%3A343%7D%7D?pnsdk=PubNub-Ruby/4.0.7&uuid=d966d2a7-5d7e-4fac-8158-1b9a15226165&seqn=6&ortt=%7B%22t%22%3A14722252542914316%7D>,
:server_response=>#<HTTP::Message:0x000000044fa1d8 @http_header=#<HTTP::Message::Headers:0x000000044fa160 @http_version="1.1", @body_size=0, @chunked=false, @request_method="GET", @request_uri=#<Addressable::URI:0x227d7b8 URI:http://pubsub.pubnub.com/publish/pub-c-***-37d32e2a1d43/sub-c-***-0619f8945a4f/0/broadcast_57c05de753545020a5000000/0/%7B%22channelType%22%3A%222%22%2C%22PublisherId%22%3A%22577e0cfc69702d11fb010000%22%2C%22listener_count%22%3A%225%22%2C%22totalLikeCount%22%3A%220%22%2C%22chat_id%22%3A%2257c05fe5535450232b040000%22%2C%22created_at%22%3A%222016-08-26T15%3A27%3A33.548Z%22%2C%22pubnub_timestamp%22%3Anull%2C%22text%22%3A%22samar_us7%40yopmail.com%20has%20join%20broadcast.%22%2C%22type%22%3A%22JoinUser%22%2C%22user%22%3A%7B%22bio%22%3Anull%2C%22country%22%3A%22US%22%2C%22email%22%3A%22samar_us7%40yopmail.com%22%2C%22initial_sync_done%22%3Atrue%2C%22is_syncing%22%3Afalse%2C%22two_years_sync_done%22%3Atrue%2C%22account_type%22%3A%22SPTProductUnknown%22%2C%22name%22%3A%22samar_us7%40yopmail.com%22%2C%22platform_id%22%3A%22samar_us7%22%2C%22platform_url%22%3A%22https%3A%2F%2Fopen.spotify.com%2Fuser%2Fsamar_us7%22%2C%22user_id%22%3A%22577e0cfc69702d11fb010000%22%2C%22listeners_count%22%3A2%2C%22lyric%22%3A%22Rebirth%20of%20Cool%22%2C%22profile_picture_url%22%3A%22http%3A%2F%2F192.168.1.64%3A3000%2Fassets%2Fuser_profile_small_cover_image.png%22%2C%22likes%22%3A0%2C%22followers%22%3A2%2C%22following%22%3A0%2C%22broadcasts%22%3A104%2C%22broadcast_listeners_count%22%3A343%7D%7D?pnsdk=PubNub-Ruby/4.0.7&uuid=d966d2a7-5d7e-4fac-8158-1b9a15226165&seqn=5&ortt=%7B%22t%22%3A14722252541270930%7D>, @request_query=nil, @request_absolute_uri=nil, @status_code=200, @reason_phrase="OK", @body_type=nil, @body_charset=nil, @body_date=nil, @body_encoding=#<Encoding:UTF-8>, @is_request=false, @header_item=[["Date", "Fri, 26 Aug 2016 15:27:33 GMT"], ["Content-Type", "text/javascript; charset=\"UTF-8\""], ["Content-Length", "30"], ["Connection", "keep-alive"], ["Cache-Control", "no-cache"], ["Access-Control-Allow-Origin", "*"], ["Access-Control-Allow-Methods", "GET"]], @dumped=false>, @peer_cert=nil, @http_body=#<HTTP::Message::Body:0x000000044f9f08 @body="[1,\"Sent\",\"14722252530221972\"]", @size=0, @positions=nil, @chunk_size=nil>, @previous=nil>,
:data=>nil,
:category=>:ack,
:error=>false,
:auto_retried=>false,
:current_timetoken=>nil,
:last_timetoken=>nil,
:subscribed_channels=>nil,
:subscribed_channel_groups=>nil,
:config=>{
:tls=>false,
:uuid=>"d966d2a7-5d7e-4fac-8158-1b9a15226165",
:auth_key=>nil,
:origin=>"pubsub.pubnub.com"
}
}
IOS代码:
发布代码:
[ApplicationDelegate.client publish:publishChatDictionary toChannel:[NSString stringWithFormat:@"broadcast_%@",[BroadcastManager sharedInstance].broadcast.identifier] withCompletion:^(PNPublishStatus * _Nonnull status) {
if (!status.isError) {
chat.pubNubTimeStamp = [NSString stringWithFormat:@"%ld",(long)[status.data.timetoken integerValue]];
// Message successfully published to specified channel.
}else {
// because of which request did fail.
// Request can be resent using:
[status retry];
}
}];
// Subsriber代码:
[ApplicationDelegate.client addListener:(id)self];
// [ApplicationDelegate.client.currentConfiguration setUUID:[UserManager sharedInstance].user.identifier];
[ApplicationDelegate.client subscribeToChannels: @[[NSString stringWithFormat:@"broadcastLikes_%@",[BroadcastManager sharedInstance].broadcast.identifier], [NSString stringWithFormat:@"broadcast_%@",[BroadcastManager sharedInstance].broadcast.identifier]] withPresence:YES];
//Callback method:
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
// Handle new message stored in message.data.message
if (message.data.actualChannel) {
// Message has been received on channel group stored in
// message.data.subscribedChannel
}
else {
// Message has been received on channel stored in
// message.data.subscribedChannel
}
}
我有ruby代码,我添加了状态回调,我想知道,代码中有什么问题。请检查下面的内容并告诉我。
订阅者回调:
def callbacks
callbacks = Pubnub::SubscribeCallback.new(
message: ->(envelope) {
# puts "#{envelope.result[:data]}"
subscription_callback(envelope.result)
},
presence: ->(envelope) {
# puts #{envelope.result[:data][:message]}"
presence_callback(envelope.result)
},
status: ->(envelope) do
if envelope.status[:error]
case envelope.status[:category]
when Pubnub::Constants::STATUS_ACCESS_DENIED # :access_denied
puts "Access Denied"
when Pubnub::Constants::STATUS_TIMEOUT # :timeout
puts "Timeout error"
when Pubnub::Constants::STATUS_NON_JSON_RESPONSE # :non_json_response
puts "Non json response"
when Pubnub::Constants::STATUS_API_KEY_ERROR # :api_key_error
puts "API key error"
when Pubnub::Constants::STATUS_ERROR
puts "Other Pubnub error"
else
puts "Something went wrong"
end
end
end
)
end
Presence Callback:
def presence_callback(result)
Pubnub.logger.info("==============================================================presence_callback")
Pubnub.logger.info(result.to_json)
broadcast_id = result[:channel].split("_")[1] rescue result[:data][:subscribed_channel].split("-")[0].split("-")[1]
broadcast = Broadcast.find(broadcast_id)
if broadcast.is_fake_broadcast
track = Track.with_platform_id(broadcast.current_track_id, "Spotify").first
Pubnub.logger.info("============================================================== channel : #{channel}, state : #{state}, uuid : #{uuid}")
Pubnub.logger.info(result.to_json)
state = { "is_live" => broadcast.is_live, "listener_count" => broadcast.broadcast_listener_ids.count.to_s, "likeIcons" => broadcast.fetch_used_like_images, "totalLikeCount" => broadcast.get_broadcast_likes_count, "is_track_change" => false, "track" => track.as_json, "track_count" => broadcast.tracks.count, "track_position" => broadcast.set_track_position}
if result[:action] == 'join'
$pubnub.set_state(channel: result[:channel], state: state) do |envelope|
puts envelope.result[:data][:state]
end
elsif result[:action] == 'leave'
$pubnub.set_state(channel: result[:channel], state: state) do |envelope|
puts envelope.result[:data][:state]
end
end
end
end