频道相关

说明:以下所有方法都位于SignallingService

创建频道

 /**
     * 创建频道
     * 同一时刻频道名互斥,不能重复创建,但如果频道名缺省,服务器会自动分配频道id。
     * @param type        频道类型
     * @param channelName 频道名,可缺省
     * @param channelExt  频道的自定义扩展信息,可缺省
     * @return InvocationFuture
     */
    InvocationFuture<ChannelBaseInfo> create(ChannelType type, String channelName, String channelExt);
    /**
     * 创建房间
     */
    private void create() {
        String roomId = editRoom.getText().toString().trim();
        if (TextUtils.isEmpty(roomId)) {
            ToastHelper.showToast(this, "请输入房间号码");
            return;
        }
        NIMClient.getService(SignallingService.class).create(ChannelType.CUSTOM, roomId, "").setCallback(
                new RequestCallbackWrapper<ChannelBaseInfo>() {

                    @Override
                    public void onResult(int i, ChannelBaseInfo channelBaseInfo, Throwable throwable) {
                        if (i == ResponseCode.RES_SUCCESS) {
                            channelInfo = channelBaseInfo;
                            ToastHelper.showToast(MainActivity.this, "创建成功");
                        } else {
                            ToastHelper.showToast(MainActivity.this, "创建失败, code = " + i +
                                                                     (throwable == null ? "" : ", throwable = " +
                                                                                               throwable.getMessage()));
                        }
                    }
                });


    }

加入频道


    /**
     * 加入频道
     * @param channelId     对应频道id
     * @param selfUid       自己在频道中对应的uid,可选,大于零有效,无效时服务器会分配随机唯一的uid, 也可以自己生成,但要保证唯一性
     * @param customInfo    操作者附加的自定义信息,透传给其他人,可缺省
     * @param offlineEnable 通知事件是否存离线
     * @return InvocationFuture<ChannelFullInfo>
     */
    InvocationFuture<ChannelFullInfo> join(String channelId, long selfUid, String customInfo, boolean offlineEnable);
private void joinRoom() {
    selfUid = System.nanoTime();
    NIMClient.getService(SignallingService.class).join(channelId, selfUid, "", false).setCallback(
            new RequestCallbackWrapper<ChannelFullInfo>() {

                @Override
                public void onResult(int i, ChannelFullInfo channelFullInfo, Throwable throwable) {
                    if (i == ResponseCode.RES_SUCCESS) {
                        showToast("加入房间成功");
                    } else if (i == ResponseCode.RES_CHANNEL_MEMBER_HAS_EXISTS) {
                        showToast("已经在房间中");
                    } else {
                        showToast("加入房间失败 code=" + i);
                    }
                }
            });
}

离开频道

/**
     * 离开频道
     * @param channelId     对应频道id
     * @param offlineEnable 通知事件是否存离线
     * @param customInfo    操作者附加的自定义信息,透传给其他人,可缺省
     * @return InvocationFuture<Void>
     */
    InvocationFuture<Void> leave(String channelId, boolean offlineEnable, String customInfo);
private void leave() {
    NIMClient.getService(SignallingService.class).leave(channelId, false, null).setCallback(
            new RequestCallbackWrapper<Void>() {

                @Override
                public void onResult(int i, Void aVoid, Throwable throwable) {
                    if (i == ResponseCode.RES_SUCCESS) {
                        showToast("离开房间成功");
                    } else {
                        showToast("离开房间失败 code=" + i);
                    }
                }
            });
}

关闭频道

    /**
     * 关闭频道
     * @param channelId      对应频道id
     * @param offlineEnabled 通知事件是否存离线
     * @param customInfo     操作者附加的自定义信息,透传给其他人,可缺省
     * @return InvocationFuture<Void>
     */
    InvocationFuture<Void> close(String channelId, boolean offlineEnabled, String customInfo);
/**
 * 关闭频道
 */
private void closeChannel() {
    if (channelFullInfo == null) {
        Toast.makeText(this, "请先创建频道或加入频道", Toast.LENGTH_SHORT).show();
        return;
    }
    service.close(channelFullInfo.getChannelId(), true,   "关闭频道的自定义字段").setCallback(new RequestCallback<Void>() {
        @Override
        public void onSuccess(Void param) {
            Toast.makeText(this, "关闭频道成功 , channelId =  " + channelFullInfo.getChannelId(), Toast.LENGTH_SHORT).show;
            channelFullInfo = null;
        }

        @Override
        public void onFailed(int code) {
            Toast.makeText(this, "关闭频道失败, code =  " + code).show();
        }

        @Override
        public void onException(Throwable exception) {
             Toast.makeText(this, "关闭频道异常, exception =  " + exception, Toast.LENGTH_SHORT).show();;
        }
    });
}
}