Search in sources :

Example 26 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class RatioChangeActivity method joinRoom.

private void joinRoom(String uuid, String token) {
    logRoomInfo("room uuid: " + uuid + "\nroom token: " + token);
    WhiteSdkConfiguration configuration = new WhiteSdkConfiguration(demoAPI.getAppId(), true);
    /*显示用户头像*/
    configuration.setUserCursor(true);
    // 动态 ppt 需要的自定义字体,如果没有使用,无需调用
    configuration.setFonts(new MapBuilder<String, String>().put("宋体", "https://your-cdn.com/Songti.ttf").build());
    mWhiteSdk = new WhiteSdk(mWhiteboardView, this, configuration);
    // 图片替换 API,需要在 whiteSDKConfig 中先行调用 setHasUrlInterrupterAPI,进行设置,否则不会被回调。
    mWhiteSdk.setCommonCallbacks(new CommonCallbacks() {

        @Override
        public String urlInterrupter(String sourceUrl) {
            return sourceUrl;
        }

        @Override
        public void onMessage(JSONObject message) {
            Log.d(TAG, message.toString());
        }

        @Override
        public void sdkSetupFail(SDKError error) {
            Log.e(TAG, "sdkSetupFail " + error.toString());
        }

        @Override
        public void throwError(Object args) {
            Log.e(TAG, "throwError " + args);
        }

        @Override
        public void onPPTMediaPlay() {
            logAction();
        }

        @Override
        public void onPPTMediaPause() {
            logAction();
        }
    });
    FontFace fontFace = new FontFace("example", "url(https://white-pan.oss-cn-shanghai.aliyuncs.com/Pacifico-Regular.ttf)");
    // mWhiteSdk.setupFontFaces(new FontFace[]{fontFace});
    mWhiteSdk.loadFontFaces(new FontFace[] { fontFace }, new Promise<JSONObject>() {

        @Override
        public void then(JSONObject object) {
            logRoomInfo("loadFontFaces");
        }

        @Override
        public void catchEx(SDKError t) {
        }
    });
    /**
     * 设置自定义全局状态,在后续回调中 GlobalState 直接进行类型转换即可
     */
    WhiteDisplayerState.setCustomGlobalStateClass(MyGlobalState.class);
    // 如需支持用户头像,请在设置 WhiteSdkConfiguration 后,再调用 setUserPayload 方法,传入符合用户信息
    RoomParams roomParams = new RoomParams(uuid, token, DemoAPI.DEFAULT_UID);
    final Date joinDate = new Date();
    logRoomInfo("native join " + joinDate);
    mWhiteSdk.joinRoom(roomParams, new AbstractRoomCallbacks() {
    }, new Promise<Room>() {

        @Override
        public void then(Room room) {
            // 记录加入房间消耗的时长
            logRoomInfo("native join in room duration: " + (System.currentTimeMillis() - joinDate.getTime()) / 1000f + "s");
            mRoom = room;
        }

        @Override
        public void catchEx(SDKError t) {
            logRoomInfo("native join fail: " + t.getMessage());
            showToast(t.getMessage());
        }
    });
}
Also used : WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) AbstractRoomCallbacks(com.herewhite.sdk.AbstractRoomCallbacks) RoomParams(com.herewhite.sdk.RoomParams) Date(java.util.Date) FontFace(com.herewhite.sdk.domain.FontFace) JSONObject(org.json.JSONObject) CommonCallbacks(com.herewhite.sdk.CommonCallbacks) JSONObject(org.json.JSONObject) WhiteSdk(com.herewhite.sdk.WhiteSdk) Room(com.herewhite.sdk.Room)

Example 27 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class ScenesActivity method joinRoom.

// region room
private void joinRoom(String uuid, String token) {
    logRoomInfo("room uuid: " + uuid + "\nroom token: " + token);
    WhiteSdkConfiguration configuration = new WhiteSdkConfiguration(demoAPI.getAppId(), true);
    mWhiteSdk = new WhiteSdk(mWhiteboardView, this, configuration);
    RoomParams roomParams = new RoomParams(uuid, token, DemoAPI.DEFAULT_UID);
    roomParams.setDisableNewPencil(false);
    roomParams.setWritable(true);
    mWhiteSdk.joinRoom(roomParams, new RoomCallbacks() {

        @Override
        public void onCanUndoStepsUpdate(long canUndoSteps) {
        }

        @Override
        public void onCanRedoStepsUpdate(long canRedoSteps) {
        }

        @Override
        public void onCatchErrorWhenAppendFrame(long userId, Exception error) {
        }

        @Override
        public void onPhaseChanged(RoomPhase phase) {
            logRoomInfo("onPhaseChanged: " + phase.name());
            showToast(phase.name());
        }

        @Override
        public void onDisconnectWithError(Exception e) {
            logRoomInfo("onDisconnectWithError: " + e.getMessage());
        }

        @Override
        public void onKickedWithReason(String reason) {
            logRoomInfo("onKickedWithReason: " + reason);
        }

        @Override
        public void onRoomStateChanged(RoomState modifyState) {
            logRoomInfo("onRoomStateChanged: " + modifyState);
            if (modifyState.getSceneState() != null) {
                // callback when sceneState changed
                SceneState sceneState = modifyState.getSceneState();
                logRoomInfo("sceneState changed " + sceneState.toString());
            }
        }
    }, new Promise<Room>() {

        @Override
        public void then(Room room) {
            mRoom = room;
        }

        @Override
        public void catchEx(SDKError t) {
            showToast(t.getMessage());
        }
    });
}
Also used : WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) SceneState(com.herewhite.sdk.domain.SceneState) RoomParams(com.herewhite.sdk.RoomParams) RoomCallbacks(com.herewhite.sdk.RoomCallbacks) RoomPhase(com.herewhite.sdk.domain.RoomPhase) WhiteSdk(com.herewhite.sdk.WhiteSdk) Room(com.herewhite.sdk.Room) RoomState(com.herewhite.sdk.domain.RoomState)

