当前位置: 首页>>代码示例>>Java>>正文


Java Pubnub类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:codenameone,项目名称:codenameone-demos,代码行数:24,代码来源:SocialChat.java

示例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);
    }
}
 
开发者ID:groupflix,项目名称:android-pubnub-example,代码行数:25,代码来源:ChatterBoxClient.java

示例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());

}
 
开发者ID:after-the-sunrise,项目名称:bitflyer4j,代码行数:26,代码来源:RealtimeServiceImplTest.java

示例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();

}
 
开发者ID:after-the-sunrise,项目名称:bitflyer4j,代码行数:21,代码来源:PubNubProviderTest.java

示例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();
}
 
开发者ID:newbie007fx,项目名称:newwebrtc,代码行数:10,代码来源:HistoryAdapter.java

示例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();
}
 
开发者ID:newbie007fx,项目名称:newwebrtc,代码行数:10,代码来源:PnPeerConnectionClient.java

示例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() {});
}
 
开发者ID:newbie007fx,项目名称:newwebrtc,代码行数:15,代码来源:PnRTCClient.java

示例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();
    }
}
 
开发者ID:AvijitGhosh82,项目名称:Madad_SOS,代码行数:15,代码来源:comm.java

示例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();
}
 
开发者ID:GleasonK,项目名称:android-webrtc-api,代码行数:9,代码来源:PnPeerConnectionClient.java

示例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);

    }
 
开发者ID:IndoorAtlas,项目名称:android-sdk-examples,代码行数:10,代码来源:PubNubLocationChannelImpl.java

示例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) {
		}
	});
}
 
开发者ID:WomenWhoCode,项目名称:MentorMe,代码行数:9,代码来源:NotificationCenter.java

示例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);
    }
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:41,代码来源:PubNubIntegrationTest.java

示例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();
}
 
开发者ID:newbie007fx,项目名称:newwebrtc,代码行数:9,代码来源:MainActivity.java

示例14: initPubNub

import com.pubnub.api.Pubnub; //导入依赖的package包/类
private void initPubNub() {
        PUBNUB_INSTANCE =new Pubnub(this.PUBNUB_PUBLISH_KEY,this.PUBNUB_SUBSCRIBE_KEY);
}
 
开发者ID:shyampurk,项目名称:bluemix-todo-app,代码行数:4,代码来源:ToDoAppInstance.java

示例15: getPubnubInstance

import com.pubnub.api.Pubnub; //导入依赖的package包/类
public  Pubnub getPubnubInstance(){
    return PUBNUB_INSTANCE;
}
 
开发者ID:shyampurk,项目名称:bluemix-todo-app,代码行数:4,代码来源:ToDoAppInstance.java


注:本文中的com.pubnub.api.Pubnub类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。