本文整理汇总了Java中com.pubnub.api.Pubnub类的典型用法代码示例。如果您正苦于以下问题:Java Pubnub类的具体用法?Java Pubnub怎么用?Java Pubnub使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pubnub类属于com.pubnub.api包,在下文中一共展示了Pubnub类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listenToMessages
import com.pubnub.api.Pubnub; //导入依赖的package包/类
private void listenToMessages() {
try {
pb = new Pubnub(PUBNUB_PUB_KEY, PUBNUB_SUB_KEY);
pb.subscribe(tokenPrefix + uniqueId, new Callback() {
@Override
public void successCallback(String channel, Object message, String timetoken) {
if(message instanceof String) {
pendingAck.remove(channel);
return;
}
Message m = new Message((JSONObject)message);
pb.publish(tokenPrefix + m.getSenderId(), "ACK", new Callback() {});
Display.getInstance().callSerially(() -> {
addMessage(m);
respond(m);
});
}
});
} catch(PubnubException err) {
Log.e(err);
Dialog.show("Error", "There was a communication error: " + err, "OK", null);
}
}
示例2: presence
import com.pubnub.api.Pubnub; //导入依赖的package包/类
/**
* Listen to presence events for a channel. Accepts a listener and channel and
* registers for presence events. TODO://REFACTOR..
*
* @param roomName
* @param presenceListener
*/
public void presence(String roomName, final ChatterBoxCallback presenceListener) {
List<ChatterBoxCallback> listeners = new ArrayList<ChatterBoxCallback>();
listeners.add(presenceListener);
HashMap<String, UserProfile> presenceCache =
chatterBoxService.getPresenceCache();
Pubnub pubnub = chatterBoxService.getPubNub();
try {
pubnub.presence(roomName, new PresenceCallback(listeners, pubnub, presenceCache));
} catch (PubnubException e) {
Log.e(Constants.LOGT, "exception while attempting to register for presence", e);
}
}
示例3: setUp
import com.pubnub.api.Pubnub; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
module = new TestModule();
module.putMock(Gson.class, new GsonProvider().get());
when(module.getMock(ExecutorFactory.class).get(any(Class.class))).thenReturn(newDirectExecutorService());
gson = module.getMock(Gson.class);
pubNub = module.getMock(PubNub.class);
SubscribeBuilder sb = module.getMock(SubscribeBuilder.class);
when(sb.channels(anyListOf(String.class))).thenReturn(sb);
when(pubNub.subscribe()).thenReturn(sb);
UnsubscribeBuilder ub = module.getMock(UnsubscribeBuilder.class);
when(ub.channels(anyListOf(String.class))).thenReturn(ub);
when(pubNub.unsubscribe()).thenReturn(ub);
l1 = mock(RealtimeListener.class);
l2 = mock(RealtimeListener.class);
l3 = mock(RealtimeListener.class);
target = new RealtimeServiceImpl(module.createInjector());
}
示例4: testGet_Configured
import com.pubnub.api.Pubnub; //导入依赖的package包/类
@Test
public void testGet_Configured() throws Exception {
when(module.getEnvironment().getTimeout()).thenReturn(Duration.ofMillis(1234));
when(module.getEnvironment().getProxy()).thenReturn(NO_PROXY);
when(module.getEnvironment().getPubNubKey()).thenReturn("testkey");
when(module.getEnvironment().getPubNubSecure()).thenReturn(Boolean.TRUE);
when(module.getEnvironment().getPubNubReconnect()).thenReturn(LINEAR);
PubNub pn = target.get();
assertEquals(pn.getConfiguration().getSubscribeKey(), "testkey");
assertEquals(pn.getConfiguration().isSecure(), true);
assertEquals(pn.getConfiguration().getProxy(), NO_PROXY);
assertEquals(pn.getConfiguration().getConnectTimeout(), 1);
assertEquals(pn.getConfiguration().getReconnectionPolicy(), LINEAR);
pn.destroy();
}
示例5: HistoryAdapter
import com.pubnub.api.Pubnub; //导入依赖的package包/类
public HistoryAdapter(Context context, List<HistoryItem> values, Pubnub pubnub) {
super(context, R.layout.history_row_layout, android.R.id.text1, values);
this.context = context;
this.inflater = LayoutInflater.from(context);
this.mPubNub = pubnub;
this.values = values;
this.users = new HashMap<String, ChatUser>();
updateHistory();
}
示例6: PnPeerConnectionClient
import com.pubnub.api.Pubnub; //导入依赖的package包/类
public PnPeerConnectionClient(Pubnub pubnub, PnSignalingParams signalingParams, PnRTCListener rtcListener){
this.mPubNub = pubnub;
this.signalingParams = signalingParams;
this.mRtcListener = rtcListener;
this.pcFactory = new PeerConnectionFactory(); // TODO: Check it allowed, else extra param
this.peers = new HashMap<String, PnPeer>();
sessionID = this.mPubNub.uuid();
init();
}
示例7: PnRTCClient
import com.pubnub.api.Pubnub; //导入依赖的package包/类
/**
* Minimal constructor. Requires a valid Pub and Sub key. Get your Pub/Sub keys for free at
* https://admin.pubnub.com/#/register and find keys on developer portal.
* No UUID provided so a random phone number will be generated with this constructor (XXX-XXXX).
* @param pubKey PubNub Pub Key
* @param subKey PubNub Sub Key
*/
public PnRTCClient(String pubKey, String subKey) {
this.UUID = generateRandomNumber();
this.mPubNub = new Pubnub(pubKey, subKey);
this.mPubNub.setUUID(this.UUID);
this.pnSignalingParams = PnSignalingParams.defaultInstance();
this.pcClient = new PnPeerConnectionClient(this.mPubNub, this.pnSignalingParams, new PnRTCListener() {});
}
示例8: sendMessage
import com.pubnub.api.Pubnub; //导入依赖的package包/类
public static void sendMessage(String channelName,String message)
{
final Pubnub pubnub = new Pubnub("pub-c-f9d02ea4-19f1-4737-b3e1-ef2ce904b94f", "sub-c-3d547124-be29-11e5-8a35-0619f8945a4f");
final JSONObject data = new JSONObject();
try {
data.put("username",ParseUser.getCurrentUser().getUsername());
data.put("message",message);
data.put("displayname",ParseUser.getCurrentUser().getString("displayname"));
pubnub.publish(channelName, data, new Callback() {
});
} catch (JSONException e) {
e.printStackTrace();
}
}
示例9: PnPeerConnectionClient
import com.pubnub.api.Pubnub; //导入依赖的package包/类
public PnPeerConnectionClient(Pubnub pubnub, PnSignalingParams signalingParams, PnRTCListener rtcListener){
this.mPubNub = pubnub;
this.signalingParams = signalingParams;
this.mRtcListener = rtcListener;
this.pcFactory = new PeerConnectionFactory(); // TODO: Check it allowed, else extra param
this.peers = new HashMap<String, PnPeer>();
init();
}
示例10: PubNubLocationChannelImpl
import com.pubnub.api.Pubnub; //导入依赖的package包/类
public PubNubLocationChannelImpl(String publishKey, String subscribeKey) {
if (TextUtils.isEmpty(publishKey)
|| TextUtils.isEmpty(subscribeKey)) {
throw new IllegalArgumentException("all arguments must be non null");
}
mPubNub = new Pubnub(publishKey, subscribeKey);
}
示例11: publish
import com.pubnub.api.Pubnub; //导入依赖的package包/类
private static void publish(final String channel, final String payload) {
final Pubnub pubnub = sPubnub;
pubnub.publish(channel, payload, new Callback() {
@Override
public void successCallback(String arg0, Object arg1) {
}
});
}
示例12: createMockedPubNub
import com.pubnub.api.Pubnub; //导入依赖的package包/类
private PubNub createMockedPubNub() {
PNConfiguration pnConfiguration = new PNConfiguration();
pnConfiguration.setOrigin("localhost:8080/camel-pubnub-tests/");
pnConfiguration.setSecure(false);
pnConfiguration.setSubscribeKey("wfcSubscribeKey");
pnConfiguration.setPublishKey("wfcPublishKey");
pnConfiguration.setUuid("wfcUUID");
pnConfiguration.setLogVerbosity(PNLogVerbosity.NONE);
pnConfiguration.setHeartbeatNotificationOptions(NONE);
class MockedPubNub extends PubNub {
MockedPubNub(PNConfiguration initialConfig) {
super(initialConfig);
}
@Override
public int getTimestamp() {
return 12345;
}
@Override
public String getVersion() {
return "WFC Test 1.0";
}
@Override
public String getInstanceId() {
return "PubNubInstanceId";
}
@Override
public String getRequestId() {
return "PubNubRequestId";
}
}
return new MockedPubNub(pnConfiguration);
}
示例13: initPubNub
import com.pubnub.api.Pubnub; //导入依赖的package包/类
/**
* Subscribe to standby channel so that it doesn't interfere with the WebRTC Signaling.
*/
public void initPubNub(){
this.mPubNub = new Pubnub(Constants.PUB_KEY, Constants.SUB_KEY);
this.mPubNub.setUUID(this.username);
subscribeStdBy();
}
示例14: initPubNub
import com.pubnub.api.Pubnub; //导入依赖的package包/类
private void initPubNub() {
PUBNUB_INSTANCE =new Pubnub(this.PUBNUB_PUBLISH_KEY,this.PUBNUB_SUBSCRIBE_KEY);
}
示例15: getPubnubInstance
import com.pubnub.api.Pubnub; //导入依赖的package包/类
public Pubnub getPubnubInstance(){
return PUBNUB_INSTANCE;
}