Example 28 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class WindowRegisterAppActivity method registerMonaco.

private void registerMonaco() {
    // register local script
    String jsString = getAppJsFromAsserts("app/monaco.iife.js");
    String kind = "Monaco";
    String variable = "NetlessAppMonaco.default";
    WindowRegisterAppParams params = new WindowRegisterAppParams(jsString, kind, variable, Collections.emptyMap());
    mWhiteSdk.registerApp(params, new Promise<Boolean>() {

        @Override
        public void then(Boolean result) {
            logAction();
        }

        @Override
        public void catchEx(SDKError t) {
            logAction(t.toString());
        }
    });
    // register remote script
    String url = "https://cdn.jsdelivr.net/npm/@netless/app-monaco@0.1.13-beta.0/dist/main.iife.js";
    WindowRegisterAppParams paramsRemote = new WindowRegisterAppParams(url, kind, Collections.emptyMap());
// mWhiteSdk.registerApp(params);
}
Also used : WindowRegisterAppParams(com.herewhite.sdk.domain.WindowRegisterAppParams) SDKError(com.herewhite.sdk.domain.SDKError)

Example 29 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class WindowRegisterAppActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_window_register_app);
    getSupportActionBar().hide();
    mWhiteboardView = findViewById(R.id.white);
    mWhiteboardView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    findViewById(R.id.addMonaco).setOnClickListener(v -> {
        WindowAppParam.Options options = new WindowAppParam.Options("VSCode");
        WindowAppParam appParam = new WindowAppParam("Monaco", options, null);
        mRoom.addApp(appParam, new Promise<String>() {

            @Override
            public void then(String appId) {
            }

            @Override
            public void catchEx(SDKError t) {
            }
        });
    });
    findViewById(R.id.addEmbedPage).setOnClickListener(v -> {
        WindowAppParam appParam = new WindowAppParam("EmbeddedPage", new EmbedPageOptions("A Embed Page", "/embedPage"), new EmbedPageAttributes("https://www.baidu.com"));
        mRoom.addApp(appParam, new Promise<String>() {

            @Override
            public void then(String appId) {
            }

            @Override
            public void catchEx(SDKError t) {
            }
        });
    });
    joinRoom(demoAPI.getRoomUUID(), demoAPI.getRoomToken());
}
Also used : WindowAppParam(com.herewhite.sdk.domain.WindowAppParam) SDKError(com.herewhite.sdk.domain.SDKError)

Example 30 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class CameraMoveActivity method joinRoom.

private void joinRoom() {
    WhiteSdkConfiguration configuration = new WhiteSdkConfiguration(demoAPI.getAppId(), true);
    whiteSdk = new WhiteSdk(whiteboardView, this, configuration);
    RoomParams roomParams = new RoomParams(demoAPI.getRoomUUID(), demoAPI.getRoomToken(), DemoAPI.DEFAULT_UID);
    whiteSdk.joinRoom(roomParams, new EmptyRoomListener(), new Promise<Room>() {

        @Override
        public void then(Room room) {
            CameraMoveActivity.this.room = room;
            loadImageInfo("https://placekitten.com/1920/1080");
        }

        @Override
        public void catchEx(SDKError t) {
            showToast(t.getMessage());
        }
    });
}
Also used : WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) RoomParams(com.herewhite.sdk.RoomParams) WhiteSdk(com.herewhite.sdk.WhiteSdk) Room(com.herewhite.sdk.Room) EmptyRoomListener(com.herewhite.demo.utils.EmptyRoomListener)

Aggregations

SDKError (com.herewhite.sdk.domain.SDKError)38 JSONObject (org.json.JSONObject)18 JsonSyntaxException (com.google.gson.JsonSyntaxException)13 WhiteSdk (com.herewhite.sdk.WhiteSdk)12 WhiteSdkConfiguration (com.herewhite.sdk.WhiteSdkConfiguration)12 JsonObject (com.google.gson.JsonObject)10 Room (com.herewhite.sdk.Room)10 RoomParams (com.herewhite.sdk.RoomParams)10 RoomPhase (com.herewhite.sdk.domain.RoomPhase)7 RoomState (com.herewhite.sdk.domain.RoomState)7 AbstractRoomCallbacks (com.herewhite.sdk.AbstractRoomCallbacks)5 CommonCallback (com.herewhite.sdk.CommonCallback)5 Test (org.junit.Test)5 RoomCallbacks (com.herewhite.sdk.RoomCallbacks)4 View (android.view.View)3 ConvertException (com.herewhite.sdk.domain.ConvertException)3 FontFace (com.herewhite.sdk.domain.FontFace)3 Scene (com.herewhite.sdk.domain.Scene)3 SceneState (com.herewhite.sdk.domain.SceneState)3 WindowParams (com.herewhite.sdk.domain.WindowParams)3