Skip to content

Commit

Permalink
client: update
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 21, 2024
1 parent 776356f commit 857cc65
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
32 changes: 16 additions & 16 deletions packages/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
"license": "ISC",
"devDependencies": {
"@types/ip": "^1.1.3",
"@types/node": "^20.10.8",
"@types/node": "^20.11.30",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.4.3"
},
"dependencies": {
"@scrypted/types": "^0.3.15",
"@scrypted/types": "^0.3.27",
"engine.io-client": "^6.5.3",
"follow-redirects": "^1.15.4",
"follow-redirects": "^1.15.6",
"rimraf": "^5.0.5"
}
}
28 changes: 17 additions & 11 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MediaObjectOptions, RTCConnectionManagement, RTCSignalingSession, ScryptedStatic } from "@scrypted/types";
import { MediaObjectCreateOptions, RTCConnectionManagement, RTCSignalingSession, ScryptedStatic } from "@scrypted/types";
import * as eio from 'engine.io-client';
import { SocketOptions } from 'engine.io-client';
import { Deferred } from "../../../common/src/deferred";
Expand Down Expand Up @@ -316,28 +316,32 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro
}
}

// the alternate urls must have a valid response.
const loginCheckPromises = [...urlsToCheck].map(async baseUrl => {
const loginCheck = await checkScryptedClientLogin({
baseUrl,
previousLoginResult: options?.previousLoginResult,
});

function validateLoginResult(loginCheck: Awaited<ReturnType<typeof checkScryptedClientLogin>>) {
if (loginCheck.error || loginCheck.redirect)
throw new Error('login error');
throw new ScryptedClientLoginError(loginCheck);

if (!loginCheck.authorization || !loginCheck.username || !loginCheck.queryToken) {
console.error(loginCheck);
throw new Error('malformed login result');
}

return loginCheck;
}

// the alternate urls must have a valid response.
const loginCheckPromises = [...urlsToCheck].map(baseUrl => {
return checkScryptedClientLogin({
baseUrl,
previousLoginResult: options?.previousLoginResult,
})
.then(validateLoginResult);
});

const baseUrlCheck = checkScryptedClientLogin({
baseUrl,
previousLoginResult: options?.previousLoginResult,
});
})
.then(validateLoginResult);
loginCheckPromises.push(baseUrlCheck);

let loginCheck: Awaited<ReturnType<typeof checkScryptedClientLogin>>;
Expand Down Expand Up @@ -687,7 +691,7 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro
} = scrypted;
console.log('api attached', Date.now() - start);

mediaManager.createMediaObject = async<T extends MediaObjectOptions>(data: any, mimeType: string, options: T) => {
mediaManager.createMediaObject = async<T extends MediaObjectCreateOptions>(data: any, mimeType: string, options: T) => {
return new MediaObject(mimeType, data, options) as any;
}

Expand Down Expand Up @@ -866,6 +870,8 @@ export async function connectScryptedClient(options: ScryptedClientOptions): Pro
cloudAddress,
},
connectRPCObject,
fork: undefined,
connect: undefined,
}

socket.on('close', () => {
Expand Down

0 comments on commit 857cc65

Please sign in to comment.