@@ -14,14 +14,15 @@ function randomID() {
14
14
15
15
let lastMutationID = 0 ;
16
16
17
- function sendMutation ( socket , name , args ) {
17
+ function sendMutation ( socket , clientID , name , args ) {
18
18
const mutation = {
19
19
id : ++ lastMutationID ,
20
20
name,
21
21
args,
22
22
timestamp : Date . now ( ) ,
23
23
} ;
24
24
const pushBody = {
25
+ clientID,
25
26
mutations : [ mutation ] ,
26
27
pushVersion : 1 ,
27
28
schemaVersion : "" ,
@@ -33,14 +34,14 @@ function sendMutation(socket, name, args) {
33
34
}
34
35
35
36
function createShape ( socket , clientID , idx ) {
36
- sendMutation ( socket , "createShape" , {
37
+ sendMutation ( socket , clientID , "createShape" , {
37
38
id : `${ clientID } -${ idx } ` ,
38
39
shape : randomShape ( ) ,
39
40
} ) ;
40
41
}
41
42
42
43
function scanShape ( socket , clientID , idx ) {
43
- sendMutation ( socket , "scanShape" , {
44
+ sendMutation ( socket , clientID , "scanShape" , {
44
45
id : `${ clientID } -${ idx } ` ,
45
46
dx : 1 ,
46
47
maxX : 500 ,
@@ -63,14 +64,18 @@ export default function () {
63
64
const clientID = randomID ( ) ;
64
65
const userID = randomID ( ) ;
65
66
66
- const socketBaseURL = "ws://127.0.0.1:8787/connect" ;
67
- const url = `${ socketBaseURL } ?clientID=${ clientID } &roomID=${ roomID } &baseCookie=0&ts=${ Date . now ( ) } ` ;
67
+ // Note: it looks like wrangler only listens on ipv6!
68
+ // https://github.com/cloudflare/wrangler/issues/1198#issuecomment-1204690449
69
+ const socketBaseURL = "ws://[::1]:8787/connect" ;
70
+ const url = `${ socketBaseURL } ?clientID=${ clientID } &roomID=${ roomID } &baseCookie=0&lmid=0&ts=${ Date . now ( ) } ` ;
68
71
const params = {
69
72
headers : {
70
- "Sec-WebSocket-Protocol" : JSON . stringify ( {
71
- roomID,
72
- userID,
73
- } ) ,
73
+ "Sec-WebSocket-Protocol" : encodeURIComponent (
74
+ JSON . stringify ( {
75
+ roomID,
76
+ userID,
77
+ } )
78
+ ) ,
74
79
} ,
75
80
} ;
76
81
@@ -101,9 +106,9 @@ export default function () {
101
106
} ) ;
102
107
103
108
socket . setTimeout ( function ( ) {
104
- console . log ( "2 seconds passed , closing the socket" ) ;
109
+ console . log ( "test done , closing the socket" ) ;
105
110
socket . close ( ) ;
106
- } , 30000 ) ;
111
+ } , 5000 ) ;
107
112
} ) ;
108
113
109
114
check ( response , { "status is 101" : ( r ) => r && r . status === 101 } ) ;
0 commit comments