Skip to content

Commit

Permalink
added support for multiple ua type (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 committed Apr 22, 2024
1 parent 1a9c5a0 commit 086a3f4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@ interface PhoneIslandProps {
dataConfig: string
i18nLoadPath?: string
showAlways?: boolean
uaType: string
}

interface DeviceInputOutputTypes {
deviceId: string
}

export const PhoneIsland: FC<PhoneIslandProps> = ({ dataConfig, i18nLoadPath = undefined, showAlways = false }: PhoneIslandProps) => {
export const PhoneIsland: FC<PhoneIslandProps> = ({
dataConfig,
i18nLoadPath = undefined,
showAlways = false,
uaType,
}: PhoneIslandProps) => {
const CONFIG: string[] = Base64.atob(dataConfig || '').split(':')
const HOST_NAME: string = CONFIG[0]
const USERNAME: string = CONFIG[1]
Expand Down Expand Up @@ -164,6 +170,7 @@ export const PhoneIsland: FC<PhoneIslandProps> = ({ dataConfig, i18nLoadPath = u
authToken={AUTH_TOKEN}
reload={reload}
reloadedCallback={() => setReloadedSocket(true)}
uaType={uaType}
>
<Events sipHost={SIP_HOST}>
<Island showAlways={showAlways} />
Expand Down
4 changes: 3 additions & 1 deletion src/components/Socket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface SocketProps {
authToken: string
reload: boolean
reloadedCallback: () => void
uaType: string
}

export const Socket: FC<SocketProps> = ({
Expand All @@ -43,6 +44,7 @@ export const Socket: FC<SocketProps> = ({
reload,
reloadedCallback,
children,
uaType,
}) => {
const dispatch = useDispatch<Dispatch>()
const connectionCheckInterval = useRef<any>()
Expand Down Expand Up @@ -283,7 +285,7 @@ export const Socket: FC<SocketProps> = ({
socket.current.emit('login', {
accessKeyId: `${username}`,
token: authToken,
uaType: 'desktop',
uaType: uaType,
})
})

Expand Down
3 changes: 2 additions & 1 deletion src/index.widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const widgetDivs = document.querySelectorAll('.phone-island')
widgetDivs.forEach((div) => {
const config: string = div.getAttribute('data-config') || ''
const showAlways: boolean = div.getAttribute('showAlways') === 'true' ? true : false
const uaType: string = div.getAttribute('ua-type') || ''

const root = createRoot(div)
root.render(
<React.StrictMode>
<PhoneIsland dataConfig={config} showAlways={showAlways} />
<PhoneIsland dataConfig={config} showAlways={showAlways} uaType={uaType}/>
</React.StrictMode>,
)
})
2 changes: 1 addition & 1 deletion src/stories/Call.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const CallTemplate: Story<any> = (args) => {
/>
<button onClick={() => launchEvent()}>Launch {getEventName}</button>

<PhoneIsland dataConfig={config} showAlways={false} {...args} />
<PhoneIsland dataConfig={config} showAlways={false} {...args} uaType={'mobile'} />
</div>
)
}
Expand Down
12 changes: 10 additions & 2 deletions widget-example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!-- IMPORT THE WIDGET CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/nethesis/phone-island/dist-widget/index.widget.css" />
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/gh/nethesis/phone-island/dist-widget/index.widget.css"
/>
<!-- IMPORT THE WIDGET CSS -->
<title>React Widget</title>
</head>
Expand All @@ -16,9 +20,13 @@
<div
class="phone-island"
data-config="bnYtc2ViOmZvbzI6YzI5ODFkYzZlN2FkMzMyNDZiODc4NDA1ZDg4MDE5ZTU1ZmU2ZTM3OTo5MTIxMjphZmFhNmYzYTRlYmQyNWYzZTNjYjYzYmU3Nzg1NzY1Nw=="
ua-type="mobile"
></div>
<!-- IMPORT THE WIDGET JS -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/nethesis/phone-island/dist-widget/index.widget.js"></script>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/gh/nethesis/phone-island/dist-widget/index.widget.js"
></script>
<!-- IMPORT THE WIDGET JS -->
<script type="text/javascript" src="./index.js"></script>
</body>
Expand Down

0 comments on commit 086a3f4

Please sign in to comment.