@signalwire/js 3.6.0-dev.202111170816.f436d5f.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/src/BaseClient.d.ts +0 -7
- package/dist/core/src/BaseClient.d.ts.map +1 -1
- package/dist/core/src/BaseComponent.d.ts +9 -6
- package/dist/core/src/BaseComponent.d.ts.map +1 -1
- package/dist/core/src/BaseConsumer.d.ts +2 -1
- package/dist/core/src/BaseConsumer.d.ts.map +1 -1
- package/dist/core/src/chat/BaseChat.d.ts +33 -0
- package/dist/core/src/chat/BaseChat.d.ts.map +1 -0
- package/dist/core/src/chat/ChatMember.d.ts +9 -0
- package/dist/core/src/chat/ChatMember.d.ts.map +1 -0
- package/dist/core/src/chat/ChatMessage.d.ts +12 -0
- package/dist/core/src/chat/ChatMessage.d.ts.map +1 -0
- package/dist/core/src/chat/index.d.ts +4 -0
- package/dist/core/src/chat/index.d.ts.map +1 -0
- package/dist/core/src/chat/methods.d.ts +27 -0
- package/dist/core/src/chat/methods.d.ts.map +1 -0
- package/dist/core/src/chat/utils/index.d.ts +3 -0
- package/dist/core/src/chat/utils/index.d.ts.map +1 -0
- package/dist/core/src/chat/utils/toInternalChatChannels.d.ts +3 -0
- package/dist/core/src/chat/utils/toInternalChatChannels.d.ts.map +1 -0
- package/dist/core/src/chat/utils/toInternalChatChannels.test.d.ts +2 -0
- package/dist/core/src/chat/utils/toInternalChatChannels.test.d.ts.map +1 -0
- package/dist/core/src/chat/workers.d.ts +3 -0
- package/dist/core/src/chat/workers.d.ts.map +1 -0
- package/dist/core/src/index.d.ts +2 -0
- package/dist/core/src/index.d.ts.map +1 -1
- package/dist/core/src/internal/BaseBackendSession.d.ts.map +1 -1
- package/dist/core/src/redux/connect.d.ts.map +1 -1
- package/dist/core/src/redux/features/component/componentSaga.d.ts +4 -0
- package/dist/core/src/redux/features/component/componentSaga.d.ts.map +1 -0
- package/dist/core/src/redux/features/component/componentSaga.test.d.ts +2 -0
- package/dist/core/src/redux/features/component/componentSaga.test.d.ts.map +1 -0
- package/dist/core/src/redux/features/component/componentSelectors.d.ts +6 -2
- package/dist/core/src/redux/features/component/componentSelectors.d.ts.map +1 -1
- package/dist/core/src/redux/features/component/componentSelectors.test.d.ts +2 -0
- package/dist/core/src/redux/features/component/componentSelectors.test.d.ts.map +1 -0
- package/dist/core/src/redux/features/component/componentSlice.d.ts +4 -0
- package/dist/core/src/redux/features/component/componentSlice.d.ts.map +1 -1
- package/dist/core/src/redux/features/pubSub/pubSubSaga.d.ts.map +1 -1
- package/dist/core/src/redux/features/session/sessionSaga.d.ts.map +1 -1
- package/dist/core/src/redux/features/session/sessionSelectors.d.ts +1 -0
- package/dist/core/src/redux/features/session/sessionSelectors.d.ts.map +1 -1
- package/dist/core/src/redux/index.d.ts +7 -5
- package/dist/core/src/redux/index.d.ts.map +1 -1
- package/dist/core/src/redux/interfaces.d.ts +6 -4
- package/dist/core/src/redux/interfaces.d.ts.map +1 -1
- package/dist/core/src/redux/rootSaga.d.ts +11 -4
- package/dist/core/src/redux/rootSaga.d.ts.map +1 -1
- package/dist/core/src/redux/utils/sagaHelpers.d.ts +3 -2
- package/dist/core/src/redux/utils/sagaHelpers.d.ts.map +1 -1
- package/dist/core/src/testUtils.d.ts +5 -4
- package/dist/core/src/testUtils.d.ts.map +1 -1
- package/dist/core/src/types/chat.d.ts +129 -0
- package/dist/core/src/types/chat.d.ts.map +1 -0
- package/dist/core/src/types/index.d.ts +5 -1
- package/dist/core/src/types/index.d.ts.map +1 -1
- package/dist/core/src/types/utils.d.ts +11 -4
- package/dist/core/src/types/utils.d.ts.map +1 -1
- package/dist/core/src/types/videoMember.d.ts.map +1 -1
- package/dist/core/src/types/videoPlayback.d.ts +2 -2
- package/dist/core/src/types/videoPlayback.d.ts.map +1 -1
- package/dist/core/src/types/videoRoomSession.d.ts +10 -7
- package/dist/core/src/types/videoRoomSession.d.ts.map +1 -1
- package/dist/core/src/utils/constants.d.ts +2 -1
- package/dist/core/src/utils/constants.d.ts.map +1 -1
- package/dist/core/src/utils/eventTransformUtils.d.ts.map +1 -1
- package/dist/core/src/utils/interfaces.d.ts +12 -6
- package/dist/core/src/utils/interfaces.d.ts.map +1 -1
- package/dist/core/src/utils/proxyUtils.d.ts +10 -0
- package/dist/core/src/utils/proxyUtils.d.ts.map +1 -0
- package/dist/core/src/utils/toExternalJSON.d.ts +5 -1
- package/dist/core/src/utils/toExternalJSON.d.ts.map +1 -1
- package/dist/index.esm.js +73 -22
- package/dist/index.esm.js.map +3 -3
- package/dist/index.js +100 -47
- package/dist/index.js.map +3 -3
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/js/src/Client.d.ts +4 -0
- package/dist/js/src/Client.d.ts.map +1 -1
- package/dist/js/src/JWTSession.d.ts.map +1 -1
- package/dist/js/src/RoomSession.docs.d.ts +22 -10
- package/dist/js/src/RoomSession.docs.d.ts.map +1 -1
- package/dist/js/src/RoomSessionDevice.docs.d.ts +2 -0
- package/dist/js/src/RoomSessionDevice.docs.d.ts.map +1 -1
- package/dist/js/src/RoomSessionScreenShare.docs.d.ts +2 -0
- package/dist/js/src/RoomSessionScreenShare.docs.d.ts.map +1 -1
- package/dist/js/src/chat/Client.d.ts +16 -0
- package/dist/js/src/chat/Client.d.ts.map +1 -0
- package/dist/js/src/chat/index.d.ts +2 -0
- package/dist/js/src/chat/index.d.ts.map +1 -0
- package/dist/js/src/createClient.d.ts +1 -21
- package/dist/js/src/createClient.d.ts.map +1 -1
- package/dist/js/src/index.d.ts +2 -0
- package/dist/js/src/index.d.ts.map +1 -1
- package/dist/js/src/testUtils.d.ts +6 -6
- package/dist/js/src/utils/videoElement.d.ts.map +1 -1
- package/dist/js/tsconfig.build.tsbuildinfo +1 -1
- package/dist/webrtc/src/BaseConnection.d.ts +2 -0
- package/dist/webrtc/src/BaseConnection.d.ts.map +1 -1
- package/dist/webrtc/src/utils/webrtcHelpers.native.d.ts +2 -2
- package/dist/webrtc/src/utils/webrtcHelpers.native.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Client.ts +17 -0
- package/src/RoomSession.docs.ts +23 -10
- package/src/RoomSessionDevice.docs.ts +3 -0
- package/src/RoomSessionScreenShare.docs.ts +3 -0
- package/src/chat/Client.test.ts +606 -0
- package/src/chat/Client.ts +55 -0
- package/src/chat/index.ts +1 -0
- package/src/createClient.test.ts +116 -0
- package/src/createClient.ts +1 -22
- package/src/index.ts +3 -0
- package/src/utils/constants.ts +1 -1
- package/src/utils/videoElement.ts +21 -13
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import WS from 'jest-websocket-mock'
|
|
2
|
+
import { AuthError } from '@signalwire/core'
|
|
3
|
+
import { createClient } from './createClient'
|
|
4
|
+
|
|
5
|
+
describe('createClient', () => {
|
|
6
|
+
const host = 'ws://localhost:1234'
|
|
7
|
+
const token = '<jwt>'
|
|
8
|
+
const authError = {
|
|
9
|
+
code: -32002,
|
|
10
|
+
message:
|
|
11
|
+
'Authentication service failed with status ProtocolError, 401 Unauthorized: {}',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let server: WS
|
|
15
|
+
let consoleMock: jest.SpyInstance
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
consoleMock = jest
|
|
18
|
+
.spyOn(global.console, 'error')
|
|
19
|
+
.mockImplementation(() => {})
|
|
20
|
+
|
|
21
|
+
server = new WS(host)
|
|
22
|
+
server.on('connection', (socket) => {
|
|
23
|
+
socket.on('message', (data: any) => {
|
|
24
|
+
const parsedData = JSON.parse(data)
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
parsedData.method === 'signalwire.connect' &&
|
|
28
|
+
parsedData.params.authentication.jwt_token === '<invalid-token>'
|
|
29
|
+
) {
|
|
30
|
+
socket.send(
|
|
31
|
+
JSON.stringify({
|
|
32
|
+
jsonrpc: '2.0',
|
|
33
|
+
id: parsedData.id,
|
|
34
|
+
error: authError,
|
|
35
|
+
})
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
socket.send(
|
|
40
|
+
JSON.stringify({
|
|
41
|
+
jsonrpc: '2.0',
|
|
42
|
+
id: parsedData.id,
|
|
43
|
+
result: {},
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
consoleMock.mockRestore()
|
|
52
|
+
WS.clean()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('should throw an error when invalid credentials are provided', async () => {
|
|
56
|
+
expect.assertions(1)
|
|
57
|
+
|
|
58
|
+
const client = createClient({
|
|
59
|
+
host,
|
|
60
|
+
token: '<invalid-token>',
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
await client.connect()
|
|
65
|
+
} catch (e) {
|
|
66
|
+
expect(e).toBeInstanceOf(AuthError)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('should resolve `connect()` when the client is authorized', async () => {
|
|
71
|
+
expect.assertions(1)
|
|
72
|
+
|
|
73
|
+
const client = createClient({
|
|
74
|
+
host,
|
|
75
|
+
token,
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
// @ts-expect-error
|
|
79
|
+
client._waitUntilSessionAuthorized().then((c) => {
|
|
80
|
+
expect(c).toEqual(client)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
await client.connect()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('should automatically resolve (without hitting the network) when calling `.connect()` if the session was already authorized', async () => {
|
|
87
|
+
const h = 'ws://localhost:2222'
|
|
88
|
+
const s = new WS(h)
|
|
89
|
+
|
|
90
|
+
let messageHandler
|
|
91
|
+
s.on('connection', (socket) => {
|
|
92
|
+
messageHandler = jest.fn((data: any) => {
|
|
93
|
+
const parsedData = JSON.parse(data)
|
|
94
|
+
|
|
95
|
+
socket.send(
|
|
96
|
+
JSON.stringify({
|
|
97
|
+
jsonrpc: '2.0',
|
|
98
|
+
id: parsedData.id,
|
|
99
|
+
result: {},
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
socket.on('message', messageHandler)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const client = createClient({
|
|
108
|
+
host: h,
|
|
109
|
+
token,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
await Promise.all([client.connect(), client.connect(), client.connect()])
|
|
113
|
+
|
|
114
|
+
expect(messageHandler).toHaveBeenCalledTimes(1)
|
|
115
|
+
})
|
|
116
|
+
})
|
package/src/createClient.ts
CHANGED
|
@@ -16,30 +16,10 @@ import { JWTSession } from './JWTSession'
|
|
|
16
16
|
* Create a client
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
|
-
* With autoConnect true the client is ready to be used.
|
|
20
19
|
* ```js
|
|
21
20
|
* try {
|
|
22
|
-
* const client =
|
|
23
|
-
* token: '<YourToken>',
|
|
24
|
-
* })
|
|
25
|
-
*
|
|
26
|
-
* // Your client is already connected..
|
|
27
|
-
* } catch (error) {
|
|
28
|
-
* console.error('Auth Error', error)
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* With autoConnect false you can attach additional handlers.
|
|
34
|
-
* ```js
|
|
35
|
-
* try {
|
|
36
|
-
* const client = await Video.createClient({
|
|
21
|
+
* const client = Video.createClient({
|
|
37
22
|
* token: '<YourJWT>',
|
|
38
|
-
* autoConnect: false,
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* client.on('socket.closed', () => {
|
|
42
|
-
* // The WebSocket connection is closed
|
|
43
23
|
* })
|
|
44
24
|
*
|
|
45
25
|
* await client.connect()
|
|
@@ -69,7 +49,6 @@ export const createClient = <RoomSessionType>(userOptions: UserOptions) => {
|
|
|
69
49
|
componentListeners: {
|
|
70
50
|
errors: 'onError',
|
|
71
51
|
responses: 'onSuccess',
|
|
72
|
-
id: 'onClientSubscribed',
|
|
73
52
|
},
|
|
74
53
|
})(baseUserOptions)
|
|
75
54
|
|
package/src/index.ts
CHANGED
package/src/utils/constants.ts
CHANGED
|
@@ -10,8 +10,8 @@ export const ROOM_COMPONENT_LISTENERS = {
|
|
|
10
10
|
|
|
11
11
|
export const SCREENSHARE_AUDIO_CONSTRAINTS: MediaTrackConstraints = {
|
|
12
12
|
echoCancellation: false,
|
|
13
|
-
// @ts-expect-error
|
|
14
13
|
noiseSuppression: false,
|
|
15
14
|
autoGainControl: false,
|
|
15
|
+
// @ts-expect-error
|
|
16
16
|
googAutoGainControl: false,
|
|
17
17
|
}
|
|
@@ -4,6 +4,10 @@ import {
|
|
|
4
4
|
InternalVideoLayout,
|
|
5
5
|
} from '@signalwire/core'
|
|
6
6
|
|
|
7
|
+
const _addSDKPrefix = (input: string) => {
|
|
8
|
+
return `sw-sdk-${input}`
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
const buildVideo = () => {
|
|
8
12
|
const video = document.createElement('video')
|
|
9
13
|
video.muted = true
|
|
@@ -81,19 +85,22 @@ const makeLayoutChangedHandler =
|
|
|
81
85
|
async ({ layout, myMemberId, localStream }: LayoutChangedHandlerParams) => {
|
|
82
86
|
try {
|
|
83
87
|
const { layers = [] } = layout
|
|
84
|
-
const
|
|
88
|
+
const location = layers.find(({ member_id }) => member_id === myMemberId)
|
|
89
|
+
|
|
90
|
+
const myLayerKey = _addSDKPrefix(myMemberId)
|
|
91
|
+
let myLayer = layerMap.get(myLayerKey)
|
|
92
|
+
if (!location) {
|
|
93
|
+
if (myLayer) {
|
|
94
|
+
getLogger().debug('Current layer not visible')
|
|
95
|
+
myLayer.style.display = 'none'
|
|
96
|
+
}
|
|
85
97
|
|
|
86
|
-
|
|
87
|
-
return getLogger().debug(
|
|
88
|
-
'Current Layer Not Found',
|
|
89
|
-
JSON.stringify(layout)
|
|
90
|
-
)
|
|
98
|
+
return
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
let myLayer = layerMap.get(myMemberId)
|
|
94
101
|
if (!myLayer) {
|
|
95
|
-
myLayer = await _buildLayer({ element, location
|
|
96
|
-
myLayer.id =
|
|
102
|
+
myLayer = await _buildLayer({ element, location })
|
|
103
|
+
myLayer.id = myLayerKey
|
|
97
104
|
|
|
98
105
|
const localVideo = buildVideo()
|
|
99
106
|
localVideo.srcObject = localStream
|
|
@@ -103,16 +110,17 @@ const makeLayoutChangedHandler =
|
|
|
103
110
|
myLayer.appendChild(localVideo)
|
|
104
111
|
|
|
105
112
|
const mcuLayers = rootElement.querySelector('.mcuLayers')
|
|
106
|
-
const exists = document.getElementById(
|
|
113
|
+
const exists = document.getElementById(myLayerKey)
|
|
107
114
|
if (mcuLayers && !exists) {
|
|
108
115
|
mcuLayers.appendChild(myLayer)
|
|
109
|
-
layerMap.set(
|
|
116
|
+
layerMap.set(myLayerKey, myLayer)
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
return
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
const { top, left, width, height } = _getLocationStyles(
|
|
122
|
+
const { top, left, width, height } = _getLocationStyles(location)
|
|
123
|
+
myLayer.style.display = 'block'
|
|
116
124
|
myLayer.style.top = top
|
|
117
125
|
myLayer.style.left = left
|
|
118
126
|
myLayer.style.width = width
|
|
@@ -124,7 +132,7 @@ const makeLayoutChangedHandler =
|
|
|
124
132
|
|
|
125
133
|
const makeDisplayChangeFn = (display: 'block' | 'none') => {
|
|
126
134
|
return (domId: string) => {
|
|
127
|
-
const el = document.getElementById(domId)
|
|
135
|
+
const el = document.getElementById(_addSDKPrefix(domId))
|
|
128
136
|
if (el) {
|
|
129
137
|
el.style.display = display
|
|
130
138
|
}
|