ci: fix `v build-examples` too
							parent
							
								
									8f5cefb116
								
							
						
					
					
						commit
						f5c245ceb8
					
				|  | @ -126,10 +126,10 @@ fn read_wav_file_samples(fpath string) ?[]f32 { | ||||||
| 	mut offset := u32(0) | 	mut offset := u32(0) | ||||||
| 	rh := &RIFFHeader(pbytes) | 	rh := &RIFFHeader(pbytes) | ||||||
| 	// eprintln('rh: $rh')
 | 	// eprintln('rh: $rh')
 | ||||||
| 	if rh.riff != [`R`, `I`, `F`, `F`]!! { | 	if rh.riff != [byte(`R`), `I`, `F`, `F`]!! { | ||||||
| 		return error('WAV should start with `RIFF`') | 		return error('WAV should start with `RIFF`') | ||||||
| 	} | 	} | ||||||
| 	if rh.form_type != [`W`, `A`, `V`, `E`]!! { | 	if rh.form_type != [byte(`W`), `A`, `V`, `E`]!! { | ||||||
| 		return error('WAV should have `WAVE` form type') | 		return error('WAV should have `WAVE` form type') | ||||||
| 	} | 	} | ||||||
| 	if rh.file_size + 8 != bytes.len { | 	if rh.file_size + 8 != bytes.len { | ||||||
|  | @ -147,15 +147,15 @@ fn read_wav_file_samples(fpath string) ?[]f32 { | ||||||
| 		// eprintln('ch: $ch')
 | 		// eprintln('ch: $ch')
 | ||||||
| 		// eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len')
 | 		// eprintln('p: $pbytes | offset: $offset | bytes.len: $bytes.len')
 | ||||||
| 		// ////////
 | 		// ////////
 | ||||||
| 		if ch.chunk_type == [`L`, `I`, `S`, `T`]!! { | 		if ch.chunk_type == [byte(`L`), `I`, `S`, `T`]!! { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		//
 | 		//
 | ||||||
| 		if ch.chunk_type == [`i`, `d`, `3`, ` `]!! { | 		if ch.chunk_type == [byte(`i`), `d`, `3`, ` `]!! { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		//
 | 		//
 | ||||||
| 		if ch.chunk_type == [`f`, `m`, `t`, ` `]!! { | 		if ch.chunk_type == [byte(`f`), `m`, `t`, ` `]!! { | ||||||
| 			// eprintln('`fmt ` chunk')
 | 			// eprintln('`fmt ` chunk')
 | ||||||
| 			rf = &RIFFFormat(&ch.chunk_data) | 			rf = &RIFFFormat(&ch.chunk_data) | ||||||
| 			// eprintln('fmt riff format: $rf')
 | 			// eprintln('fmt riff format: $rf')
 | ||||||
|  | @ -171,7 +171,7 @@ fn read_wav_file_samples(fpath string) ?[]f32 { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		//
 | 		//
 | ||||||
| 		if ch.chunk_type == [`d`, `a`, `t`, `a`]!! { | 		if ch.chunk_type == [byte(`d`), `a`, `t`, `a`]!! { | ||||||
| 			if rf == 0 { | 			if rf == 0 { | ||||||
| 				return error('`data` chunk should be after `fmt ` chunk') | 				return error('`data` chunk should be after `fmt ` chunk') | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -1,53 +0,0 @@ | ||||||
| module main |  | ||||||
| 
 |  | ||||||
| import net.websocket |  | ||||||
| import time |  | ||||||
| 
 |  | ||||||
| fn main() { |  | ||||||
| 	//URLs working for testing, reply the same sent messages
 |  | ||||||
| 	ws_test('ws://echo.websocket.org') |  | ||||||
| 	ws_test('wss://echo.websocket.org') |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| fn ws_test(uri string) { |  | ||||||
| 	println('connecting to $uri ...') |  | ||||||
| 	mut ws := websocket.new(uri) |  | ||||||
| 	ws.subscriber.subscribe('on_open', on_open) |  | ||||||
| 	ws.subscriber.subscribe('on_message', on_message) |  | ||||||
| 	ws.subscriber.subscribe('on_error', on_error) |  | ||||||
| 	ws.subscriber.subscribe('on_close', on_close) |  | ||||||
| 	ws.connect() |  | ||||||
| 	// Needs another thread, generates an infinite loop for listen
 |  | ||||||
| 	go ws.listen() |  | ||||||
| 	for i := 0; i < 10; i++ { |  | ||||||
| 		text := 'a'.repeat(i) |  | ||||||
| 		println(text) |  | ||||||
| 		// Send a text to the server
 |  | ||||||
| 		ws.write(text.str, text.len, .text_frame) |  | ||||||
| 		// Only for test purposes, to give time to receive message
 |  | ||||||
| 		time.sleep_ms(100) |  | ||||||
| 	} |  | ||||||
| 	// Only for test purposes, to give time to receive message
 |  | ||||||
| 	time.sleep_ms(100) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| fn on_open(ws &websocket.Client, x, y voidptr) { |  | ||||||
| 	println('websocket opened.') |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| fn on_message(ws &websocket.Client, msg &websocket.Message, x voidptr) { |  | ||||||
| 	typ := msg.opcode |  | ||||||
| 	if typ == .text_frame { |  | ||||||
| 		println('Message: ${cstring_to_vstring(msg.payload)}') |  | ||||||
| 	} else { |  | ||||||
| 		println('Binary message: $msg') |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| fn on_close(ws &websocket.Client, x, y voidptr) { |  | ||||||
| 	println('websocket closed.') |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| fn on_error(ws &websocket.Client, x, y voidptr) { |  | ||||||
| 	println('we have an error.') |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in New Issue