-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed getClientInfo receiving wrong format from android (#705)
Co-authored-by: James Hunt <[email protected]>
- Loading branch information
Showing
8 changed files
with
175 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
ILiveShareHost, | ||
IFluidTenantInfo, | ||
IFluidContainerInfo, | ||
INtpTimeInfo, | ||
UserMeetingRole, | ||
IClientInfo, | ||
} from "../interfaces"; | ||
|
||
export class BaseHostDecorator implements ILiveShareHost { | ||
/** | ||
* @hidden | ||
*/ | ||
constructor(readonly _host: ILiveShareHost) {} | ||
|
||
public async registerClientId( | ||
clientId: string | ||
): Promise<UserMeetingRole[]> { | ||
return this._host.registerClientId(clientId); | ||
} | ||
public async getClientRoles( | ||
clientId: string | ||
): Promise<UserMeetingRole[] | undefined> { | ||
return this._host.getClientRoles(clientId); | ||
} | ||
public async getClientInfo( | ||
clientId: string | ||
): Promise<IClientInfo | undefined> { | ||
return this._host.getClientInfo(clientId); | ||
} | ||
|
||
public getFluidTenantInfo(): Promise<IFluidTenantInfo> { | ||
return this._host.getFluidTenantInfo(); | ||
} | ||
|
||
public getFluidToken(containerId?: string): Promise<string> { | ||
return this._host.getFluidToken(containerId); | ||
} | ||
|
||
public getFluidContainerId(): Promise<IFluidContainerInfo> { | ||
return this._host.getFluidContainerId(); | ||
} | ||
|
||
public setFluidContainerId( | ||
containerId: string | ||
): Promise<IFluidContainerInfo> { | ||
return this._host.setFluidContainerId(containerId); | ||
} | ||
|
||
public getNtpTime(): Promise<INtpTimeInfo> { | ||
return this._host.getNtpTime(); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/live-share/src/internals/FormatFixHostDecorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { UserMeetingRole, IClientInfo } from "../interfaces"; | ||
import { BaseHostDecorator } from "./BaseHostDecorator"; | ||
|
||
import { isClientRolesResponse } from "./type-guards"; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export class FormatFixHostDecorator extends BaseHostDecorator { | ||
public async getClientInfo( | ||
clientId: string | ||
): Promise<IClientInfo | undefined> { | ||
const clientInfo = await this._host.getClientInfo(clientId); | ||
if (isAndroidClientInfoBugFormat(clientInfo)) { | ||
return { | ||
userId: clientInfo.lock, | ||
roles: clientInfo._loadStates, | ||
displayName: clientInfo.internalState, | ||
}; | ||
} | ||
return clientInfo; | ||
} | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
function isAndroidClientInfoBugFormat( | ||
value: any | ||
): value is AndroidClientInfoBugFormat { | ||
return ( | ||
typeof value?.lock === "string" && | ||
isClientRolesResponse(value?._loadStates) && | ||
(typeof value?.internalState === "string" || | ||
value?.internalState === undefined) | ||
); | ||
} | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
interface AndroidClientInfoBugFormat { | ||
/** | ||
* The user identifier that corresponds to the provided client identifier. | ||
*/ | ||
lock: string; | ||
/** | ||
* List of roles of the user. | ||
*/ | ||
_loadStates: UserMeetingRole[]; | ||
/** | ||
* Optional. The display name for the user. | ||
*/ | ||
internalState?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/live-share/src/internals/test/FormatFixHostDecorator.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ILiveShareHost, UserMeetingRole, IClientInfo } from "../../interfaces"; | ||
import { strict as assert } from "assert"; | ||
import { FormatFixHostDecorator } from ".."; | ||
|
||
class HostWithAndroidBug { | ||
constructor(private result: unknown) {} | ||
public async getClientInfo( | ||
clientId: string | ||
): Promise<IClientInfo | undefined> { | ||
return this.result as IClientInfo; | ||
} | ||
} | ||
|
||
describe("FormatFixHostDecorator tests", function () { | ||
it("should map android bug format to expected format", async () => { | ||
const hostResponse = { | ||
lock: "userId", | ||
_loadStates: [UserMeetingRole.organizer], | ||
internalState: "displayName", | ||
}; | ||
const host = new HostWithAndroidBug( | ||
hostResponse | ||
) as unknown as ILiveShareHost; | ||
const hostWithMapper = new FormatFixHostDecorator(host); | ||
const expectedResult = { | ||
userId: "userId", | ||
roles: [UserMeetingRole.organizer], | ||
displayName: "displayName", | ||
}; | ||
const result = await hostWithMapper.getClientInfo("test"); | ||
assert( | ||
JSON.stringify(result) === JSON.stringify(expectedResult), | ||
`unexpected result: ${JSON.stringify(result)}` | ||
); | ||
}); | ||
|
||
it("should not map if already expected format", async () => { | ||
const hostResponse = { | ||
userId: "userId", | ||
roles: [UserMeetingRole.organizer], | ||
displayName: "displayName", | ||
}; | ||
const host = new HostWithAndroidBug( | ||
hostResponse | ||
) as unknown as ILiveShareHost; | ||
const hostWithMapper = new FormatFixHostDecorator(host); | ||
const result = await hostWithMapper.getClientInfo("test"); | ||
assert( | ||
JSON.stringify(result) === JSON.stringify(hostResponse), | ||
`unexpected result: ${JSON.stringify(result)}` | ||
); | ||
}); | ||
}); |